You are previewing Essential PHP Security.
O'Reilly logo
Essential PHP Security

Book Description

Being highly flexible in building dynamic, database-driven web applications makes the PHP programming language one of the most popular web development tools in use today. It also works beautifully with other open source tools, such as the MySQL database and the Apache web server. However, as more web sites are developed in PHP, they become targets for malicious attackers, and developers need to prepare for the attacks.

Security is an issue that demands attention, given the growing frequency of attacks on web sites. Essential PHP Security explains the most common types of attacks and how to write code that isn't susceptible to them. By examining specific attacks and the techniques used to protect against them, you will have a deeper understanding and appreciation of the safeguards you are about to learn in this book.

In the much-needed (and highly-requested) Essential PHP Security, each chapter covers an aspect of a web application (such as form processing, database programming, session management, and authentication). Chapters describe potential attacks with examples and then explain techniques to help you prevent those attacks.

Topics covered include:

  • Preventing cross-site scripting (XSS) vulnerabilities

  • Protecting against SQL injection attacks

  • Complicating session hijacking attempts

  • You are in good hands with author Chris Shiflett, an internationally-recognized expert in the field of PHP security. Shiflett is also the founder and President of Brain Bulb, a PHP consultancy that offers a variety of services to clients around the world.

    Table of Contents

    1. Essential PHP Security
      1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
      2. Foreword
      3. Preface
        1. What's Inside
        2. Style Conventions
        3. Comments and Questions
        4. Safari Enabled
        5. Acknowledgments
      4. 1. Introduction
        1. 1.1. PHP Features
          1. 1.1.1. Register Globals
          2. 1.1.2. Error Reporting
        2. 1.2. Principles
          1. 1.2.1. Defense in Depth
          2. 1.2.2. Least Privilege
          3. 1.2.3. Simple Is Beautiful
          4. 1.2.4. Minimize Exposure
        3. 1.3. Practices
          1. 1.3.1. Balance Risk and Usability
          2. 1.3.2. Track Data
          3. 1.3.3. Filter Input
          4. 1.3.4. Escape Output
      5. 2. Forms and URLs
        1. 2.1. Forms and Data
        2. 2.2. Semantic URL Attacks
        3. 2.3. File Upload Attacks
        4. 2.4. Cross-Site Scripting
        5. 2.5. Cross-Site Request Forgeries
        6. 2.6. Spoofed Form Submissions
        7. 2.7. Spoofed HTTP Requests
      6. 3. Databases and SQL
        1. 3.1. Exposed Access Credentials
        2. 3.2. SQL Injection
        3. 3.3. Exposed Data
      7. 4. Sessions and Cookies
        1. 4.1. Cookie Theft
        2. 4.2. Exposed Session Data
        3. 4.3. Session Fixation
        4. 4.4. Session Hijacking
      8. 5. Includes
        1. 5.1. Exposed Source Code
        2. 5.2. Backdoor URLs
        3. 5.3. Filename Manipulation
        4. 5.4. Code Injection
      9. 6. Files and Commands
        1. 6.1. Traversing the Filesystem
        2. 6.2. Remote File Risks
        3. 6.3. Command Injection
      10. 7. Authentication and Authorization
        1. 7.1. Brute Force Attacks
        2. 7.2. Password Sniffing
        3. 7.3. Replay Attacks
        4. 7.4. Persistent Logins
      11. 8. Shared Hosting
        1. 8.1. Exposed Source Code
        2. 8.2. Exposed Session Data
        3. 8.3. Session Injection
        4. 8.4. Filesystem Browsing
        5. 8.5. Safe Mode
      12. A. Configuration Directives
        1. A.1. allow_url_fopen
        2. A.2. disable_functions
        3. A.3. display_errors
        4. A.4. enable_dl
        5. A.5. error_reporting
        6. A.6. file_uploads
        7. A.7. log_errors
        8. A.8. magic_quotes_gpc
        9. A.9. memory_limit
        10. A.10. open_basedir
        11. A.11. register_globals
        12. A.12. safe_mode
      13. B. Functions
        1. B.1. eval()
        2. B.2. exec()
        3. B.3. file()
        4. B.4. file_get_contents()
        5. B.5. fopen()
        6. B.6. include
        7. B.7. passthru()
        8. B.8. phpinfo()
        9. B.9. popen()
        10. B.10. preg_replace()
        11. B.11. proc_open()
        12. B.12. readfile()
        13. B.13. require
        14. B.14. shell_exec()
        15. B.15. system()
      14. C. Cryptography
        1. C.1. Storing Passwords
        2. C.2. Using mcrypt
        3. C.3. Storing Credit Card Numbers
        4. C.4. Encrypting Session Data
      15. About the Author
      16. Index
      17. About the Author
      18. Colophon
      19. SPECIAL OFFER: Upgrade this ebook with O’Reilly