Remediation
Temporary mitigations and hardening
Contents
The PHP project is clear: only upgrading is a complete fix. The measures on this page reduce exposure to specific attack paths, have side effects on operation and do not make an installation safe.
Source: PHP projectFour different categories#
| Category | What it does | Is it enough? |
|---|---|---|
| Definitive fix | Upgrade to a fixed version or a fixed vendor package, with a restart of all processes. | Yes (together with a check for compromise) |
| Temporary path reduction | Settings that block known, confirmed paths. | No: other variants remain |
| General hardening | Limits the damage if exploitation occurs. | No |
| Post-upgrade checks | Adjusting limits to PHP’s new behaviour. | Complementary |
Definitive fix#
Upgrade to PHP 8.5.13, 8.4.28, 8.3.37, 8.2.36 (19 Nov 2026, which also fix CVE-2026-115560) or to a fixed package from your vendor, and restart all PHP processes. See the remediation steps and the guides per environment.
Temporary reduction of specific attack paths#
Only if you cannot upgrade immediately. Test each change first, and record what you changed so you can revert it after the upgrade.
For CVE-2026-109618 (out-of-memory)#
memory_limit = -1: only with a resource limit at operating-system level
The PHP project recommends memory_limit=-1 set where the application cannot change it (e.g. php_admin_value in the FPM pool or in Apache), checking that no pool, directory or application restores a finite limit. At the same time it notes that an underlying memory allocation failure can still reach the vulnerable path.
Changes packages or configuration: back up and test first
; PHP-FPM pool (e.g. /etc/php/8.3/fpm/pool.d/www.conf). The application cannot change it.
php_admin_value[memory_limit] = -1
# Apache with mod_php (vhost or server config)
php_admin_value memory_limit -1
# systemd drop-in for a memory limit on the FPM service (cgroup v2), e.g.:
# systemctl edit php8.3-fpm
[Service]
MemoryMax=2G
The exact service name and the appropriate value depend on your server. MemoryMax at service level applies to the whole of FPM, not a single worker; if it is exceeded, the entire service may be terminated.
Low post_max_size
From the PHP project’s advisory:
; No need for file uploads
post_max_size = 8M
; With file uploads
; post_max_size = 32M
upload_max_filesize = 2M ; always smaller than post_max_size
Side effect: uploads or forms larger than the limit will fail. Calif notes that chunked HTTP/1.1 requests, HTTP/2 requests without a length, or input decompression filters can bypass the post_max_size check. That is why limits are also needed on the web server.
Limits on the web server or proxy
The PHP project recommends limits on: request size after decoding, number of fields, number of multipart parts, number of headers and nesting depth. The limits must also cover requests without a usable Content-Length.
Changes packages or configuration: back up and test first
# Nginx: body limit (also applies to chunked bodies) and headers
client_max_body_size 8m;
large_client_header_buffers 4 8k;
# Apache: limits on body, number of headers and header size
LimitRequestBody 8388608
LimitRequestFields 50
LimitRequestFieldSize 8190
In addition, at PHP level there are max_input_vars, max_input_nesting_level, max_file_uploads and max_multipart_body_parts. Set them to the application’s real needs and test complex forms: values that are too low silently “truncate” data.
Blocking multipart where it is not needed
The advisory and AWS recommend blocking multipart requests at the frontend if the application does not use uploads. Side effect: it breaks every upload (e.g. media in WordPress) and forms with files. Apply it only to sites or paths where you are certain.
# Nginx: inside the location that passes requests to PHP
if ($http_content_type ~* "multipart/form-data") { return 403; }
# Apache 2.4
<If "%{CONTENT_TYPE} =~ /multipart\/form-data/i">
Require all denied
</If>
Sources: PHP project · php-src (GitHub) · Amazon Web Services · Calif
For CVE-2026-109619 (stale global state)#
session.upload_progress.enabled = 0
Blocks the confirmed paths via sessions, not other variants. Since 23 October 2026 the PHP project also recommends it for the separate CVE-2026-115560, which was fixed on 19 November 2026; those releases disable it by default. If you have not upgraded yet, keep it in place. It must be set in php.ini, in the FPM pool or in a server setting that takes effect before the request is parsed, followed by a restart of every worker. According to the PHP project, you must not rely on ini_set() or on FPM’s .user.ini.
session.upload_progress.enabled = 0
Side effect: upload progress bars that rely on this PHP feature stop working. Few applications use it.
PHP 8.5 only: fatal_error_backtraces = 0
fatal_error_backtraces = 0
Blocks only the confirmed path via backtraces. Side effect: less information in fatal error logs.
Cleaning up per-request settings and fatal errors
- Remove invalid or deprecated per-request settings (e.g. old
php_valueentries in.htaccess) that produce diagnostic messages before initialisation. - Fix fatal errors and timeouts that a visitor can trigger: callbacks, upload and import processing, cleanup.
General hardening#
Not specific to PHP2Shell, but it limits the damage if exploitation occurs:
- Each site with its own user and its own FPM pool (or CageFS/LVE on CloudLinux), so that a compromise does not spread to other sites.
- The PHP user should not have write access to code files, except for the necessary folders (e.g. uploads).
- Block PHP execution in upload folders.
- Restrict outbound connections from the web server, where practical.
- Secrets outside the document root and with minimal permissions. Separate database users per application.
- Centralise logs on a system outside the server, so they cannot be deleted by an attacker.
- Find and disable forgotten installations (old subdomains, test sites, admin tools).
Post-upgrade checks#
According to the researchers, the fix introduces a hard memory limit: when it is exceeded, the process is terminated without shutdown handlers running. After the upgrade:
- Review
memory_limitin relation to request size limits and expected consumption. If you temporarily setmemory_limit=-1, restore a finite limit. - Keep
post_max_sizewell below the memory budget, while allowing legitimate uploads. - Set
max_input_nesting_levelto what the application needs and test complex forms. - Applications that rely on shutdown functions for cleanup (e.g. releasing locks) may behave differently if a request drastically exceeds memory. Monitor the logs.
- Optionally
expose_php = Off, for less version disclosure. It does not fix PHP2Shell.