PHP Session Use-After-Free During Shutdown (CVE-2026-129481)
PHP's session extension can retain a stale script filename pointer after request memory is freed, causing a use-after-free when a later request on the same worker frees the string. Affects PHP 8.3. before 8.3.37, 8.4. before 8.4.28, and 8.5. before 8.5.13.
Overview
CVE-2026-129481 is a use-after-free in PHP's session shutdown path. When a session starts, the filename of the executing script is recorded. If a fatal error occurs in an application callback while session variables are destroyed at shutdown (for example, stream_close() of a user-defined stream wrapper), the pointer is retained after request memory is freed. A later request handled by the same worker can then free the stale string, potentially crashing the worker or corrupting memory. Code execution has not been demonstrated.
The issue requires the filename to be allocated in request memory, such as when the script is not cached by OPcache.
Affected versions: - PHP 8.3. before 8.3.37 - PHP 8.4. before 8.4.28 - PHP 8.5. before 8.5.13
References: NVD, PHP advisory
What to do
1. Identify all PHP versions in your environment and compare them against the fixed releases: 8.3.37, 8.4.28, and 8.5.13. 2. Upgrade affected PHP installations to a patched version as soon as possible. If an immediate upgrade is not feasible, review the vendor advisory for any interim mitigations before changing production. 3. If OPcache is available, verify that it is enabled and caching the relevant scripts; this reduces exposure but is not a substitute for patching. 4. Review application code for user-defined stream wrappers or callbacks that can fail during session shutdown, and harden error handling to avoid triggering the failing cleanup path. 5. Monitor for worker crashes or memory-corruption indicators and re-check the vendor advisory for updates.