Summary
CVE-2026-126714 ("phpAfterShell") is a critical remote code execution vulnerability in PHP’s default file-based session handler. It was disclosed by depthfirst and fixed by PHP on November 19, 2026. An interrupted session write can leave a session file that mixes new and old data. When PHP loads that file, attacker-chosen objects can be deserialized, and with a suitable gadget chain in the application this leads to code execution. It is rated CVSS v4.0 9.2 (Critical).
Technical details
- Root cause: when updating a session, the
filessave handler writes the new data into the existing file and truncates the file only if the new data is shorter. If the write is interrupted, the file keeps the start of the new session followed by the end of the old one (CWE-367, CWE-662). - Trigger: the attacker needs to influence the session contents and interrupt the write at a useful point. Session upload progress is the easiest input path for a remote client. Applications that store large user-controlled strings in the session are another path.
- Impact: the next
session_start()deserializes the mixed data. With a suitable gadget chain in the application, this gives code execution with the privileges of the PHP worker. - Scope: only the
filessession save handler, which is PHP’s default. Redis, database and other session handlers are not affected by this defect. - Attack vector: network, no privileges or user interaction required.
Affected software
- PHP 8.2 before 8.2.36, 8.3 before 8.3.37, 8.4 before 8.4.28 and 8.5 before 8.5.13.
- The October 21, 2026 releases (8.2.35, 8.3.36, 8.4.27, 8.5.12), which fixed PHP2Shell, do not fix this issue.
- PHP 8.1 and older are end-of-life, contain the same session write code and will not be fixed.
Severity
- CVSS v4.0 base score: 9.2 (Critical)
- Vector:
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
Mitigation and recommended actions
- Upgrade to PHP 8.2.36, 8.3.37, 8.4.28, 8.5.13 or later. Rebuild container images and confirm that production runs the new version. Move PHP 8.1 and older to a supported branch.
- If you cannot upgrade immediately, set
session.upload_progress.enabled = 0in php.ini and restart the PHP workers. This removes the easiest attack path, not the flaw. - Limit the untrusted data your application stores in sessions.
- A session handler that replaces records atomically, such as Redis or a database, is not affected by this file-write defect.

