Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
PHP Development

The Vulnerabilities That Actually Get Exploited

Last updated:

The same handful of problems

Despite the variety of attacks discussed in security literature, the PHP applications we are asked to investigate have been compromised through a small and consistent set of causes.

Getting five things right eliminates the overwhelming majority of practical risk.

Database access

  • Prepared statements with bound parameters, always — never string concatenation
  • That includes ORDER BY and LIMIT clauses, which are commonly overlooked
  • Least-privilege database credentials, not a superuser
  • No database errors displayed to users, ever
Injection through a search box or a sort parameter remains the most common way a PHP application is compromised, and prepared statements make it impossible.

Output escaping

Anything that came from a user and is rendered into a page must be escaped for its context. HTML, attributes, JavaScript and URLs each need different treatment.

Modern template engines escape by default, which is one of the strongest arguments for using one rather than writing raw PHP templates.

Authentication and sessions

  1. Use the framework's authentication rather than writing your own
  2. Password hashing with the language's current recommended function
  3. Session identifiers regenerated on privilege change
  4. Secure and HttpOnly flags on session cookies
  5. Rate limiting on login attempts

File uploads and dependencies

RiskControl
Uploaded files executedStore outside the web root, always
Type spoofingValidate content, not the extension
Path traversalNever use user input in a file path
Vulnerable dependenciesAutomated auditing on every build
Outdated PHP versionStay on a supported release

File uploads stored inside the web root is the second most common compromise route we find, after injection.

Frequently asked questions

Do frameworks make applications secure?

They make the common vulnerabilities harder to introduce. They do not prevent bad code, and they are a substantial improvement over hand-rolled equivalents.

How often should dependencies be updated?

Security releases within days. Others on a regular schedule with tests. Automated auditing should run on every build.

What about legacy applications?

Audit for the five causes above first. Those are usually where the actual exposure is, rather than in anything exotic.

Is a web application firewall worth it?

As an additional layer, yes. It is not a substitute for fixing the code, and it should not be treated as one.

Keep reading

Not sure whether an old PHP application is safe?

The five common causes are quick to check. Happy to audit what you are running.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Web DevelopmentCustom Software Development