On November 19, 2026, the PHP project released 8.2.36, 8.3.37, 8.4.28, 8.5.13, and the first stable build of 8.6.0, closing eighteen vulnerabilities, seven of them critical. Most patch days blend together. This one didn’t, because of CVE-2026-126714 — a bug the security firm depthfirst named phpAfterShell.
What makes it unusual is that it isn’t a flaw that slipped past review. It’s a flaw that survived its own fix. depthfirst’s Yuhang Wu, working with the firm’s AI-assisted analysis platform and its own models, asked a question patch verification rarely bothers with: the October exploit no longer works, but is the underlying operation actually safe now? It wasn’t.
PHP’s file-backed session handler updates a live file using pwrite() and ftruncate() — two separate system calls with no transactional guarantee between them. A worker process that dies between the wrong pair of instructions can leave behind a file that’s neither the old session nor the new one. Under the default files save handler, that half-written file can be steered into an arbitrary deserialization primitive. Chained with a memory-corruption bug in one of PHP’s own internal classes, it becomes unauthenticated remote code execution. The official advisory rates it CVSS v4.0 9.2.
The timing matters. Exactly four weeks earlier, on October 21, PHP had shipped emergency fixes for a separate attack researchers called php2shell: CVE-2026-109618 and CVE-2026-109619, also scored 9.2, both use-after-free bugs reachable through the same upload-progress code before any application logic runs. Those weren’t theoretical. Infosecurity Magazine reported campaigns against Check Point gateways dating back to October 30, exploitation attempts against exposed Palo Alto Networks admin interfaces, backdoors, and destructive tooling aimed at VMware ESXi hosts. Amazon had detected exploitation attempts four days before the disclosure. So when depthfirst went back to the patched code and found that the October fix had changed which objects could be created in memory, without touching how the file itself gets written, they weren’t poking at some forgotten corner of the runtime. They were re-auditing the most actively exploited surface in the PHP ecosystem, and they found a second way in.
How PHP starts writing your session before your code runs
Most PHP developers encounter file uploads through $_FILES, which feels like an application-level concern. It isn’t. By the time a script reads that array, PHP has already parsed the entire multipart request body during startup, using a parser built around RFC 1867, the 1995 memo that defined form-based file upload in HTML. That parser fires events as it hits form fields, file headers, and the closing boundary. The session extension listens for those events whenever session.upload_progress.enabled is on — a feature that shipped in PHP 5.4.0 back in 2012 and has defaulted to “on” ever since.
If a multipart POST includes a field called PHP_SESSION_UPLOAD_PROGRESS (the default name) positioned before the file data, PHP treats its value as a progress token, resolves the request’s session ID, initializes the session module, and writes progress state before index.php runs a single line. depthfirst’s technical writeup quotes the exact sequence from ext/session/session.c: php_rinit_session(0), then PS(id) = zend_string_copy(Z_STR(progress->sid)), then php_session_rfc1867_update(progress, 0).

The record PHP writes is keyed upload_progress_<token> and contains content_length, bytes_processed, and a files list with entries for field_name, name, tmp_name, and an error code. Two of those values — the field name and the filename — are attacker-controlled bytes that land directly inside a serialized session value. Because session.upload_progress.cleanup=1 is also the default, the same request rewrites the whole file again on its way out, once the progress entry gets removed. Writes during the upload itself are throttled by session.upload_progress.freq (1%) and min_freq (one second), but throttling only slows down how often PHP writes — it doesn’t change what a write does. The manual is explicit that this state is written before any script executes, which also means it uses whatever save handler was configured at startup. A custom handler registered later through session_set_save_handler() never sees this data at all.
Three defaults make the whole thing reachable: session.save_handler=files, session.serialize_handler=php, and session.use_strict_mode=0. That last one is the quiet enabler. With strict mode off, PHP will accept any well-formed PHPSESSID cookie, even one it never issued, and create sess_<SID> inside session.save_path — which, left empty, resolves to the system temp directory, usually /tmp. No upload controller is required. No deserialization sink. Not even a call to session_start() on the multipart endpoint itself. A later, completely ordinary request that does call session_start() with the same cookie resolves to the same file.
So you end up with one session ID, one handler, one file, and two writers: the RFC1867 callback running before any application code, and the application itself running after it. The files handler isn’t careless about this — it creates files with mode 600, opens with O_NOFOLLOW, checks the file owner against the worker’s uid, and takes an exclusive flock(). But a lock only serializes cooperating writers; it doesn’t undo a write that’s already half-finished. When a worker disappears mid-write, the kernel closes the file descriptor, releases the lock, and leaves whatever bytes happen to be sitting in the file. You don’t even need two writers racing each other. One writer, interrupted at the right instant, is enough.
Why a half-written session file is dangerous
A session file isn’t an opaque blob — it’s parser input. With the default php serializer, it’s just a string of key|serialized_value pairs concatenated with no separator between records, no overall length field, no checksum, and no commit marker. A small session looks like this, all on one line:
📬 Stay Ahead of Cyber Threats
Get the latest cybersecurity news, critical vulnerabilities, threat intelligence, tutorials, and exclusive giveaways delivered straight to your inbox. No spam. Unsubscribe anytime.
username|s:5:"alice";roles|a:1:{i:0;s:5:"admin";}profile|O:8:"stdClass":1:{s:5:"theme";s:4:"dark";}
The decoder scans forward to the first | to find the key (which is why keys can’t contain | or !), then hands everything after it to PHP’s unserialization logic. Wherever that value ends, the next byte starts a new record. The grammar covers the full PHP serialization format: N; for null, b:1; for booleans, i:42; for integers, d:3.14; for floats, s:5:"alice"; for strings whose declared length tells the parser exactly where to resume, a:2:{...} for arrays with an element count, O:8:"stdClass":1:{...} for objects (which triggers class lookup and property reconstruction), C: for custom serialization, E: for enum cases, and R:/r: for back-references to already-decoded values by index. Every length, every count, every reference number is tracked parser state. Change one number near the front of the file, and every byte after it gets reinterpreted.
That’s the whole trick. The same bytes can be completely inert at one offset — just part of a string the decoder skips over because the declared length says so — and become live, parseable data at another offset, if you shorten the length that comes before them. The other two serializers PHP ships, php_serialize and php_binary, don’t have this property in the same way, but neither is the default. The php format’s delimiter-and-length structure is exactly what makes a spliced file still parse cleanly. So the researchers’ target wasn’t arbitrary file corruption — it was a specific outcome: a short replacement session that moves the decoder onto a chosen leftover tail from a longer “carrier” session, where dormant object bytes had been tucked inside an ordinary string the whole time.
The two-call write that isn’t actually one operation
The write path lives in ps_files_write(), in ext/session/mod_files.c. The handler caches the file’s size when it reads the session, then — in the ordering that shipped with the October releases — truncates only if the new value is shorter than that cached size, and writes at offset zero:
c
if (ZSTR_LEN(val) < data->st_size) { php_ignore_value(ftruncate(data->fd, 0));}n = pwrite(data->fd, ZSTR_VAL(val), ZSTR_LEN(val), 0);if (n != ZSTR_LEN(val)) { return FAILURE;}
At the PHP level, this reads as one atomic step. At the kernel level, it’s nothing of the sort. A large pwrite() copies user-space pages into the page cache incrementally, checking for fatal signals as it goes. Pages that were already copied stay dirty in the cache and get written back even if the process never returns from the syscall. So if a worker is killed after copying k bytes of a replacement value R over an equal-or-longer carrier C — meaning no truncation happened — the file now contains R[0:k] followed by C[k:]. depthfirst’s first guess was PHP’s own execution timeout, since it’s remotely controllable and parser work is expensive. Tracing showed that was wrong: the timeout only became relevant after pwrite() had already returned in full. To land inside the copy itself, the worker had to die mid-syscall — and an uncatchable SIGKILL from a cgroup out-of-memory kill delivered exactly that.
There’s a second, more ironic ordering buried in the history. On October 15, 2026, PHP core developer Ilia Alshanetsky committed c2b02f24dff — “ext/session: Truncate session file after successful write” — as a reliability fix, because session data was being lost when a write failed after the file had already been truncated. The commit moved the ftruncate() call to after the write, targeted it at the new value’s length instead of zero, and added regression tests, including one using RLIMIT_FSIZE to force a write failure and confirm the old data survives. Reasonable fix, on its own terms. It also opened a new window: if R is shorter than C, a complete pwrite() now temporarily leaves the file containing R followed by the leftover tail of C, and only the subsequent ftruncate() removes it. Kill the worker between those two syscalls, and that temporary state becomes permanent.
That ordering shipped in the release candidates for the next cycle — 8.4.28RC1, 8.5.13RC1, 8.6.0RC4, and master — while the October security releases still truncated before writing. depthfirst labels these Variant A (death during a buffered copy) and Variant B (death between two syscalls). Variant B’s window is smaller, but it no longer depends on catching a partial kernel copy at all. Either way, the root cause is the same: PHP treated an update spanning two separate syscalls on a live file as one logical commit, and nothing in the storage layer enforced that.
How two legitimate sessions get spliced into a third
Here’s where the construction gets genuinely clever. The “carrier” session C is something PHP itself generates from ordinary multipart fields, containing the target record — say evil|O:8:"stdClass":1:{s:5:"proof";s:5:"pwned";} — buried inside a length-delimited string, where it’s completely inert. The “replacement” R, also generated from ordinary PHP fields, follows the same grammar but with a shorter inner length. Parsed on their own, both files are valid, boring sessions.

After an interrupted write, the decoder consumes R’s prefix, the shortened length ends that string early, and the retained tail of C suddenly gets read as a brand-new top-level key. To prove this without needing a weaponized gadget chain, depthfirst used a harmless stdClass object, so success is directly observable: a consumer route containing nothing but session_start(); var_dump($_SESSION['evil'] ?? null); prints a real object on a hit. And the kill point doesn’t need to land on one exact byte — by shaping the serialized data carefully, a whole range of partial writes converge on the same retained record, turning a narrow kernel timing event into a much wider window the attacker can actually hit.
Each attempt costs three HTTP requests against the same session file: a carrier POST that writes C, a replacement POST that writes R while the worker is pushed toward termination, and a consumer GET that reports the outcome. Miss early and the consumer sees the carrier. Miss late and it sees the full replacement. Hit, and $_SESSION['evil'] exists. That three-way result tells you more than socket timing ever could, because the HTTP connection only tells you whether a worker finished or disappeared — the consumer tells you what actually ended up on disk. And none of this requires local access. It all runs over the network, against an ordinary Apache deployment.
Turning a kernel timing event into a controllable HTTP attack
A fixed delay that worked on one machine failed on the next, because the moment a worker dies depends on CPU speed, Apache’s scheduler, page-cache state, allocator pressure, multipart parsing cost, and the exact instant a worker crosses its memory limit. The researchers stopped guessing at a constant and started estimating a moving target from live feedback.
For Variant A, held-open multipart requests push the Apache cgroup toward its memory limit while the carrier and replacement requests keep fixed, known byte sizes. Two replacement requests cross the memory boundary at roughly the same time, so an allocation in one worker can shove the other over the edge mid-write — inside the roughly 5.96 MiB buffered copy of R. Pressure gets adjusted at two scales: coarse 2 MiB steps, and a finer request covering the gap between them. Completed responses and dropped connections feed a running model — stable outcomes shift the coarse allocation, mixed outcomes get fitted with a logistic estimate of the probability of a disconnect at a given pressure level, and the next attempts sample near that estimated boundary. Dropped background connections get replaced so the baseline pressure stays roughly constant. Kernel-level probes showed partial writes clustering near 2 MiB, 4 MiB, and 5.5 MiB, which matched where the serialized grammar’s acceptance window actually was. In a live HTTP run, the promoted object showed up on attempt eleven.
Variant B needed a different lever, and the researchers found one in the parser itself: a legal multipart field name built from deeply nested bracket notation forces PHP to burn CPU time before it flushes upload progress — and because that field name never enters the carrier record, changing its nesting depth shifts timing without touching the target data at all. Shallow field names finish before the replacement write happens; deep ones sail past the truncate; somewhere in between is the window where pwrite() has completed but ftruncate() hasn’t run yet. That window doesn’t move in a predictable direction request to request, so the controller first brackets a small, locally consistent range, then tracks the boundary with a particle filter that accounts for drift and outliers, widening its search after a surprising result and resampling toward the most informative depths. In simulation, this lifted the 24-attempt hit rate from 52.8% to 88.4%. On a live HTTP target, it reached the exploited state in ten attempts after one coarse recalibration. The key point is that the controller learns the specific host it’s attacking instead of importing a timing constant from a lab machine — which is the difference between a demo that works once and an exploit that works against a real target.
From corrupted session file to code execution
Once the hybrid file sits in session.save_path, everything left is an ordinary GET request. The application calls session_start() with the same session ID, and PHP reads the file through its normal decoder as trusted server-side state. This is exactly where the October patch’s scope falls short. That fix restricted class resolution only while the RFC1867 callback itself is running: on patched builds, any object encountered during that callback is transported as __PHP_Incomplete_Class. Once multipart parsing finishes, that restriction is gone. The next session_start() resolves the promoted record through PHP’s ordinary class-loading path, magic methods included. The attacker never needs to trigger deserialization during the callback — just leave the right bytes on disk and come back later.

The primitive is broader than object injection in two directions. First, the splice works before any object even enters the picture: plain scalars and arrays can overwrite identity, authorization, CSRF tokens, password-reset state, cart contents, or workflow progress before the application runs its own access checks — because the corrupted value arrives through a channel applications treat as inherently trustworthy by default. Second, the advisory states plainly that upload progress is just the easiest entry point, not the only one. Any application storing large user-controlled strings in sessions can hit the same underlying defect, and in threaded PHP builds, a hard memory-limit failure in a different thread can kill the process mid-write just as easily.
From the deserialization side, depthfirst separately audited PHP’s internal classes: SPL containers, iterators, date and time objects, random engines, and extension-owned wrappers all reconstruct native state from serialized input, crossing from PHP-level values into zend_object structures, hash tables, property tables, native pointers, and length fields. That audit produced a chain built entirely out of PHP’s own native decoders — a memory-corruption bug supplies the first primitive, later stages leak the addresses the worker needs and hijack an internal call, and the object promoted from the session tail enters the chain during session_start(), ending in code execution inside the PHP process. depthfirst is withholding the specific decoder and heap layout for coordinated disclosure. The advisory describes the general version of this as needing a suitable gadget chain already present in the application; depthfirst’s contribution was removing that requirement entirely. That’s the uncomfortable part for defenders: hardening your own unserialize() call sites or blocking userland gadget classes does nothing here, because the application doesn’t contribute anything beyond normal session use.
How PHP finally made session writes atomic
The fix, commit e2d3cee, was developed by Ilija Tovilo, reviewed by Arnaud Le Blanc, and merged across every supported branch by release manager Jakub Zelenka on November 19. It’s a small change to ps_files_write():
c
- if (ZSTR_LEN(val) < data->st_size) {- php_ignore_value(ftruncate(data->fd, 0));- }+ if (ftruncate(data->fd, 0) != 0) {+ php_error_docref(NULL, E_WARNING, "ftruncate() failed: %s (%d)", strerror(errno), errno);+ return FAILURE;+ }
Every write now truncates the file to zero first, and a failed truncation aborts the write entirely. The same release reverted Alshanetsky’s October commit outright. The advisory is upfront about the trade-off: an interrupted write can still lose session data — the exact problem the October change tried to avoid — but it can no longer leave behind a usable old tail. PHP chose data loss over a splicing opportunity, which is the right call for a security boundary, and it’s a clean example of a fix removing the actual reason a bug was possible instead of just blocking one route into it. The advisory (GHSA-fm2m-fjf5-v3cp) classifies the issue under CWE-367 and CWE-662, both about improper synchronization. Its CVSS vector pairs low attack complexity with “present” attack requirements: the vulnerable configuration is the default one, but the attacker still has to pull off a precisely timed interruption.

Every release from 8.2.0 through the November 19 builds was affected. Fixed versions are 8.2.36, 8.3.37, 8.4.28, 8.5.13, and the newly GA 8.6.0. The October 21 releases — 8.2.35, 8.3.36, 8.4.27, 8.5.12 — explicitly do not contain this fix. The source history splits into three behavioral families: pre-October releases with ordinary object handling during the callback, the October security releases that added incomplete-object transport but kept truncate-before-write (Variant A), and the RC builds carrying the October 15 commit that moved truncation after the write (Variant B). All three are spliceable. The minimal source backports PHP’s security team shipped in October for the EOL 7.4, 8.0, and 8.1 branches disable the upload-progress callback entirely, so they’re not exposed through this specific path — but older, unpatched EOL builds still carry the original vulnerable code, and PHP 8.2 itself reaches end of life on December 31, 2026.
One more change in the same release is worth flagging separately, because it’s easy to misattribute: session.upload_progress.enabled now defaults to off, and runtime changes to session settings while the feature is active get rejected. That hardening actually belongs to the fix for a different bug, CVE-2026-115560 (GHSA-658j-r8rw-q6mx) — a serializer-mismatch RCE where progress data written with php_binary or php_serialize gets later read back as php, letting an attacker-supplied delimiter inside a key feed the unserializer. An explicit enabled=1 anywhere in your php.ini, FPM pool config, or vhost config overrides the new default, so checking your own configuration is still necessary.
For anyone running PHP in production, the practical steps are short: upgrade, rebuild your container images, redeploy, and actually verify which version is serving requests, since downstream distro packages sometimes carry backported fixes without changing PHP_VERSION. If an upgrade isn’t immediate, set session.upload_progress.enabled=0 at the configuration level (an ini_set() call from application code runs too late to matter) and restart every worker. Both depthfirst and the advisory are clear that this closes off the easiest unauthenticated path, not the underlying defect, and should be paired with limiting how much untrusted data your application stores in sessions. Applications whose sessions live in Redis, a database, or any other handler that replaces records atomically aren’t exposed to this specific file-write bug at all. With PHP still powering roughly 68% of websites with a known server-side language, per W3Techs, and vendored runtimes in containers and self-hosted tools routinely running behind the host, depthfirst is now offering repository and container image scans to find exposed versions — a reasonable pitch, given that this same firm’s October findings were under active exploitation against security appliances within days of disclosure.
What this means for how patches get reviewed
PHP security research has long been better known for its clever tricks than for its CVE counts. Session upload progress was already a CTF staple before it ever got a CVE number: Orange Tsai’s “One Line PHP Challenge” at HITCON CTF 2018 raced the progress writer against a local file inclusion to execute code straight out of /tmp/sess_*. Sam Thomas’s 2018 Black Hat research turned PHAR metadata into a deserialization surface PHP 8.0 later had to defuse. php://filter chains and Charles Fol’s glibc iconv bug (CVE-2024-2961) turned limited local file inclusions into full RCE. LD_PRELOAD tricks through mail() made disable_functions largely decorative. None of that needed AI assistance — it was built by hand, through manual review and a lot of stubborn experimentation.
What’s changed is the pace. A model can hold more of a codebase in view at once and keep several competing hypotheses alive simultaneously, and on this particular bug, the adaptive controllers — the logistic boundary estimator for Variant A, the particle filter over parser depth for Variant B — only converged after several failed models and rounds of kernel-level probing that would have taken weeks to iterate by hand. That same speed applies equally to defense, and that’s the real risk: a patch can be written quickly, follow the known exploit exactly, add a guard, pass its regression test, and still leave the deeper problem untouched. The php2shell patch stopped objects from becoming active during the upload-progress callback. It never made the session write itself atomic. The original proof-of-concept stopped working. The reason the bug existed in the first place didn’t.
phpAfterShell is the case study that falls out of that gap. Checking whether a proof-of-concept still works is the first test of a fix, not the last one — and the question that actually found this bug (what happens to the file if the worker dies mid-write?) was sitting there for anyone to ask the day the October patch shipped. November’s fix answers it properly, at the storage layer, by making the leftover tail impossible to produce. The default-off change removes the pre-script writer entirely for anyone who never wanted it running in the first place. Both are root-cause fixes, and they’re the bar the next fast, AI-assisted patch should be measured against. When finding a bug and shipping a fix can both happen in a matter of days, the fix deserves at least as much scrutiny as the exploit that found it — because the bytes left on disk don’t stop working just because the proof-of-concept did.







