Fast. Simple. No meetings. No delays.
Home / Blog / PHP Development / PHP Web Application Security: An OWASP-Based Checklist

PHP Web Application Security: An OWASP-Based Checklist

A developer checklist mapped to the OWASP Top 10: injection, authentication, access control, XSS, CSRF, uploads and dependency risk.

Cover graphic for the article: PHP Web Application Security: An OWASP-Based Checklist

PHP web application security starts with a short list of habits applied everywhere: prepared statements for every query, strong password hashing, an access check on every request, output escaping, CSRF tokens, locked-down uploads, and up-to-date dependencies with secrets kept out of code. This checklist maps them to the OWASP Top 10.

It is written for developers. If you are a business owner reviewing an agency or an internal team, the owner-level security checklist asks the questions to put to them, and secure API development covers the API side. The OWASP Top 10 is revised from time to time, so check the current edition on the OWASP site and map this list to it.

PHP web application security begins with prepared statements

Injection stays on the OWASP list because string-built queries keep appearing. A prepared statement sends the SQL and the values separately, so a value can never change the structure of the query.

$stmt = $pdo->prepare('SELECT id, email FROM users WHERE email = :email');
$stmt->execute(['email' => $email]);
$user = $stmt->fetch();
  • Never concatenate request data into SQL, including in ORDER BY, LIMIT and table or column names. Those cannot be bound, so check them against an allow-list.
  • Use PDO or mysqli with real prepared statements, or an ORM or query builder that binds parameters. Check any raw-query escape hatch.
  • Apply the same thinking to shell commands, LDAP, XML and template engines. Avoid passing user input to exec, system or eval.
  • Give the database user only the privileges the application needs.

Authentication and session handling

  • Hash passwords with password_hash() using the default algorithm and check with password_verify(). Never use plain MD5 or SHA for passwords, and never store them reversibly. Use password_needs_rehash() at login to upgrade old hashes.
  • Call session_regenerate_id(true) after login and privilege changes.
  • Set session cookies with Secure, HttpOnly and a suitable SameSite value, and serve everything over HTTPS.
  • Rate limit login, password-reset and verification endpoints, and respond with the same message whether or not an account exists.
  • Make reset tokens random, single-use, short-lived and stored hashed.
  • Offer multi-factor authentication for administrators at least.

Access control checks

Broken access control is a leading category in the OWASP list, and no framework fixes it for you. The typical bug is an endpoint like /invoice?id=123 that loads the record without checking that it belongs to the logged-in user.

  • Deny by default. Every route requires an explicit rule.
  • Check ownership or role on the server for every read, update and delete, not just in the UI.
  • Scope queries by tenant or user (WHERE id = :id AND account_id = :account) so a guessed ID returns nothing.
  • Re-check permissions on APIs, exports, downloads and background jobs, not only on pages.
  • Write tests where user A requests user B's resources and expects a refusal.

Output escaping and XSS

Cross-site scripting happens when untrusted data reaches a page as markup. Escape on output, for the context it lands in.

  • HTML body and attributes: htmlspecialchars($value, ENT_QUOTES, 'UTF-8'), or a template engine that escapes by default. Treat any "raw" output flag as a code-review item.
  • JavaScript contexts: pass data as JSON encoded with json_encode and the hex flags, not by echoing into script blocks.
  • URLs: validate the scheme, because javascript: links are a classic route.
  • Rich text from users: sanitise with a maintained library using an allow-list of tags.
  • Add a Content-Security-Policy header as a second layer, and start in report-only mode to see what breaks.

CSRF protection

Cross-site request forgery makes a logged-in user's browser submit an action they did not intend. Protect every state-changing request.

  • Include a per-session, unpredictable token in each form and verify it on POST, PUT, PATCH and DELETE.
  • Never change state on GET requests.
  • Use SameSite cookies as an extra layer, not the only one.
  • For APIs authenticated by cookies, require the token or a custom header; for token-based APIs sent in headers, the browser does not attach credentials automatically.

File uploads

Uploads combine several risks: code execution, storage abuse and malware delivery.

  1. Limit size and count in PHP, the web server and the application.
  2. Check the real content type on the server (for example with finfo), not the client-supplied name or MIME header, and use an allow-list of types.
  3. Generate your own file names. Never trust the original name or extension, and strip path characters.
  4. Store uploads outside the web root, or on object storage, and serve through a script or signed URL that checks access.
  5. Make sure the upload directory cannot execute PHP.
  6. For images, re-encode them to drop embedded payloads, and consider malware scanning for documents that other users will open.

Dependencies and secrets

  • Run composer audit regularly, commit composer.lock, and update on a schedule. Running an unsupported PHP version leaves known flaws unpatched; see the PHP 7 to PHP 8 checklist if you are behind.
  • Remove unused packages and plugins.
  • Keep secrets in environment variables or a secrets manager, never in the repository or front-end code. Rotate any key that has been exposed.
  • Turn off display_errors in production, log errors privately, and avoid exposing stack traces, version headers and debug pages.
  • Log authentication events and access failures, and make sure someone looks at the logs.

Next step

Turn this list into a pull-request checklist and a short automated suite, then schedule a periodic review by someone who did not write the code. Security requirements and standards change, so treat OWASP and your framework's security documentation as the current reference. For help reviewing a PHP application, see our software development overview, or contact us with a short description.

Frequently asked questions

How do prepared statements prevent SQL injection?

A prepared statement sends the SQL structure to the database first and the values separately afterwards. The database treats values strictly as data, so quotes or SQL keywords inside them cannot change the query. Identifiers and sort directions cannot be bound, so those need allow-list checks instead.

How should passwords be stored?

Hash them with PHP's password_hash() function using the default algorithm, and verify with password_verify(). Never store them in plain text or with fast hashes such as plain MD5 or SHA. Check password_needs_rehash() at login so older hashes upgrade over time, and rate limit login attempts.

How do I secure file uploads?

Limit size and count, allow only specific file types checked by content on the server, and generate your own file names. Store files outside the web root or on object storage, serve them through an access check, make sure uploaded files cannot execute as PHP, and re-encode images.

Related articles

PHP Development USA

Scaling a PHP Application for Higher Traffic

Where PHP applications actually hit limits — database queries, sessions, caching and file storage — and the fixes in the order that pays off.

5 min read

🚀 Start Now