Security audit for legacy PHP applications
A review of your actual code, not a scanner report. You get the problems an attacker could use, ranked by impact, each with a concrete fix.
What I check
The audit follows the OWASP Top 10 and the PHP-specific problems I keep finding in older code. These are the most common ones:
- SQL injectionQueries built by string concatenation, often with
mysql_*or earlymysqli. - Prepared statements or a query builder, one query at a time, with tests around the risky ones.
- Cross-site scripting (XSS)Request data echoed into HTML without escaping.
- Context-aware escaping, a template engine with auto-escaping, and a Content Security Policy.
- Cross-site request forgery (CSRF)Forms and state-changing GET links without tokens.
- CSRF tokens, POST for every change, and
SameSitesession cookies. - Weak password storagePasswords hashed with
md5()orsha1(), sometimes without a salt. password_hash()with Argon2id or bcrypt, upgraded silently at the next login.- PHP object injection
unserialize()called on cookies, form fields or cache data an attacker can touch. - JSON instead of serialized objects, or
allowed_classeswhere serialization must stay. - File upload and include holesUploads saved in the web root, or code like
include $_GET['page']. - Allow-lists, storage outside the web root, and no user input in paths.
- Session handlingNo ID regeneration after login, cookies without
SecureandHttpOnly. - Session fixation fixed, hardened cookie flags, sensible timeouts.
- Vulnerable dependenciesOld Composer packages with published CVEs, or copied libraries nobody updates.
composer audit, upgrades or replacements, and a lock file that is actually used.- Secrets in the repositoryDatabase passwords and API keys committed in
config.php. - Environment-based configuration, rotated credentials, history cleaned if needed.
- End-of-life PHPA runtime that gets no security fixes at all.
- A planned upgrade to a supported PHP 8 version. See the table above.
An example
Password checks like this one are still common in PHP 5 era code. The hash is fast to brute-force, and the comparison is loose:
// before
if (md5($_POST['pass']) == $row['password']) { login($row); }
// after
$pass = $_POST['pass'];
if (password_verify($pass, $row['password'])) {
if (password_needs_rehash($row['password'], PASSWORD_DEFAULT)) {
$users->updateHash($row['id'], password_hash($pass, PASSWORD_DEFAULT));
}
session_regenerate_id(true);
login($row);
} elseif (hash_equals($row['password'], md5($pass))) {
// legacy md5 hash: upgrade it on this successful login
$users->updateHash($row['id'], password_hash($pass, PASSWORD_DEFAULT));
session_regenerate_id(true);
login($row);
}
Old md5 hashes are replaced at each user's next successful login, so nobody has to reset a password. hash_equals() keeps the comparison strict and timing-safe. Once every active account is converted, the legacy branch is deleted.
How the audit works
- Kick-off call: what the application does, who uses it, what data it holds.
- Code review and tooling: manual review of input handling, authentication, sessions, file access and queries, plus
composer audit, PHPStan and server configuration checks. - Written report: each finding with severity, where it is, how it could be exploited, and how to fix it.
- Walk-through with your team, then fixes by your developers or by me.
What you get
- A ranked list of real problems, without pages of scanner noise.
- Code-level fixes, ready to apply.
- A clear view of how far your PHP version and dependencies are from supported ones, and what a PHP 8 upgrade or a framework migration would involve.
Questions
How is this different from an automated scan?
Scanners see the application from the outside and miss most logic flaws. I read the code: how queries are built, where user input flows, how sessions and passwords are handled. Automated tools are part of the audit, not the whole of it.
Do you need access to production?
No. Read access to the repository and a way to run the application locally or on staging are enough. I never test against production without written permission.
Who fixes the findings?
Your choice. Each finding comes with a concrete fix your team can apply, or I fix them myself, usually together with a PHP upgrade.