GHSA-fm2m-fjf5-v3cp / CVE-2026-126714: Partially overwritten session files can lead to remote code execution
- Published:
- Fetched:
- Updated:
- Affects:
- php ext-session
https://github.com/php/php-src/security/advisories/GHSA-fm2m-fjf5-v3cp ↗
Partially overwritten session files can lead to remote code execution ### Summary PHP's file-based session handler can leave a session file containing parts of two different serialized sessions if a write is interrupted. An attacker who can influence the session contents and interrupt a replacement write may be able to make PHP deserialize attacker-controlled objects when the session is next opened. A suitable object gadget chain in the application can turn this into remote code execution. This affects the `files` session save handler, which is PHP's default. The issue is not limited to session upload progress or PHP 8.6. ### Details When updating a session, `ps_files_write()` writes the new serialized data into the existing file. The vulnerable implementation does not clear the existing contents before every write. If the operation stops after replacing only part of the file, the result can contain a prefix of the new session followed by a suffix of the old one. The file lock prevents competing session operations from accessing the file during the write, but does not make an interrupted write atomic. PHP's session decoders use its unserialization machinery to restore session values. Carefully arranged old and new data can cause the combined file to be interpreted differently from either original session. Bytes that were previously part of an ordinary string can become serialized object data. A later `session_start()` or another session-reading operation can then create those objects and invoke their deserialization behavior. Session upload progress provides one way for a remote client to influence stored session data through multipart uploads. The same underlying problem can arise when an application stores large user-controlled strings in a session. In threaded PHP builds, a hard memory-limit failure in another thread can terminate the process while the session write is in progress. This provides a way to influence where the write stops. The fix truncates the session file to zero before writing the replacement data and aborts the write if truncation fails. An interrupted write can still lose session data, but it can no longer retain the old suffix that enables this attack. ### Impact Successful exploitation can execute code with the privileges of the PHP worker. It requires attacker influence over the session data, an interruption at a useful point in the write, and an application with a suitable deserialization gadget chain. The issue can also corrupt session state. Authentication requirements depend on how the application exposes the affected session operations. Other session storage implementations are not affected by this specific file-write defect, although their own handling of interrupted updates must be considered separately. ### Affected versions The affected code has been present since PHP 4.1.0. This is based on code inspection. ### Mitigation Upgrade to the fixed release for your PHP branch when it becomes available. As a temporary measure, disable `session.up Affected packages: php:ext-session Patched: ext-session 8.2.36, ext-session 8.3.37, ext-session 8.4.28, ext-session 8.5.13