PHP's default file-based session storage can be made to return objects an attacker chose, by cutting off a session write at the right moment. When combined with a second weakness, such as a suitable gadget chain in the app, those objects can allow the attacker to run code on the server.
Today's PHP releases fix the flaw, called phpAfterShell.
The flaw is tracked as CVE-2026-126714 and rated 9.2 out of 10 on the CVSS 4.0 scale by PHP's maintainers. Depthfirst, a security company, says it found the flaw and reported it to the maintainers.
The October 21 PHP releases, which fixed two critical flaws known as PHP2Shell, do not contain this fix. Servers updated then remain affected until they install today's releases. Neither the maintainers nor the company reports any attacks using phpAfterShell.
Who Is Affected and What to Do
These releases are affected, according to the maintainers' security advisory:
| Branch | Affected releases | Fixed release |
|---|---|---|
| PHP 8.2 | Before 8.2.36 | 8.2.36 |
| PHP 8.3 | Before 8.3.37 | 8.3.37 |
| PHP 8.4 | Before 8.4.28 | 8.4.28 |
| PHP 8.5 | Before 8.5.13 | 8.5.13 |
PHP 8.6.0, also released today, includes the fix.
The flaw is in the files session handler, which PHP uses by default. Sessions kept in Redis, a database, or another store are outside this defect, though each store's handling of a cut-off update needs its own check.
Whether an attacker needs to log in depends on how the app exposes its session handling.
On the path the company tested, the attacker uses upload progress, a PHP feature that records the progress of a file upload in the user's session. Where the feature is on, a multipart form upload that carries its field makes PHP write to the session before the app's own code runs. The app does not need an upload page, only any page that opens the session later.
PHP 8.1 and older are end-of-life. The official end-of-life mitigation branches for 7.4, 8.0, and 8.1 are not affected, but older unpatched builds of those versions are, according to the company.
The company's remediation guidance sets out these steps:
- Install the fixed release for your branch, as listed above. If you run PHP 8.1 or older, move to a supported branch.
- Rebuild any container images and redeploy.
- Check that the PHP version serving web requests is the new one.
If you cannot update yet and your app does not use upload progress, set session.upload_progress.enabled = 0 in php.ini or the server's PHP settings, then restart the PHP workers. Also limit the untrusted data your app stores in sessions.
Switching the feature off is not a full fix. It closes the upload path, but apps that put attacker-controlled data into sessions in other ways remain affected, the maintainers say.
The maintainers listed the same setting on October 21 as a temporary measure for one of the PHP2Shell flaws. Servers that have kept it off since then still need the update.
Moving sessions to a store that replaces records in one step also avoids this defect. The update is still the recommended fix for sites that keep the files handler.
Linux distribution packages may include the fix without changing the PHP version number, according to the company, so the version number alone may not indicate whether a server is fixed.
Once installed, the fixed releases empty the session file before each write and stop the write if that step fails. A cut-off write can still lose session data, but it can no longer leave old data behind for an attacker to use.
The updates also switch upload progress off by default. The Hacker News compared PHP's source code for the October 21 releases and today's. The built-in setting is on in 8.2.35, 8.3.36, 8.4.27 and 8.5.12, and off in 8.2.36, 8.3.37, 8.4.28, 8.5.13 and 8.6.0.
The release notes do not mention or explain the change. The sample php.ini files still show the old setting in a commented-out line. A php.ini file, distribution package, or hosting panel that switches the setting on will keep it on.
Where nothing else sets it, apps that rely on upload progress will need it switched back on after the update.
The same releases also fix other PHP security flaws.
How the Attack Works
The attack starts with the session write that upload progress makes before the app's code runs, Depthfirst's researchers say in their technical analysis.
A PHP session file stores each value as a name followed by serialized data. Length fields in that data tell PHP where each string ends, and nothing in the file marks a write as finished.
PHP locks the file while it writes, but the lock cannot undo a write that stops halfway. If the worker process dies partway through, the file can retain the start of the new data and the end of the old data.
By setting the lengths in the new data, an attacker can make text that sat harmlessly inside the old data read as a separate record, including a serialized object. The next request that calls session_start() loads that record and creates the object.
The researchers' public proof uses a harmless built-in object, stdClass, which appears in the session once the file is mixed.
The emergency PHP2Shell fixes on October 21 addressed an earlier attack via the same step.
"The original exploit stopped working, but the underlying problem was still there," the researchers say of the PHP2Shell patch.
That exploit needed objects to become active while PHP recorded upload progress, so the maintainers limited which classes can load at that moment. The change did not touch the file write. The object data still reaches the disk and becomes active later, when an ordinary request calls session_start().
The attack depends on stopping the write at the right moment. The maintainers say one way is a hard memory-limit failure in another thread of a threaded PHP build, which can kill the process mid-write.
Code execution then still needs a suitable gadget chain in the app, and the flaw can also corrupt session state.
In the researchers' own Linux tests, PHP's execution timeout fired only after the write had finished, so they used an out-of-memory kill to stop the worker mid-write instead.
The planted object appeared on the 11th attempt in a fresh run. That count measures getting the file into the right state on their servers, not how often code execution succeeds.
Their own chain needed no gadget from the app, the researchers say. It used a second bug instead, memory corruption in one of PHP's built-in classes.
They are holding back its details for coordinated disclosure and have not said whether that bug is fixed in today's releases.
The same trick can also replace ordinary session values, such as who is logged in, their permissions, or a CSRF token, before the app checks them, the researchers say.
Found this article interesting? Follow us on Google News, Twitter and LinkedIn to read more exclusive content we post.


