>_ AYSOLI CYBERSECURITY
← Back to Advisories
HIGHAYS-2026-013 · 2026-11-20

CVE-2026-126714 – phpAfterShell: Partially Overwritten Session Files Enable Code Execution in PHP

A flaw in PHP's default session storage can leave session files partially overwritten. Attackers can use it to smuggle their own objects into a session without authentication and, under certain conditions, run code on the server. October's PHP2Shell updates do not close this hole – PHP has to be updated again.

What happened?

By default, PHP stores sessions as files on the server (sess_…). When saving, PHP simply writes the new data over the existing file without clearing it first. If the write is interrupted halfway, for example because the PHP process dies at the memory limit or on a timeout, a mix is left behind: the new data at the front, the remainder of the old data at the back.

The session format has neither length fields nor checksums. On the next access, PHP therefore reads the jumbled file without complaint, including parts an attacker previously wrote into the session. Those parts are restored as PHP objects. This first of all allows changing the contents of a session, such as login state, shopping cart or CSRF protection. Code execution additionally requires a suitable object chain ("gadget chain"). According to the PHP advisory, it has to exist in the application. The researchers at depthfirst say they have also found a chain in PHP itself, but have not published it so far.

The flaw was found while analyzing October's PHP2Shell patches. The fixed versions were released on November 19. PHP rates it at CVSS 9.2, Red Hat at 8.1 because of the high attack complexity. No attacks in the wild are known so far. Only a harmless demonstration is public; the code-execution part is missing.

Who is affected?

  • PHP 8.2 to 8.5 before 8.2.36, 8.3.37, 8.4.28 and 8.5.13 respectively. This includes the October versions with the PHP2Shell fix (8.2.35, 8.3.36, 8.4.27, 8.5.12). If you patched in October, you are still vulnerable.
  • Applications that store PHP sessions in files. That is the default (session.save_handler = files). Sessions in Redis, Memcached or a database are not affected by this flaw.
  • The easiest attack path runs through upload progress tracking (session.upload_progress), which is enabled by default: a crafted file upload writes data into the session before the application even runs. Applications that store user input in the session are just as exposed.
  • PHP 8.1 and older are affected too but no longer receive a fix. The only route there is through your distribution or vendor.
  • Distribution status (November 20): Debian 12 and 13, Amazon Linux 2023 and the official Docker images have fixed packages. Updates from Red Hat (RHEL 7 to 10) and Ubuntu are still pending.

What needs to be done?

  1. Update: Install PHP 8.2.36, 8.3.37, 8.4.28 or 8.5.13 – or the security update from your distribution or hosting provider. Then restart PHP-FPM or Apache and rebuild container images. Distributions often backport the fix into older version numbers. What matters is therefore your distribution's advisory and the PHP version that actually serves web requests, not the command-line one.
  2. Turn off upload progress: Set session.upload_progress.enabled=0 in php.ini or the FPM pool, not via ini_set() or .user.ini, and restart the workers. The fixed versions turn the feature off by default. An explicit setting in your configuration overrides that, though, so check it after the update as well.
  3. Limit session contents: Don't store large, user-supplied data in the session unchecked. This closes the second attack path that the interim measure from step 2 leaves open.
  4. Switch in the medium term: Where it is planned anyway, a session store such as Redis or a database instead of files is worth it.
  5. Check for compromise: Look for clusters of requests containing PHP_SESSION_UPLOAD_PROGRESS in the access log, for repeated "Failed to decode session object" messages in the PHP error log and for web server processes spawning a shell. Session files that unexpectedly contain objects (O:…) are another indicator, although some applications legitimately store objects there.
  6. Isolate legacy systems: Systems running PHP 8.1 or older that no longer receive updates don't belong directly on the internet.

This advisory is for informational purposes. For support in securing your web servers, contact us.

Ready to know your attack surface?

Tell us briefly about your project. We'll come back with a concrete proposal.

Request a first call