← All articles

PHP phpAfterShell flaw fixed in critical security updates

PHP phpAfterShell flaw fixed in critical security updates

phpAfterShell is a critical PHP flaw that can make a server load attacker-controlled objects from a damaged session file. When an application also contains a suitable gadget chain, a sequence of existing code paths that can be misused together, the flaw can lead to code execution on the server.

The vulnerability is tracked as CVE-2026-126714 and PHP's maintainers rate it 9.2 out of 10 under the CVSS 4.0 scoring system. Depthfirst says it discovered and reported the issue. Neither PHP's maintainers nor Depthfirst has reported attacks using phpAfterShell.

The problem affects PHP's default files session handler, which stores session information in files. The affected releases are PHP 8.2 versions before 8.2.36, fixed in 8.2.36; PHP 8.3 versions before 8.3.37, fixed in 8.3.37; PHP 8.4 versions before 8.4.28, fixed in 8.4.28; and PHP 8.5 versions before 8.5.13, fixed in 8.5.13. PHP 8.6.0, released at the same time, also contains the fix.

The October 21 PHP releases that fixed two critical flaws called PHP2Shell did not fix phpAfterShell. Servers updated on that date therefore remain exposed until they install the newer releases. PHP 8.1 and older are end-of-life, meaning they no longer receive normal support. Depthfirst says the official end-of-life mitigation branches for PHP 7.4, 8.0 and 8.1 are not affected, but older unpatched builds of those versions are.

The vulnerability is limited to the files session handler. Sites that store sessions in Redis, a database or another storage system are outside this specific defect, although each storage system needs its own review of what happens when an update is cut off. Whether an attacker must first log in depends on how an application exposes its session handling.

Depthfirst tested an attack path involving upload progress, a PHP feature that records the progress of a file upload in the user's session. When the feature is enabled, a multipart upload containing the relevant field can make PHP write to the session before the application's own code runs. The application does not need to provide an upload page. It only needs some page that opens the session later.

A PHP session file stores values as names followed by serialized data, which means data converted into a format PHP can save and reload. Length fields tell PHP where each string ends, but the file contains no marker showing that a write has completed. PHP locks the file during a write, yet that lock cannot undo a write that stops halfway. If the worker process dies mid-write, the file can contain the beginning of new data followed by the end of old data.

By controlling lengths in the new data, an attacker can make text that was harmlessly inside the old data appear to be a separate record. That record can include a serialized object. On a later request, session_start() reads the file and creates the object. Depthfirst's public proof of concept uses the harmless built-in object stdClass, which appears in the session after the file has been mixed in this way.

The PHP2Shell emergency fixes addressed an earlier attack using the same upload-progress step. Those changes stopped the original exploit, according to Depthfirst, but did not repair the underlying file-write problem. The earlier attack required objects to become active while PHP recorded upload progress, so the maintainers restricted which classes could load at that stage. The object data could still reach disk and become active later, when a normal request called session_start().

The attack requires the write to stop at the right moment. PHP's maintainers say one possible trigger is a hard memory-limit failure in another thread of a threaded PHP build, which can kill the process during the write. In Depthfirst's Linux tests, PHP's execution timeout fired only after the write had finished, so the researchers used an out-of-memory kill to stop the worker instead. The planted object appeared on the 11th attempt in a fresh run on their servers. That count measures how often they got the file into the required state, not how often code execution succeeds.

Code execution still requires a suitable gadget chain in the application. Depthfirst says its own chain did not need an application gadget and instead used a second bug involving memory corruption in one of PHP's built-in classes. The researchers are withholding details for coordinated disclosure and have not said whether that second bug was fixed in the current PHP releases. The session attack can also corrupt session state or replace ordinary values, including the identity of the logged-in user, their permissions or a CSRF token, a value used to help stop unwanted requests from being accepted.

The recommended action is to install the fixed PHP release for the branch in use, rebuild container images and redeploy them, then confirm that the PHP version serving web requests is the updated one. Linux distribution packages may include the correction without changing the PHP version number, so the version alone may not prove that a server is fixed.

If an immediate update is impossible and the application does not use upload progress, administrators can set session.upload_progress.enabled = 0 in php.ini or the server's PHP settings and restart PHP workers. This is only a temporary measure. It closes the upload-progress route, but applications that store attacker-controlled data in sessions through other routes remain affected. The same setting was listed as a temporary measure for one PHP2Shell flaw on October 21, so servers that have left it disabled since then still need the phpAfterShell update.

Moving sessions to a store that replaces records in one step also avoids this defect, but updating remains the recommended fix for sites that use the files handler. The corrected releases empty the session file before each write and stop the write if that emptying step fails. A cut-off write can still lose session data, but it can no longer leave old data behind for an attacker to reuse.

The updates also disable upload progress by default. A comparison of PHP source code found the setting enabled in 8.2.35, 8.3.36, 8.4.27 and 8.5.12, and disabled in 8.2.36, 8.3.37, 8.4.28, 8.5.13 and 8.6.0. The release notes do not explain the change, while sample php.ini files still show the old setting in a commented-out line. A php.ini file, distribution package or hosting panel that enables the feature will keep it enabled. Applications that rely on upload progress may need administrators to turn it back on after updating.

For website owners using managed WordPress, AEU Hosting offers managed WordPress hosting, secured end to end, which is relevant when reviewing PHP updates and session handling.

Also available in: DeutschItalianoShqip