JupiteX Get the app
Science & Technology21 Nov 2026 · about 7 min

phpAfterShell Explained: How Hackers Could Turn a PHP Session Flaw Into Code Execution

The brief

phpAfterShell is a flaw in PHP’s default, file-based session handler. It lets an attacker manipulate a session file by interrupting a write at the right moment. The danger is that PHP may later interpret leftover file contents as valid session data, rather than simply treating the incomplete write as unusable. A session file stores each value as a name followed by serialized data. Length fields tell PHP where strings end, but the file has no marker showing that a write finished. If a worker stops partway through, new data can remain at the start of the file while old data remains at the end. An attacker can manipulate lengths so the old data reads as a separate serialized object. On the next request that calls session start(), PHP loads that object. Depthfirst’s public proof uses a harmless stdClass object; code execution requires a suitable gadget chain in the application. PHP’s current releases fix the flaw by emptying the file before writing and stopping if that step fails.

01

What is phpAfterShell, and what weakness in PHP’s file-based session handler does it exploit?

phpAfterShell is a flaw in PHP’s default, file-based session handler. It lets an attacker manipulate a session file by interrupting a write at the right moment. The danger is that PHP may later interpret leftover file contents as valid session data, rather than simply treating the incomplete write as unusable.

A session file stores each value as a name followed by serialized data. Length fields tell PHP where strings end, but the file has no marker showing that a write finished. If a worker stops partway through, new data can remain at the start of the file while old data remains at the end. An attacker can manipulate lengths so the old data reads as a separate serialized object.

On the next request that calls session_start(), PHP loads that object. Depthfirst’s public proof uses a harmless stdClass object; code execution requires a suitable gadget chain in the application. PHP’s current releases fix the flaw by emptying the file before writing and stopping if that step fails.

02

How severe is the flaw, and which PHP releases or session setups are affected?

The flaw is rated 9.2 out of 10 on the CVSS 4.0 scale by PHP’s maintainers, making it a critical security issue. PHP’s current releases include the fix, but servers running older vulnerable builds may remain exposed until updated.

The defect is in the files session handler, which PHP uses by default. Session data kept in Redis, a database, or another store is outside this specific flaw. The article lists PHP 8.2.35, 8.3.36, 8.4.27, and 8.5.12 as releases where upload progress was on by default; the corresponding fixed releases are 8.2.36, 8.3.37, 8.4.28, and 8.5.13. PHP 8.6.0 also includes the fix.

PHP 8.1 and older are end-of-life. The company says official end-of-life mitigation branches for 7.4, 8.0, and 8.1 are not affected, while older unpatched builds of those versions are. Linux distribution packages may contain the fix without changing the displayed PHP version.

03

What could an attacker do if they exploit the flaw and the application has a suitable gadget chain?

The most serious possible result is code execution on the server. That outcome depends on a second weakness: the application must contain a suitable gadget chain that can be triggered by an object PHP loads from the session. Without that condition, the article does not claim that exploitation automatically runs code.

The attack can make PHP create an attacker-chosen serialized object from a mixed session file. On the path Depthfirst tested, upload progress causes PHP to write to the user’s session before the application’s own code runs. If the write is interrupted, old file contents can be exposed as a separate object when a later request starts the session.

Depthfirst’s public proof uses stdClass, a harmless built-in object, and does not itself demonstrate server code execution. The article says a suitable application gadget chain can turn the object-loading weakness into code execution. Neither PHP’s maintainers nor Depthfirst reported attacks using phpAfterShell, but the fixed releases address the underlying flaw.

04

How can stopping a session-file write halfway make PHP load an object chosen by an attacker?

PHP stores session values as names followed by serialized data. Length fields inside that data tell PHP where strings end. But the file does not mark a completed write, so a write that stops early can leave a mixture of new and old contents. That matters because PHP may parse the mixture as valid session records later.

In Depthfirst’s tested path, upload progress triggers a session write before the application code runs. PHP locks the file during a write, but the lock cannot undo a write if the worker process dies partway through. The beginning of the file may contain new data while its end still holds old data. By setting lengths in the new data, an attacker can make text in the old data appear to be a separate record, including a serialized object.

When a later request calls session_start(), PHP loads that record and creates the object. The researchers’ public proof uses stdClass. The fixed releases empty the session file before each write and stop if emptying it fails, preventing old data from being left behind for this attack.

05

What fixes the vulnerability, and why is turning off upload progress only a partial workaround?

The recommended fix is to install the fixed release for the PHP branch in use. The update empties the session file before each write and stops the write if emptying fails. That prevents old contents from remaining at the end of a cut-off write, though an interrupted write can still cause session data loss. Sites using the files handler should apply the update.

If updating is not yet possible and the app does not use upload progress, administrators can set session.upload_progress.enabled = 0 in php.ini or the server’s PHP settings, then restart PHP workers. The feature can otherwise trigger a session write during a multipart upload, before the app’s code runs. The fixed releases also turn upload progress off by default.

Disabling the feature is only a partial workaround. An application that stores attacker-controlled data in sessions through another route remains affected, according to the maintainers. Moving sessions to a store that replaces records in one step also avoids this defect, but updating remains recommended for sites using file-based sessions. Rebuild and redeploy container images, and verify the PHP version serving requests.

06

How does phpAfterShell differ from the earlier PHP2Shell flaws and their October 21 fixes?

phpAfterShell is distinct from the earlier PHP2Shell flaws, despite a shared connection to session handling. PHP’s October 21 releases fixed two critical flaws known as PHP2Shell. Those releases did not contain the phpAfterShell fix, so servers updated on October 21 remain affected until they install today’s releases.

The article says the earlier emergency fixes addressed an earlier attack via the same step: a session write. It does not give further technical detail about how the PHP2Shell attacks worked. The same upload-progress setting was also listed on October 21 as a temporary measure for one of those flaws. That setting does not fully fix phpAfterShell, because attacker-controlled data can enter sessions in other ways.

Today’s releases fix phpAfterShell by emptying the session file before each write and stopping if that step fails. They also switch upload progress off by default. The Hacker News compared the source code and found the feature on by default in the October 21 releases and off in today’s listed releases. Servers that disabled it earlier still need the software update.

07

What are sessions and serialized data, and why do web applications use them to remember information between requests?

In ordinary web use, a session is a way for an application to associate information with a user across separate requests. This explanation uses general knowledge: the article does not describe the broader purpose of sessions. Applications use them so information does not have to be supplied afresh with every request.

Serialized data is a representation of values arranged so software can store them and later reconstruct them. The article describes PHP session files as storing each value under a name, followed by serialized data. Length fields tell PHP where strings end. In the phpAfterShell attack, a cut-off write can leave old and new serialized content together, and altered lengths can make part of the old content appear to be a separate object.

A later request that calls session_start() loads the record and creates the object. This is why the file format matters: PHP interprets the stored data when it opens the session. The fixed releases empty the session file before writing and stop if that step fails. The article also says applications should limit untrusted data stored in sessions.

This brief was written by AI from the original reporting and checked by other models. Names, figures and quotes come from the source; read it for full context.

Read more in the JupiteX app

Pulse is free. New stories every 4 hours, each one broken into the questions that explain it.

Or read more news on the web