CVE-2026-129481
Patch Available.
This Vulnerability has been fixed in the Never-Ending Support (NES) version offered by HeroDevs.
Overview
PHP is a general-purpose scripting language used mostly for web development. It runs behind web servers through server APIs such as Apache mod_php and PHP-FPM, and powers content management systems and frameworks such as WordPress, Drupal, Moodle and Laravel. Since PHP 8.3, the session extension records the filename and line of the script that started a session in an internal global, so that later errors can report where the session was started.
A Use After Free vulnerability (CVE-2026-129481) has been identified in how the session extension cleans up after an interrupted session shutdown, which allows a fatal error in a callback reached during session cleanup to leave a pointer to a script filename in freed request memory. A later request handled by the same worker can then release the stale string, which can corrupt memory or crash the worker. The PHP project tracks this issue as GHSA-g3vh-838c-65v7 and describes it as an incomplete fix for CVE-2026-109619.
Per MITRE CWE-416: The product reuses or references memory after it has been freed.
This issue affects PHP 8.3 before 8.3.37, PHP 8.4 before 8.4.28 and PHP 8.5 before 8.5.13. PHP 8.2 and earlier do not contain the affected session filename field, but they share the engine behavior that the fix also changes: PHP keeps serving requests after a module's request shutdown handler is interrupted.
Details
Module Info
- Product: PHP
- Affected packages:
php-src(ext/session, Zend engine) - Affected versions: >=8.3.0 <8.3.37, >=8.4.0 <8.4.28, >=8.5.0 <8.5.13
- GitHub repository: https://github.com/php/php-src
- Published packages: https://www.php.net/downloads
- Package manager: N/A
- Fixed in:
- OSS PHP 8.3.37, 8.4.28, 8.5.13
- NES for PHP
Vulnerability Info
This Critical-severity vulnerability is found in the session extension of PHP 8.3 before 8.3.37, PHP 8.4 before 8.4.28 and PHP 8.5 before 8.5.13. The PHP project scores it 9.2 under CVSS 4.0 (CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N). The PHP project also classifies it as CWE-459, Incomplete Cleanup.
Session shutdown normally releases the recorded filename, but it destroys the session variables first. That destruction can invoke application callbacks, including the stream_close() method of a user-defined stream wrapper whose stream is held in the session. If such a callback raises a fatal error, session shutdown is abandoned before the filename is released or cleared. PHP catches the bailout and carries on shutting down the request. In PHP 8.5.12, zend_deactivate_modules() reads:
if (module->request_shutdown_func) {
zend_try {
module->request_shutdown_func(module->type, module->module_number);
} zend_end_try();
}
The request heap is then freed while the worker still holds the filename pointer, and session initialization in the next request did not reset the field. Starting another session can release the stale string, and ordinary session module shutdown can also reach it even when the next script calls no session functions. The two requests must reach the same worker, but they do not need to belong to the same user or session.
The reported reproducer uses PHP-FPM with OPcache disabled, so the recorded filename belongs to the request heap. A filename held in persistent OPcache memory does not produce the same dangling pointer. The advisory confirms the use after free on PHP 8.4.27 and 8.5.12 and states that PHP 8.3.36 contains the same code. Unlike the cases in the original advisory, this path needs neither a diagnostic-producing FastCGI parameter nor session upload progress.
An attacker who can make an application's session cleanup fail in this way may corrupt memory or crash a reused PHP worker. The use after free could potentially lead to remote code execution, but code execution through this field has not been demonstrated.
The fix clears the recorded filename and line number during session initialization:
PS(in_rfc1867_update) = false;
ZVAL_UNDEF(&PS(http_session_vars));
PS(session_started_filename) = NULL;
PS(session_started_lineno) = 0;
}
It also terminates the PHP process if a module's request shutdown handler bails out, so that a process with partially cleaned-up state does not handle another request. This engine change is not specific to the session filename field. PHP 8.2 and the End-of-Life PHP 5.6 through 8.1 lines continue after an interrupted request shutdown handler in the same way, and the PHP project did not apply the change to them. NES for PHP includes the engine change in its release lines.
Mitigation
The use after free through the session filename field affects only PHP 8.3, 8.4 and 8.5, which are supported and received a fix. The PHP project did not apply the accompanying engine change to PHP 8.2 or to the End-of-Life PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0 and 8.1 lines, which will not receive any public updates for it.
Until an upgrade is possible, avoid fatal errors in callbacks reached during session cleanup. For PHP-FPM, setting pm.max_requests=1 and restarting the workers keeps the demonstrated sequence from reaching a second request in the same worker, at a performance cost. Disabling session upload progress does not address this path, and enabling OPcache alone is not a reliable mitigation.
Users of the affected components should apply one of the following mitigations:
- Upgrade to PHP 8.3.37, 8.4.28, 8.5.13, or later.
- Leverage a commercial support partner like HeroDevs (NES for PHP) for post-EOL security support.
Credits
- TarPeg007 (finder)
- bryans3c (finder)
- Arnaud Le Blanc (remediation)
- Jakub Zelenka (remediation)