phpAfterShell (CVE-2026-126714): Torn Session Files in PHP's Default Handler Lead to Remote Code Execution and Bypass the PHP2Shell Fix

A critical race in PHP's default files session handler (CVSS 9.2) lets an interrupted write mix old and new session data into injected objects and code execution; fixed in PHP 8.2.36, 8.3.37, 8.4.28, 8.5.13 and 8.6.0.
Overview
PHP has patched CVE-2026-126714, nicknamed phpAfterShell: a critical flaw in the default "files" session handler (ext/session). It is rated CVSS v4.0 9.2 (Critical). When PHP rewrites a session file and the write is interrupted, the file can end up holding the start of the new session followed by the tail of the old one. On the next request, PHP reads this mixed file back, and bytes that were only harmless text inside a string can come back as live PHP objects. With a usable deserialization chain, that becomes remote code execution in the PHP worker. Without one, an attacker can still tamper with session values such as identity, roles or CSRF tokens.
The bug went out in the same PHP security release as 16 other CVEs, published on 19 November 2026 at 18:00 Mauritius time (14:00 UTC). Seven of them are rated 9.2. phpAfterShell is a separate flaw from PHP2Shell (CVE-2026-109619) from October: the October patch does not protect against it. Servers patched last month are still exposed until they move to the November builds.
- CVE: CVE-2026-126714 (advisory GHSA-fm2m-fjf5-v3cp)
- Component: PHP core,
ext/session, files save handler (ps_files_write()inmod_files.c) - Weakness: CWE-367 (TOCTOU race condition), CWE-662 (improper synchronization); impact CAPEC-586 (object injection)
- CVSS v4.0: 9.2,
AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H - Affected: PHP before 8.2.36, 8.3.x before 8.3.37, 8.4.x before 8.4.28, 8.5.x before 8.5.13, plus the 8.6.0 release candidates
- Fixed: PHP 8.2.36, 8.3.37, 8.4.28, 8.5.13 and 8.6.0
- Exploited in the wild: none reported so far; not in CISA KEV
The Vulnerability
How PHP saves a session
With the default session.save_handler = files, each session lives in a file such as /var/lib/php/sessions/sess_<id>. The file is a plain run of key|serialized_value records. There is no overall length field, checksum or "write finished" marker. On load, the decoder reads up to a |, unserializes the value after it, and treats the next byte as the start of the next key.
On save, ps_files_write() writes the new data into the existing file from offset 0 using pwrite(). In the vulnerable code, PHP only trims the file when the new data is shorter than the old file. If the new data is the same size or longer, the old bytes stay in place until the new bytes cover them.
Why an interrupted write is dangerous
PHP holds an exclusive flock() on the session file. That stops two requests writing at once, but it does not make the write atomic. If the worker dies part-way through, nothing rolls the file back. If only the first k bytes of the new session were written, the file now holds:
new_session[0:k] + old_session[k:]
PHP's own short-write check never runs, because the process is already dead. According to the advisory, in threaded PHP builds a hard memory-limit failure in another thread can kill the whole process mid-write. This gives an attacker some control over where the write stops.
Getting attacker bytes into the session
The easiest way to put attacker data into a session file is session upload progress (session.upload_progress.enabled, which is on by default). When a multipart upload includes a PHP_SESSION_UPLOAD_PROGRESS field, PHP writes an upload_progress_<name> entry into the session before any application code runs. That entry contains the form field name and the uploaded file's name, both chosen by the attacker. Any application that stores long user-supplied strings in $_SESSION gives the same opening.
Timeline
- Late October 2026: researchers privately report the issue to the PHP security team, soon after the PHP2Shell patches of 21 October (8.5.12, 8.4.27, 8.3.36, 8.2.35), which do not contain this fix.
- 11 November 2026: CVE-2026-126714 is reserved.
- 19 November 2026, 18:00 Mauritius time (14:00 UTC): PHP 8.2.36, 8.3.37, 8.4.28, 8.5.13 and 8.6.0 are released with fixes for 17 CVEs.
- 19 November 2026, 18:43 Mauritius time (14:43 UTC): the CVE record is published. The same day, the researchers publish their write-up with a harmless proof-of-concept "oracle" and a video of the full chain.
- 20 November 2026: CISA's enrichment rates the CVE as Exploitation: none, Automatable: yes, Technical impact: total. Distribution security trackers (SUSE, Ubuntu) open entries for it.
Tradecraft
This is how the attack works according to the published research. We describe it for defenders and leave out working exploit details.
- Pick a session ID. If
session.use_strict_modeis off (the default), PHP accepts an ID the attacker makes up. If it is on, one normal visit gives the attacker a valid ID. - Write a "carrier" session. The attacker sends a request that stores a long string in the session, usually through the upload-progress filename. Hidden inside that string, as inert text, is a serialized object record (for example
evil|O:...). - Write a "replacement" session. A second request stores data of at least the same size, with a shorter length field for that same string. Because it is not shorter than the old file, the vulnerable code skips the truncate.
- Interrupt the write. The worker has to die mid-write. The researchers describe two routes: pushing the worker into an out-of-memory kill (an uncatchable SIGKILL under a container or cgroup memory limit), and CPU-heavy multipart parsing to land inside the gap between the write and the truncate. They found that PHP's normal execution timeout did not fire in time on Linux.
- Trigger the load. A normal request with the same session ID calls
session_start(). The decoder reads the shortened string from the new data, then reaches the leftover old bytes and treats them as a new top-level record. The hidden object becomes a real object in$_SESSION. - Turn the object into code execution. PHP's advisory and some vendors say this needs a suitable gadget chain in the application (common in frameworks and Composer libraries). The researchers say they built the full chain from a memory-corruption bug in a PHP-native class decoder, with no application gadget needed. They have withheld that part.
Why the PHP2Shell patch does not help: the October fix made objects seen during the upload-progress callback load as __PHP_Incomplete_Class. Here, the object only appears on a later session_start(), after that restriction has been lifted, so it loads normally.
The attack is noisy and probabilistic. It needs many requests to control memory pressure and timing, and works best against PHP running in memory-limited containers (Apache mod_php or PHP-FPM) with file sessions.
IOCs
No file hashes, domains or IP addresses have been published for CVE-2026-126714. With no confirmed exploitation, there is no attacker infrastructure to list. Hunt for behaviour instead:
- Multipart POST requests containing
PHP_SESSION_UPLOAD_PROGRESSwith unusually long field names or filenames, especially repeated against the same session cookie - Field names with deeply nested bracket notation (for example
a[][][][]...), used to slow down multipart parsing - Bursts of large or stalled uploads that push PHP workers toward their memory limit, followed by worker OOM kills
- Session files whose top level contains an unexpected object record:
|O:<n>:"or|C:<n>:" - Repeated
session_start(): Failed to decode session objecterrors for the same session IDs (corrupted or failed attempts)
Detection
- Find vulnerable PHP: check the running web workers, not only the CLI:
php -v,php-fpm -v, anddocker exec <container> php -v. Anything below 8.2.36 / 8.3.37 / 8.4.28 / 8.5.13 is affected. - Check exposure:
php -i | grep -E 'session.save_handler|session.serialize_handler|session.upload_progress.enabled|session.use_strict_mode'. High risk =fileshandler + upload progress enabled. - Web logs:
grep -Ei 'PHP_SESSION_UPLOAD_PROGRESS' /var/log/nginx/access.log /var/log/apache2/access.log. Look for many hits from one client or against one session. - Session files:
grep -alE '\|(O|C):[0-9]+:"' /var/lib/php/sessions/sess_*(the path depends onsession.save_path). Some legitimate apps store objects in sessions, so treat a hit as a lead and compare against what your app normally writes. - Error logs: search PHP-FPM, Apache and nginx error logs for
Failed to decode session, and kernel or container logs for OOM kills ofphp-fpm/apache2workers (dmesg | grep -i oom,journalctl -k). - After compromise: if a worker was hit, look for what follows RCE: new PHP files in web roots or upload folders, unexpected outbound connections from PHP workers, and new cron jobs or users.
Recommended Actions
- Upgrade now to PHP 8.2.36, 8.3.37, 8.4.28, 8.5.13 or 8.6.0. On distributions, use the vendor's patched packages (
apt install --only-upgrade php8.x-,dnf upgrade 'php',apk upgrade 'php*') and check the vendor's advisory for backports. - Restart PHP-FPM, Apache and any long-running PHP workers, and rebuild container images. An upgraded package does nothing until the running processes are replaced.
- If you cannot patch today: set
session.upload_progress.enabled = 0inphp.ini(notini_set()or.user.ini, which apply too late), then restart workers. This closes the easiest input path but not the flaw itself. - Move sessions off flat files where you can: Redis, Memcached or a transactional database are not affected by this defect.
- Keep large untrusted strings out of
$_SESSION, and enablesession.use_strict_mode = 1so attacker-chosen session IDs are rejected. - PHP 8.1 and older are end-of-life and get no official release. Upgrade to a supported branch, or confirm that your distribution or vendor has shipped a fix. Note that 8.2 security support ends in December 2026.
- Don't stop at this CVE: the same release fixes other critical bugs, including PHP-FPM request smuggling (CVE-2026-129289), a session serializer mismatch (CVE-2026-115560) and an interrupted-shutdown use-after-free that completes the PHP2Shell fix (CVE-2026-129481). One upgrade covers them all.
Analyst Assessment
Severity: Critical, and patch priority is high even though exploitation is complex. phpAfterShell is a design weakness that has existed for a very long time: PHP's advisory traces the code path back to PHP 4.1.0. It sits in the default configuration of the world's most widely deployed server-side language. Reliable exploitation is hard: it needs precise memory and timing control and works best on containerised PHP with tight memory limits. That probably explains the "attack requirements present" rating in the CVSS score.
Three things push us to treat it as urgent anyway. First, the researchers have shown a full end-to-end chain and say it needs no application gadget. Once that native chain becomes public or is reproduced, the "you need a gadget" safety margin disappears. Second, PHP2Shell was weaponised within days last month and ended up in CISA KEV, which shows how quickly attackers move on PHP core bugs. Third, organisations that rushed out the October patch may believe they are covered. They are not.
We expect a public proof-of-concept within weeks and opportunistic scanning against PHP hosts that remain unpatched. Patch, restart, disable upload progress where it isn't needed, and move high-value applications to non-file session storage.
Sources
- Partially overwritten session files can lead to remote code execution, GHSA-fm2m-fjf5-v3cp (PHP / GitHub Security Advisory)
- CVE-2026-126714 record (CVE.org)
- phpAfterShell: From Interrupted Session Writes to Remote Code Execution (depthfirst)
- phpAfterShell and Critical PHP RCE Vulnerabilities: Everything You Need To Know (Wiz)
