GHSA-5j3f-64r7-f564 / CVE-2026-129538: PHP-CGI out-of-bounds read and write during PATH_INFO correction
- Published:
- Fetched:
- Updated:
- Affects:
- php sapi-cgi
https://github.com/php/php-src/security/advisories/GHSA-5j3f-64r7-f564 ↗
PHP-CGI out-of-bounds read and write during PATH_INFO correction ### 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. ### Details The problem occurs when PHP removes a trailing path from `SCRIPT_FILENAME`, or from `PATH_TRANSLATED` in a redirected CGI request, but the supplied `PATH_INFO` is shorter than the path being removed. A present but empty `PATH_INFO` can also trigger the problem. This requires particular web server mappings; using CGI, FastCGI, or URL rewriting alone is not enough. In `init_request_info()`, PHP calculates the replacement `PATH_INFO` by subtracting the length of the removed suffix from the end of the supplied value. If the suffix is longer, the resulting pointer lies before the `PATH_INFO` buffer. Subsequent path correction can read, write and copy memory through this invalid pointer. The fix checks the lengths before deriving the pointer and skips the rewrite when no valid replacement exists. #### Apache CGI example A legitimate configuration that can produce these values is a legacy Apache CGI installation using `Action`, combined with a rewrite to an absolute filesystem path. For example, this virtual-host configuration routes a short public URL to a longer route handled by an existing `/srv/site/index.php`: ```apache DocumentRoot "/srv/site" ScriptAlias /cgi-bin/php "/usr/local/bin/php-cgi" AddHandler php-script .php Action php-script /cgi-bin/php AcceptPathInfo On RewriteEngine On RewriteRule "^/news/(.*)$" "/srv/site/index.php/content/articles/$1" [L] ``` This fragment assumes an otherwise working Apache CGI installation with the required modules and access permissions. The `Action` arrangement is described in the [PHP CGI installation documentation](https://www.php.net/manual/en/security.cgi-bin.force-redirect.php). A request for `/news/x` can then reach PHP with: ```text PATH_INFO = /news/x PATH_TRANSLATED = /srv/site/index.php/content/articles/x REDIRECT_URL = /news/x ``` PHP finds the existing `index.php`, but the remaining `/content/articles/x` is longer than the original `/news/x`. Attempting to reconcile these values triggers the invalid memory access. This was reproduced through an actual HTTP request with Apache 2.4.58 and an unmodified PHP CGI binary. An `Alias` that maps `/news` to `/srv/site/index.php/content/articles` produced the same result. The ordinary `Action` setup, a conventional rewrite to `index.php`, and a rewrite to the URL `/index.php/content/articles/x` did not trigger the issue in these tests. The vulnerable example is a valid routing confi Affected packages: php:sapi-cgi Patched: sapi-cgi 8.2.36, sapi-cgi 8.3.37, sapi-cgi 8.4.28, sapi-cgi 8.5.13