phpAfterShell: PHP Session File RCE (CVE-2026-126714)
An interrupted PHP session write can splice two sessions into one file, letting an attacker inject objects at session_start(); fixed in 8.2.36 through 8.5.13.
TL;DR
- PHP's files session handler rewrites the live session file in place. If the worker dies mid-write, bytes from the new session and the old session can share one file and decode as a third, attacker-chosen session.
- PHP 8.2 through 8.2.35, 8.3 through 8.3.36, 8.4 through 8.4.27 and 8.5 through 8.5.12 are affected when the files handler stores a session an attacker can influence.
- The CVE record rates the flaw CVSS v4.0 9.2 Critical. No exploitation in the wild is known and it is not in CISA KEV as of 2026-11-20. The researcher published a full technical write-up and an end-to-end demonstration.
- Upgrade to 8.2.36, 8.3.37, 8.4.28, 8.5.13 or 8.6.0. If you cannot, disable upload progress and stop storing large attacker-controlled strings in sessions.
Am I affected?
All of these must hold:
- PHP uses the
filessession save handler, which is the default. - The session serializer is
php, also the default. - An attacker can influence data stored in a session, for example through
PHP_SESSION_UPLOAD_PROGRESSor an application that stores a large user-supplied string. - The attacker can interrupt a session write at a useful point, or the deployment has a build where truncation happens after the write.
- A code-execution chain needs an application-defined gadget chain or a PHP-native object chain that the attacker can reach after
session_start().
PHP's advisory says the flaw is not limited to session upload progress or to PHP 8.6. The files handler defect exists in every affected branch. Applications that store only small, trusted values in sessions are much harder to exploit, because the attacker needs a long carrier string and control over the replacement data.
| Branch | Affected versions | Fixed version |
|---|---|---|
| PHP 8.6 | 8.6.0 release candidates | 8.6.0 |
| PHP 8.5 | through 8.5.12 | 8.5.13 |
| PHP 8.4 | through 8.4.27 | 8.4.28 |
| PHP 8.3 | through 8.3.36 | 8.3.37 |
| PHP 8.2 | through 8.2.35 | 8.2.36 |
| PHP 8.1 and older | out of support by the PHP project | no PHP release; check the distribution or vendor |
Check the runtime, the handler and the serializer on every host and inside every container that serves PHP:
php -v
php -i | grep -E 'session.save_handler|session.serialize_handler|session.upload_progress.enabled'
php-fpm -i 2>/dev/null | grep -E 'session.save_handler|session.serialize_handler'
docker exec <container> php -i | grep -E 'session.save_handler|session.serialize_handler'
The defaults are session.save_handler=files and session.serialize_handler=php. If both are set that way, the storage path is the one the advisory describes. A Redis, database or custom handler is outside this specific file-write defect, but each backend has its own atomicity questions.
How do I fix it?
Upgrade to the 2026-11-19 security release for your branch: PHP 8.2.36, 8.3.37, 8.4.28 or 8.5.13. PHP 8.6.0, released the same day, also carries the fix.
# Debian and Ubuntu, PHP 8.5 packages
sudo apt update
sudo apt install --only-upgrade php8.5-cli php8.5-fpm libapache2-mod-php8.5
# RHEL, Fedora and derivatives
sudo dnf upgrade 'php*'
# Alpine
sudo apk upgrade 'php*'
- Upgrade every package that carries the PHP runtime: the CLI, FPM and the Apache module.
- Restart the service that serves requests. CLI checks do not reload a running FPM pool.
- Rebuild and recreate containers from the fixed image. Pulling the image alone does not change a running container.
- Confirm the running service reports the fixed version with
php -vand the checks in "Am I affected?".
If you cannot upgrade immediately, reduce the attack surface:
- Set
session.upload_progress.enabled=0inphp.inior the FPM pool configuration. Do not useini_set()or.user.ini, because they apply after request startup. - Stop storing large attacker-controlled strings in sessions, or cap their length before they reach
session_write_close(). - Move sessions to a backend that replaces records atomically, such as a database or Redis with a transactional write.
- Restart every PHP worker so the configuration takes effect.
Disabling upload progress removes one way to control the stored data. It does not fix applications that put untrusted strings into sessions themselves, and it does not make the files handler write atomically. Treat it as a temporary control and upgrade.
What is the root cause?
ps_files_write() in ext/session/mod_files.c writes the serialized session into the existing inode with pwrite() at offset zero. It truncates the file only when the replacement is shorter than the size that was cached when the file was opened. The vulnerable code at PHP 8.5.12 is:
/* Truncate file if the amount of new data is smaller than the existing data set. */
if (ZSTR_LEN(val) < data->st_size) {
php_ignore_value(ftruncate(data->fd, 0));
}
#ifdef HAVE_PWRITE
n = pwrite(data->fd, ZSTR_VAL(val), ZSTR_LEN(val), 0);
When the replacement is at least as long as the old value, the old inode stays in place and pwrite() overwrites from the start. The kernel can copy the new buffer in parts.
If the process dies after copying k bytes, the file holds new[0:k] followed by old[k:]. The file lock prevents another session operation from entering during the write, but it does not roll back bytes when the worker disappears.
The session file is not an opaque blob. With session.serialize_handler=php, it is a sequence of key|serialized_value records. The decoder scans to the first pipe, then passes the bytes after it to php_var_unserialize(). Once that value ends, the next byte starts another record. There is no file-level length, checksum or commit marker.
That format turns the mixed file into a parser problem. The carrier session contains the attacker's object bytes inside a length-delimited string, where they are inert. The replacement session contains a shorter length field for the same string. After the splice, the decoder reads the short string, then treats the leftover object bytes as a new top-level record.
Both source sessions are valid. The third, mixed session exists only at the storage layer.
How is it exploited?
- The attacker obtains or chooses a session ID. With
session.use_strict_modeoff, PHP accepts an unissued ID; with strict mode on, the attacker visits the application once and keeps the ID. - The attacker writes a carrier session that contains a long string, with the future object bytes inside it. Upload progress is one way to make PHP write this before the application runs.
- The attacker writes a replacement session with a shorter length field for the same string. The replacement is at least as long as the carrier, so the pre-write truncate does not run.
- The attacker interrupts the
pwrite(). A memory-limit kill in a container can stop the worker inside the copy. On a build that truncates after the write, a timeout betweenpwrite()andftruncate()gives the same retained tail. - The attacker sends a normal request with the same session ID.
session_start()reads the mixed file, decodes the leftover bytes as an object, and calls its deserialization methods. - A gadget chain or a PHP-native object chain turns that object into code execution as the PHP worker. Without a chain, the attacker can still rewrite session state such as identity, authorization, CSRF or cart values.
Depthfirst's write-up describes remote calibration of the interruption point. It uses held multipart requests to approach a container memory limit for the partial-write family, and multipart bracket depth to move a timeout across the write and truncate for the other family. The public demonstration uses a harmless stdClass object as the oracle and a separate native chain for code execution, which the researchers withheld.
How does the attack flow?
An attacker-controlled carrier session and a replacement session share one inode, an interrupted write leaves a prefix of the replacement followed by the old tail, and the next session_start() turns the leftover bytes into an object.
What can an attacker do?
The demonstrated impact is code execution as the user that runs the PHP worker. It needs three things together: influence over the stored session data, an interruption at a useful point in the write, and a suitable deserialization chain in the application. The advisory states those conditions. Without a chain, the attacker can still corrupt or replace session values and change application state.
The attack can be remote. The advisory and the research use unauthenticated multipart requests to make PHP write the session before the target script runs. Authentication requirements depend on how the application exposes the affected session operations.
The flaw also corrupts session state on its own. A partial write can log users out, merge two users' state or leave a session file that fails to decode. That corruption is not proof of exploitation, but repeated decode failures around the same session IDs are worth investigating.
Why does the fix work?
The fix truncates the file to zero before every write and stops if the truncation fails:
- /* Truncate file if the amount of new data is smaller than the existing data set. */
- 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;
}
With the file empty before pwrite() starts, an interrupted write can leave a prefix of the new session, but there is no old suffix to splice into it. The file may lose session data, which is an availability problem, but it cannot contain two valid sessions with a third meaning. The check on ftruncate() also stops the write instead of silently continuing when the filesystem refuses the truncation.
The final 8.5.13 tag contains this pre-write truncate, and so do 8.4.28, 8.3.37, 8.2.36 and 8.6.0. Depthfirst's version table, dated 2026-11-17, describes the release-candidate ordering, where truncation happened after the write; the published releases we checked use the fixed order. The patch covers the files handler. Other save handlers are outside this defect, although their own interrupted-write behavior should be reviewed separately.
How do I check if I was compromised?
PHP publishes no indicators for this CVE. These checks look for the input path and for the corrupted files the technique leaves behind:
# Upload-progress requests, one documented way to control the session data
grep -Ei 'PHP_SESSION_UPLOAD_PROGRESS' /var/log/nginx/access.log /var/log/apache2/access.log
# Session files that contain a top-level object record
grep -aE '\|(O|C):[0-9]+:"' /var/lib/php/sessions/sess_* 2>/dev/null
# PHP decode failures around the same session IDs
grep -Ei 'Failed to decode session object|session_start\(\): Failed to decode' /var/log/php*.log /var/log/nginx/error.log /var/log/apache2/error.log
A legitimate application can store objects in sessions, so the O: or C: hit is a lead, not proof. Compare it with the application's own session format. A failed attempt may leave only an access-log line, and the advisory publishes no file hashes, domains or IP addresses.
Timeline
- 2026-11-11: CVE-2026-126714 reserved.
- 2026-11-19 14:00 UTC: PHP 8.2.36, 8.3.37, 8.4.28, 8.5.13 and 8.6.0 released with the fix.
- 2026-11-19: CVE-2026-126714 published.
- 2026-11-19: Depthfirst published the phpAfterShell research and the end-to-end demonstration.
FAQ
- Is PHP 8.6.0 affected? No. The 8.6.0 release carries the fix, and the final tag truncates before the write. The release candidates are in the affected range.
- Is this the same flaw as CVE-2026-115560? No. CVE-2026-115560 is a serializer mismatch between the upload-progress writer and a runtime switch. CVE-2026-126714 is an interrupted file write that splices two valid sessions. The same 2026-11-19 release fixes both.
- Do I need upload progress? No. It is one way to control the session data. An application that stores a large attacker-supplied string in a session gives the same primitive.
- Does a gadget chain have to be in my code? A native PHP object chain also works. The researchers used a native chain and withheld the final stages. An application-defined gadget chain is the other path.
- Are Redis or database sessions affected? This specific defect is in the files handler's in-place write. Other handlers do not use
ps_files_write(), but each backend has its own atomicity behavior that this advisory does not cover. - Was it exploited in the wild? No exploitation is known, and the CVE is not in CISA KEV as of 2026-11-20. The technique is public, so exposure can change quickly.
Inventory your PHP runtime with Ostorlab
Ostorlab's SCA/SBOM inventory identifies the libraries and runtime versions in an application image, which helps you find the PHP builds that still need the 2026-11-19 update: https://www.ostorlab.co/product/sca_sbom
References
- PHP advisory GHSA-fm2m-fjf5-v3cp: https://github.com/php/php-src/security/advisories/GHSA-fm2m-fjf5-v3cp (checked November 20, 2026)
- CVE-2026-126714 record: https://www.cve.org/CVERecord?id=CVE-2026-126714 (checked November 20, 2026)
- Fix commit: https://github.com/php/php-src/commit/e2d3cee9ad4b0b739f4a8ebe6a69c938399b7da6 (checked November 20, 2026)
- PHP 8.5.13 changelog: https://www.php.net/ChangeLog-8.php#8.5.13 (checked November 20, 2026)
- PHP 2026-11-19 release archive: https://www.php.net/archive/2026.php#2026-11-19-4 (checked November 20, 2026)
- Depthfirst phpAfterShell research: https://depthfirst.com/research/phpaftershell (checked November 20, 2026)
mod_files.cat PHP 8.5.12: https://github.com/php/php-src/blob/php-8.5.12/ext/session/mod_files.c (checked November 20, 2026)mod_files.cat PHP 8.5.13: https://github.com/php/php-src/blob/php-8.5.13/ext/session/mod_files.c (checked November 20, 2026)- W3Techs PHP usage: https://w3techs.com/technologies/details/pl-php (checked November 20, 2026)
- CISA KEV catalog: https://www.cisa.gov/known-exploited-vulnerabilities-catalog (checked November 20, 2026)