phpAfterShell: Critical RCE in PHP’s Default Session Handler (CVE-2026-126714) – 20261120019

SeverityCRITICAL
Threat CategoryVulnerability – Unauthenticated Remote Code Execution (object injection via session files)
Affected PlatformsPHP using the default file-based session save handler (session.save_handler = files): all versions before 8.2.36, 8.3.x before 8.3.37, 8.4.x before 8.4.28, and 8.5.x before 8.5.13. End-of-life PHP 8.1 and earlier receive no fix
CVECVE-2026-126714 (“phpAfterShell”)
CVSS9.2 (CVSS v4.0, Critical, assigned by the PHP Group) – CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H

1. Overview

CVE-2026-126714, named “phpAfterShell” by its finder, is a critical vulnerability in PHP’s default file-based session save handler (session.save_handler = files). When PHP writes updated session data, it overwrites the existing session file in place without first clearing it. If that write is interrupted at the right moment, the file is left holding the beginning of the new session followed by the end of the old one. By carefully arranging the data, an attacker can make the spliced file decode so that bytes that were ordinary string data are instead parsed as serialized PHP objects. The next time the session is loaded, those objects are instantiated, an object-injection primitive that can lead to remote code execution.

PHP published the fix and its advisory (GHSA-fm2m-fjf5-v3cp) on 19 November 2026. The flaw is a time-of-check or time-of-use race condition (CWE-367 or CWE-662) in code that, by the PHP maintainers’ assessment, has been present since PHP 4.1.0. Notably, it is a distinct exploitation path from the earlier PHP session vulnerability patched on 21 October 2026: according to the finder, systems updated to those October releases are still vulnerable to phpAfterShell and require this new update.

2. Who is Affected

PHP runs a very large share of the world’s web applications, and the affected session handler is PHP’s default, so the potential exposure is broad, including many government and enterprise web services in Bhutan. Any site running an unpatched PHP 8.2–8.5 release that uses file-based sessions should be considered at risk.

Points that determine real exposure:

  • The default files session handler is affected; sites using an external session store (for example Redis or a database) that replaces records atomically are not affected by this particular defect.
  • Exploitation is conditional but realistic. An attacker must be able to influence session data and interrupt a session write at a precise point (reflected in the CVSS “attack requirements” flag). This is achievable remotely – the finder reports reaching the vulnerable state over HTTP in roughly 10–11 attempts in their testing.
  • The October 2026 PHP patch does not cover this flaw. Per the finder, the 21 October 2026 releases (PHP 8.2.35, 8.3.36, 8.4.27, 8.5.12) that fixed the previous session vulnerability remain vulnerable to phpAfterShell.

As of this advisory, BtCIRT is not aware of any confirmed exploitation within Bhutan; no in-the-wild exploitation has been publicly reported, and CVE-2026-126714 is not listed in the CISA Known Exploited Vulnerabilities (KEV) catalog (checked against catalog version 2026.11.18, 18 November 2026). Only a harmless proof-of-concept demonstrating the object-injection primitive, plus a technical write-up, are public; the finder is withholding the weaponized code-execution chain for coordinated disclosure. The severity is rated CRITICAL because:

  • It is an unauthenticated, network-reachable path to remote code execution (PHP Group CVSS v4.0 9.2) in the default configuration of extremely widely deployed software.
  • The finder reports a working end-to-end chain and demonstrated the technique over HTTP; public disclosure of a technical write-up shortens the time to practical exploitation.
  • Even short of code execution, the flaw can corrupt session state, with integrity and availability consequences for affected applications.

3. How the [Threat/Vulnerability/Attack] Works

The vulnerability is a race condition in how PHP’s default session handler writes session files to disk.

Stage 1 — An interrupted write leaves a spliced session file

When a request updates the session, PHP writes the new serialized session data over the existing sess_<id> file without clearing the old contents first (the truncation is a separate operation). A file lock prevents concurrent session access, but it does not make the write atomic. If the write is interrupted partway, the file is left as a prefix of the new session followed by the leftover tail of the old one.

Stage 2 — The spliced file decodes into injected objects

PHP’s session decoder reads key|serialized-value records and uses the length fields inside serialized strings to decide where each record ends. By choosing the lengths in the new prefix, an attacker can make leftover bytes from the old file – bytes that previously sat inside a string value – be parsed as a new, top-level serialized object. The corruption is written before PHP validates the data: the request may then error out, but the malformed file remains on disk, and the next session_start() deserializes the injected objects.

Stage 3 — Object injection to code execution

Deserializing attacker-chosen objects is a classic object-injection primitive. PHP’s advisory states that turning this into code execution requires a suitable “gadget chain” in the application. The finder, however, reports a full chain that relies only on PHP-native classes and “does not depend on an application-defined gadget class,” with the exploit internals withheld for coordinated disclosure. In practice this means the absence of a known gadget chain in your own application code is not a safe reason to defer patching.

Attack path (how the write is influenced and interrupted)

  • Influence: PHP’s session upload-progress feature writes attacker-controlled data into the session file during a multipart upload (a field named PHP_SESSION_UPLOAD_PROGRESS), without the application calling session_start() itself. Applications that store large user-controlled strings in the session are also exposed.
  • Interruption: the finder describes forcing the write to stop at a chosen point, for example by driving the worker toward a memory limit so it is killed mid-write, or by widening the timing window between the write and the truncation, and calibrating this remotely over HTTP.

4. Indicators to Watch For

Exposure (am I vulnerable?)

  • The PHP build actually serving traffic is below the fixed version. Check the runtime that handles web requests like PHP-FPM (php-fpm -v) or the Apache module, not only the command-line PHP, as they can differ. Fixed versions are 8.2.36, 8.3.37, 8.4.28 and 8.5.13.
  • The application uses file-based sessions (session.save_handler = files, the default), confirmed with php -i or the effective FPM pool configuration.
  • Distribution packages may be fixed by a backport without changing the reported PHP version string, so verify against your distribution’s security advisory as well as php -v.
  • Session upload progress enabled (session.upload_progress.enabled = 1) increases the attack surface, though it is not the only path.

Possible exploitation

  • Unexpected PHP worker crashes or out-of-memory kills correlated with multipart uploads, and corrupted or malformed session files under the session save path, for example /var/lib/php/sessions.
  • Anomalous behaviour of a PHP application immediately after session loading, or unexpected process or network activity by the PHP worker account – signs consistent with the described technique. (No public indicators of compromise have been published.)

5. Recommendations

5.1. For organizations and government offices

  • Patch PHP and restart workers. Update to the fixed release for your branch – 8.2.36, 8.3.37, 8.4.28 or 8.5.13, or your distribution’s patched package, then restart PHP-FPM or the web server so the running workers pick up the fix.
  • Do not assume the October update is enough. Systems updated to the 21 October 2026 releases (8.2.35, 8.3.36, 8.4.27, 8.5.12) for the earlier PHP session vulnerability are still vulnerable to this one and must be updated again. This supersedes the patch guidance in BtCIRT’s 21 October 2026 PHP advisory.
  • Plan for end-of-life PHP. PHP 8.1 and earlier will not receive this fix; migrate those systems to a supported, patched branch, and in the meantime isolate and closely monitor them.
  • If you cannot patch immediately, apply interim mitigations – understanding they reduce, not remove, the risk: disable session upload progress (session.upload_progress.enabled = 0) to close the easiest path. Note this does not protect applications that independently store attacker-controlled data in sessions, and minimize untrusted data stored in sessions.
  • Consider an atomic session backend. Per the vendor and finder, moving sessions to a store that replaces records atomically (such as Redis or a database) avoids this file-write defect; evaluate this for high-value, internet-facing applications.
  • Prioritize and monitor. Patch internet-facing PHP applications first, and watch for the indicators in Section 4 – worker crashes tied to uploads, corrupted session files, and anomalous post-session behaviour.

6. Reporting

If you suspect your organization, device or account has been affected by this threat, or observe activity matching this pattern, please report it to BtCIRT at cirt@btcirt.bt

7. Sources and References

  1. MITRE / CVE Record — CVE-2026-126714 (CNA: PHP Group), 19 November 2026. https://www.cve.org/CVERecord?id=CVE-2026-126714
  2. PHP — Security Advisory GHSA-fm2m-fjf5-v3cp, “Partially overwritten session files can lead to remote code execution,” 19 November 2026. https://github.com/php/php-src/security/advisories/GHSA-fm2m-fjf5-v3cp
  3. depthfirst — “phpAfterShell” research write-up, 19 November 2026. https://depthfirst.com/phpaftershell

Scroll to Top