Most PHP security advice is about your code: validate input, escape output, use prepared statements. PHP2Shell is different. The bug is in the PHP engine itself. You can write perfectly clean code, follow every best practice, and still be exposed, because the vulnerable code runs before your application even starts.
This note is written for developers and students. It explains what happened, how the flaws work (with simplified code), what it looks like when it goes wrong, and the exact steps to fix and verify your servers. It reflects what was public on 22 October 2026; the situation is moving fast, so always check the official PHP advisories linked at the end.
Reading time: about 12 minutes.
What is PHP2Shell, in one paragraph
PHP2Shell is the nickname for two critical remote code execution (RCE) flaws in PHP’s core, tracked as CVE-2026-109618 and CVE-2026-109619. The PHP security team rates both 9.2 (Critical) on CVSS v4.0. Both can be triggered over the network with no login, and both can end with an attacker running code as your web server’s user. PHP shipped fixes on 21 October 2026.
| CVE-2026-109618 | CVE-2026-109619 | |
|---|---|---|
| Advisory title | RCE via OOM corruption | RCE via stale global state |
| Bug class | Invalid memory used after an out-of-memory abort | Use-after-free of request memory |
| Trigger | Make PHP run out of memory at the wrong moment | Leave stale state behind, then hit the same worker again |
| Impact | Unauthenticated code execution (confirmed on Apache mod_php) |
Code execution and memory disclosure |
Why this one is different
Three things make it serious:
- It is unauthenticated. The attacker needs network access to your web server and nothing else.
- It is in the runtime. Laravel, Symfony, WordPress, Drupal, a plain
index.php: all sit on top of the same engine. - It is old. Researchers trace the affected code back to PHP 5.4 (2012), so a very large installed base is in scope.
Timeline
The practical lesson: with a leak, the window between “public” and “being attacked” is hours, not weeks. Public exploit code is also circulating and is unverified; do not run it. It may itself contain malware.
How the bugs work (simplified, code level)
The real fixes are in C inside php-src. The snippets below are simplified teaching sketches of the patterns described in the official advisories, not copies of the actual source.
Bug 1: running out of memory at the wrong moment (CVE-2026-109618)
PHP enforces memory_limit. When a request exceeds it, PHP must stop the request immediately. Historically it does that with longjmp(), a C function that jumps out of the current code straight to a recovery point, skipping everything in between.
That is fine when nothing important is half-finished. The problem is when the jump happens while request data is only partly built:
// Simplified sketch, NOT real php-src code
void start_request(void) {
request->headers = NULL; // not ready yet
request->files = NULL; // not ready yet
request->headers = alloc_headers(); // <- memory limit hit HERE
// ^ allocation fails, PHP calls longjmp() and jumps away.
// request->files is never initialised properly.
request->files = alloc_files();
}
void shutdown_request(void) {
// Cleanup code TRUSTS the structure is valid
free_all(request->headers);
free_all(request->files); // <- garbage pointer: memory corruption
}
An attacker’s job is simply to make the request consume memory until the limit trips at the right instant. The advisory describes ways to do that with a crafted multipart upload, for example parts with many headers that use far more PHP memory than their size on the wire, or many empty file fields that still create metadata. No special access is needed.
Bug 2: stale state that outlives its memory (CVE-2026-109619)
PHP workers (PHP-FPM children, Apache processes) are long-lived and serve many requests one after another. At the end of each request PHP frees the request heap. Some C globals, such as error, session and decoder state, are supposed to be reset before that memory is freed.
If a request dies abnormally (a fatal error, a timeout, an out-of-memory), that reset can be skipped. The global still points at memory that is now gone:
// Simplified sketch, NOT real php-src code
static session_state *current_session; // survives between requests
void handle_request_A(void) {
current_session = heap_alloc(sizeof(session_state));
...
fatal_error(); // request dies abnormally
// current_session = NULL; // <- reset is SKIPPED
}
void end_request(void) {
heap_free_all(); // heap freed, pointer now dangling
}
void handle_request_B(void) {
// Runs BEFORE normal initialisation (e.g. upload progress)
use(current_session); // <- use-after-free
}
The advisory lists two confirmed “consumers” of the stale state: session upload progress (a feature that runs before your script and is enabled by default) and, on PHP 8.5, fatal_error_backtraces. It also notes that any early INI diagnostic, such as a deprecation or warning raised by a per-request setting, can act as a consumer, and that hiding messages with error_reporting or @ does not help.
Student takeaway: two classic C problems, use of invalid memory and use-after-free, appear here at the level of the whole PHP request lifecycle. PHP is memory-safe for your code. The runtime underneath it is C, and C is not.
Which servers are most exposed
| Setup | Risk | Why |
|---|---|---|
Apache with mod_php |
Highest | Shutdown runs even after a failed startup; confirmed unauthenticated RCE |
| PHP-FPM (Nginx or Apache) | High | Fewer direct paths, but the session path has been validated under suitable app conditions |
| php-cgi, FrankenPHP, LiteSpeed | Treat as exposed | Considered at risk by the PHP team |
| CLI scripts / queue workers | Lower | Not serving web requests, but still patch them |
Real-world failure scenarios
These are illustrative composites, built from how the advisories say the flaws behave and from the mistakes teams routinely make. They are not reports about specific companies.
Scenario 1: “We patched, but nothing changed”
A team runs apt upgrade. The package updates. Nobody restarts PHP-FPM. The old process is still in memory, still running vulnerable code, for days. The server scan says “patched”; the running worker says otherwise.
Fix: restart or redeploy every worker, then confirm the running process, not just the package.
Scenario 2: The container that was never rebuilt
A Dockerfile says FROM php:8.3-apache. The image was built in July and sits in a registry. Once a fixed base image is published, the tag moves on, but production keeps running the old build. Worse, it is Apache with mod_php, the highest-risk setup.
Fix: rebuild with --pull, redeploy, and check php -v inside the running container.
Scenario 3: The “stable” legacy box
A company’s internal ERP runs on PHP 7.4 on a server nobody wants to touch. PHP 7.4 has had no official release for years. For this issue the PHP team published only minimal source backports for 7.4 to 8.1. The box is reachable from the internet through a customer portal.
Fix: get a vendor-patched build (your distro or an LTS vendor) or upgrade. Until then, remove it from the internet.
Scenario 4: False comfort from a config tweak
An admin sets session.upload_progress.enabled=0 and memory_limit=-1, writes “mitigated” in the ticket and moves on. Both are interim measures. The advisories say updating is the only complete fix, and that if an allocation fails for another reason the dangerous path can still run. Removing the memory cap also makes a plain memory-exhaustion denial of service easier.
Fix: use mitigations to buy time, never as the end state.
Scenario 5: A compromised box that nobody noticed
Exploitation leaves normal-looking traffic: a few large multipart requests, a worker that crashes and respawns. Weeks later the server is sending spam from a PHP process. The patch arrives long after the attacker is already in.
Fix: patching closes the door but does not evict someone already inside. Check for the signs below.
Which PHP versions are safe?
“Safe” means at or above the fixed release for your branch:
| PHP branch | Safe version | Status |
|---|---|---|
| 8.5 | 8.5.12 or newer | Fixed |
| 8.4 | 8.4.27 or newer | Fixed |
| 8.3 | 8.3.36 or newer | Fixed |
| 8.2 | 8.2.35 or newer | Fixed |
| 8.1, 8.0, 7.4 | No official release | Only minimal source backports; use a vendor-patched build or upgrade |
| 7.3 and older (down to 5.4) | None | End of life, no fix; upgrade |
A few important caveats:
- Distros backport fixes under old version numbers. Debian, Ubuntu, RHEL and others may show
8.2.30-somethingand still be patched. Check the vendor security notice or package changelog, not justphp -v. php -vmay lie about the web server. The CLI binary and the one serving requests can be different installs (or different containers).- Hosting panels and bundled PHPs (cPanel, Plesk, Docker images, vendor appliances) each ship their own PHP. Inventory all of them.
What to do today: a prevention playbook
Step 1: Find every PHP you run
# What the CLI says (may NOT be what serves your site)
php -v
# What the web server actually uses
php-fpm -v # or php-fpm8.3 -v
apachectl -M 2>/dev/null | grep -i php # mod_php loaded?
# Inside a running container
docker exec <container> php -v
# Debian/Ubuntu: is the fix backported into this package?
apt changelog php8.3-fpm | grep -i "CVE-2026-1096"
# RHEL/Fedora family
rpm -q --changelog php | grep -i "CVE-2026-1096"
Step 2: Patch (the only complete fix)
# Debian/Ubuntu
sudo apt update && sudo apt install --only-upgrade 'php*'
# Docker: pull the new base image and rebuild without cache
docker build --pull --no-cache -t myapp:php-patched .
In your Dockerfile, track the patch line of your branch and rebuild on a schedule, so you are not relying on someone remembering:
FROM php:8.4-fpm # follow the branch; rebuild weekly in CI
# Or pin an exact fixed release, then bump it deliberately:
# FROM php:8.4.27-fpm
Step 3: Restart every worker
Patching the package does not touch processes that are already running.
sudo systemctl restart php8.3-fpm
sudo systemctl restart apache2 # if you use mod_php
# Containers / Kubernetes: redeploy so the pods are replaced
kubectl rollout restart deployment/my-app
Step 4: Verify the running version
A quick guard you can run from the web tier (or add to a health check) so a stale worker is obvious:
<?php
// check-php-version.php: fail CI or a health check if PHP is below the fixed release
$fixed = ['8.5' => '8.5.12', '8.4' => '8.4.27', '8.3' => '8.3.36', '8.2' => '8.2.35'];
$branch = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
if (!isset($fixed[$branch])) {
fwrite(STDERR, "PHP $branch has no official fix. Use a vendor build or upgrade.\n");
exit(1);
}
if (version_compare(PHP_VERSION, $fixed[$branch], '<')) {
fwrite(STDERR, "PHP " . PHP_VERSION . " is vulnerable. Need >= {$fixed[$branch]}.\n");
exit(1);
}
echo "OK: PHP " . PHP_VERSION . "\n";
A distro build with a backported fix reports an older number, so this script can false-alarm there. For those machines, trust the vendor advisory and changelog instead.
Step 5: Hunt for signs of compromise
Patching does not remove an attacker who is already in. Look at your logs from 17 October onward for:
- unusually large or deeply nested multipart requests,
- PHP workers that crashed or hit their memory limit,
- new or modified files in web roots (new
.phpfiles in upload directories are a classic web shell sign), - outbound connections from PHP processes that you cannot explain,
- unexpected cron jobs or new accounts.
If you find anything, preserve logs first, then rotate secrets (database passwords, API keys, .env values) on that host.
If you cannot patch right now: stopgaps
None of these make an unpatched server safe. They only reduce exposure while you schedule the real fix.
; php.ini / FPM pool config. Must be set where the app CANNOT override it.
; CVE-2026-109619: disable session upload progress
session.upload_progress.enabled = 0
; PHP 8.5 only: remove a confirmed producer of stale state
fatal_error_backtraces = 0
; Keep request bodies bounded
post_max_size = 8M
upload_max_filesize = 2M
max_file_uploads = 5
max_input_nesting_level = 8
; PHP-FPM pool: admin values cannot be changed by the application
php_admin_value[session.upload_progress.enabled] = 0
# Nginx: enforce limits in front of PHP
client_max_body_size 8m;
# If this endpoint never takes uploads, reject multipart entirely
location /api/ {
if ($content_type ~* "multipart/form-data") { return 415; }
...
}
Then restart all workers. Other practical notes from the advisories:
- A per-worker container or cgroup memory limit helps contain denial of service, but it is not a fix.
- Do not use
RLIMIT_ASorRLIMIT_DATAto cap memory; they make allocation fail in exactly the way that triggers the vulnerable path. - Consider
pm.max_requests = 1on PHP-FPM if you can afford the performance cost, since it stops stale state from reaching a second request. - A WAF (Cloudflare shipped temporary rules) can block known attack patterns, but only for traffic that passes through it.
- If something truly cannot be patched, take it off the public internet.
Defense in depth: reduce the blast radius for next time
PHP2Shell will not be the last runtime bug. Make the next one less painful:
- Run the web worker as a low-privilege user. The attacker gets only what that user can do.
- Keep secrets out of the web root and out of readable files. Use a secret manager where you can.
- Make the filesystem read-only for everything except the directories PHP must write to.
- Isolate: one app per container or pool, so one compromise does not spread.
- Egress filtering: a web server rarely needs to call arbitrary internet hosts.
- Patch SLAs: critical runtime CVEs within 24 to 48 hours, tracked and owned.
- Automate rebuilds: weekly image rebuilds mean you pick up fixes without a fire drill.
A ten-point checklist
- Listed every place PHP runs (VMs, containers, hosting panels, appliances).
- Identified each PHP branch and whether it is 8.2 to 8.5 (fixed), 7.4 to 8.1 (backport only) or older (no fix).
- Upgraded to 8.5.12 / 8.4.27 / 8.3.36 / 8.2.35 or newer, or confirmed the vendor backport.
- Restarted or redeployed every worker.
- Verified the running version, not just the installed package.
- Disabled
session.upload_progressif you do not use it. - Capped request sizes at the web server or proxy.
- Searched logs from 17 October for large multipart requests, crashes and new files.
- Rotated secrets on any host that looks suspicious.
- Added automated rebuilds and a version check to CI.
Key takeaways
- PHP2Shell is two critical flaws in the PHP engine (CVE-2026-109618 and CVE-2026-109619), exploitable without authentication.
- The causes are classic: invalid memory after an out-of-memory abort and a use-after-free caused by state left behind between requests.
- Safe versions: PHP 8.5.12, 8.4.27, 8.3.36, 8.2.35 or newer. PHP 8.1 and older need a vendor-patched build or an upgrade.
- Patching is not finished until workers are restarted and the running version is verified.
- Config changes are stopgaps, not fixes. Updating is the only complete answer.
- Treat any server that was exposed before patching as possibly compromised until you have checked.
If you only do one thing today, run php -v on the thing that actually serves your site, and compare it with the table above.
Sources and further reading
- PHP security advisories: GHSA-w8hw-w9fx-j79w (CVE-2026-109618) and GHSA-6wmf-4rv5-p3rp (CVE-2026-109619)
- Tenable: PHP2Shell FAQ
- Qualys: how to find, mitigate and patch
- watchTowr: PHP2Shell
- Wikipedia: PHP2Shell
Details such as affected-version ranges, exploitation status and mitigations were still being updated when this was written. Treat the PHP advisories and your distribution’s security notices as the source of truth, and re-check them before acting.