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

Critical · 2026-11-21 · By H.A

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.

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

Tradecraft

This is how the attack works according to the published research. We describe it for defenders and leave out working exploit details.

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:

Detection

Recommended Actions

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

REEF SENTINEL