Summary
The PHP CGI binary (php-cgi) can access memory outside the supplied path information when a web server passes inconsistent script and path values. Depending on the request and configuration, an unauthenticated attacker may be able to crash the PHP process, expose process memory, or corrupt memory.
This affects php-cgi in both CGI and FastCGI mode when cgi.fix_pathinfo=1, the default. PHP-FPM and PHP running as an Apache module are not affected.
Product
Vulnerable Versions:
- < 8.2.36
- >= 8.3.0, < 8.3.37
- >= 8.4.0, < 8.4.28
- >= 8.5.0, < 8.5.13
Impact
- Denial of service: a single unauthenticated request can crash the
php-cgiprocess handling it. Crashes were reproduced on default, non-debug builds of PHP 8.2.35, 8.3.36, 8.4.27, and 8.5.12. - Information disclosure: unrelated memory can appear in
$_SERVER['PATH_INFO']orPATH_TRANSLATED. This may include other request parameters or values added by the front end. Disclosure to the attacker depends on the application returning these values or making them available through logs or other output. - Memory corruption: PHP can overwrite memory during path correction. Code execution has been claimed, but has not been confirmed.
Remediation
Upgrade to the fixed release for your PHP branch when it becomes available. As a workaround, set cgi.fix_pathinfo=0 in the configuration used by php-cgi, and check that the application’s routing still works.
Alternatively, correct the web server mapping so that the path PHP uses identifies the existing script and any additional path information is consistent. For the Apache example above, rewriting to the URL instead of the absolute filesystem path avoided the issue:
RewriteRule "^/news/(.*)$" "/index.php/content/articles/$1" [PT,L]
See Apache’s documentation for the PT rewrite flag. Other rewrites and aliases can affect the result, so verify the complete configuration. Direct access to a FastCGI listener should also be restricted to trusted front ends.