On this page
I read about a serious bug in PHP. One web request is enough to run commands on a server. The commands run with the rights of the account that runs PHP. That is only the first step, and attackers often go further.
Some of my own systems use PHP, so I did not want to read the news and move on. I read the reports and looked at how the bug works. Then I checked my own servers. Here is what I found.
Update, October 23, 2026. This post covers CVE-2024-4577 only. On October 21, 2026, the PHP project fixed two other critical bugs: CVE-2026-109618 and CVE-2026-109619 (opens in a new tab). They can allow remote code execution without a login. They affect every PHP setup that serves web requests, including PHP-FPM, Apache with mod_php and php-cgi. The fixes are in PHP 8.2.35, 8.3.36, 8.4.27 and 8.5.12. Please update to one of these or a newer release.
The facts in short
| CVE | CVE-2024-4577 |
| Type | Argument injection that leads to remote code execution |
| Affected | PHP-CGI on Windows |
| Reported to PHP | May 7, 2024, by DEVCORE |
| First fixed | June 6, 2024, in PHP 8.1.29, 8.2.20 and 8.3.8. A later bypass, CVE-2024-8926, was fixed in 8.1.30, 8.2.24 and 8.3.12 |
| Unsupported branches | PHP 8.0 and older never had a fix. PHP 8.1 got the 2024 fix, but it is out of support now and gets no newer fixes |
| Not affected | Linux and macOS |
Where the problem comes from
The bug comes from the way Windows handles text. Windows has a feature called Best-Fit mapping. Say a character does not exist in the current code page. Windows does not return an error. It swaps in the closest match it can find. Microsoft warns about this in the documentation of WideCharToMultiByte (opens in a new tab). A flag called WC_NO_BEST_FIT_CHARS turns it off, and the page says to use it for strings that need validation. In the code pages that matter here, the soft hyphen (byte 0xAD) turns into a normal dash (0x2D). You cannot see a soft hyphen on screen.
Now look at PHP. In CGI mode, a query string with no = sign can turn into command-line arguments. RFC 3875, section 4.4 (opens in a new tab) describes this. The server splits the query string at each plus sign and passes the words to the script. So for php-cgi.exe, an attacker can put options like -d in the URL. This was already a problem in 2012 (CVE-2012-1823), and PHP added a protection.
The new bug gets past that protection because the same byte is read as two different values. PHP's own check looks at the decoded argument. It sees a soft hyphen, not a dash, so it lets the argument through. But the options are read from a second copy of the text, converted separately. There, Windows has already changed the soft hyphen into a normal dash with Best-Fit. So the check and the option processing look at two different strings for the same byte:
Query string: ?%ADd+allow_url_include%3D1+%ADd+auto_prepend_file%3Dphp://input
Checked by PHP: %AD (soft hyphen) -> not "-", the argument is let through
Used to set options: %AD, after Best-Fit -> "-d allow_url_include=1 -d auto_prepend_file=php://input"The two options do the work:
allow_url_include=1lets PHP include code from a URL or a stream.auto_prepend_file=php://inputruns the request body before the real script.
So the code in the POST body runs on the server, with the rights of the web server process. One request is enough. The attacker needs no login and no file upload.
Who is affected
- PHP on Windows in CGI mode, for example Apache with an
Actiondirective that points tophp-cgi.exe. DEVCORE confirmed the attack on three code pages: 950 (Traditional Chinese), 936 (Simplified Chinese) and 932 (Japanese). For other locales, such as English, Korean and Western European, DEVCORE says the full list cannot be known. Do not assume you are safe. - Servers where
php.exeorphp-cgi.exesits in a folder that the web server can run as a CGI program. This can be true even when CGI mode is off. The default XAMPP setup does this with aScriptAlias. - PHP 8.0 and older, which never got a fix. PHP 8.1 had one, but it is out of support now and gets no newer fixes.
Linux and macOS
They are not affected. The bug needs the Best-Fit conversion of Windows. If your server runs Linux with PHP-FPM or mod_php, this CVE does not apply to you. If you run a mix of servers, look at the Windows ones first. This is true for this CVE only. The October 2026 bugs from the update note reach PHP-FPM and mod_php, so a Linux server still needs the update.
How to check your server
Run these three checks. If all three match, treat the server as vulnerable.
1) The PHP version. Check both the CLI and the CGI program. They can come from different folders.
php -v
php-cgi.exe -vA version below 8.1.29, 8.2.20 or 8.3.8 is vulnerable to CVE-2024-4577. So is every version before 8.1. These numbers are only the first fixes. Compare your version with the current security releases in the fix section.
2) How PHP runs. Put this file in the web folder, open it in a browser, and delete it when you are done.
<?php phpinfo();Find the line "Server API". The value CGI, or FastCGI shown as cgi-fcgi, does not tell you whether this request used the classic CGI path that the bug needs. php-cgi.exe shows the same kind of value whether the web server runs it as a plain CGI program or through FastCGI. So check the web server's own configuration. For example, look for an Apache Action or ScriptAlias line that points to php-cgi.exe. "Apache 2.0 Handler" means the page you opened runs through mod_php, and this bug does not reach that page. But a separate php-cgi.exe can still be reachable on the same server through its own configuration entry. The test below covers that case. Update anyway.
3) The system ANSI code page. This is the one that matters for the conversion. The command chcp shows the console code page, which can be different.
# Prints the system ANSI code page. Best-Fit conversion uses this one, not the console code page.
(Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage').ACPThe value 932, 936 or 950 puts you in the confirmed danger zone. On my Windows 11 machine it prints 1252, a Western code page, so I am outside that zone. Other values do not prove that you are safe.
Test it on your own machine
Do this only on a local test server that you own. Never run it against someone else's server or a production system.
Create an index.php that prints a short text. Then send this request. Use PowerShell and curl.exe, because curl is an alias for another command in Windows PowerShell.
curl.exe -s -X POST "http://localhost/index.php?%ADd+allow_url_include%3D1+%ADd+auto_prepend_file%3Dphp://input" --data-binary "<?php echo 'vuln-', 6*7;"How to read the result:
- If the output starts with
vuln-42, the server is vulnerable. PHP ran the request body as code. - If you see only the normal page or an error, the injection did not work.
I use a short marker instead of phpinfo(). It is easy to find in the output, and it does nothing else. A real attacker would send a command here.
This request tests one page. A server can run index.php through mod_php and still expose php-cgi.exe in a CGI folder. So also look for php.exe and php-cgi.exe in any folder that Apache maps with ScriptAlias or runs with ExecCGI. On a default XAMPP, send the same request to /php-cgi/php-cgi.exe instead of /index.php. If one URL does not return vuln-42, you have not shown that the whole server is safe.
The fix
Install the newest security release of a PHP branch that still gets support. On October 23, 2026, these are 8.5.12, 8.4.27, 8.3.36 and 8.2.35. PHP 8.2 reaches end of life on December 31, 2026. These releases fix CVE-2024-4577, its later bypass CVE-2024-8926, and the two October 2026 bugs. The first fixes for CVE-2024-4577 (8.1.29, 8.2.20 and 8.3.8) are not enough today. PHP 8.1 and older get no updates, so move to a supported branch.
If you cannot update right away, these steps lower the risk of CVE-2024-4577 only. They do nothing for the two October 2026 bugs from the update note. The PHP project says an update is the only full fix for those.
- Stop using CGI mode. DEVCORE suggests mod_php, FastCGI or PHP-FPM. This is the best long-term step.
- Turn off PHP-CGI in XAMPP if you do not need it. In
C:/xampp/apache/conf/extra/httpd-xampp.conf, comment out theScriptAliasline for/php-cgi/. Restart Apache. - Block the character in front of PHP. Choose this if you must keep CGI for now. The rule needs
mod_rewrite.
# ScriptAlias /php-cgi/ "C:/xampp/php/"
RewriteEngine On
RewriteCond %{QUERY_STRING} ^%ad [NC]
RewriteRule .? - [F,L]The first line is the XAMPP line from the list above, after you comment it out. The three lines below it are the DEVCORE rule. The ^ matters. It limits the rule to query strings that start with %AD. Without it, the rule also blocks normal requests that contain letters like í, because UTF-8 writes this letter as %C3%AD. DEVCORE says the rule is for the three confirmed locales. It is a short-term shield and does not fix the bug.
After every change, run the test request again and confirm that vuln-42 is gone.
After the fix: look in your logs
If the server was online and vulnerable, look for signs of an attack. Search the access log for a request whose query string starts with %AD. The default path below is the XAMPP one.
# Lists the requests whose query string starts with %AD (the soft hyphen).
# Run with: .\find-attempts.ps1 -Log C:\xampp\apache\logs\access.log
param(
[string]$Log = 'C:\xampp\apache\logs\access.log'
)
Select-String -Path $Log -Pattern '\?%AD' | ForEach-Object { "{0}: {1}" -f $_.LineNumber, $_.Line }I ran it on a small sample log with three requests: a normal page, an attack request and a request with the letter í. It found only the attack request.
2: 192.0.2.20 - - [23/Oct/2026:10:00:01 -0400] "POST /index.php?%ADd+allow_url_include%3D1+%ADd+auto_prepend_file%3Dphp://input HTTP/1.1" 200 512A hit with allow_url_include or auto_prepend_file means someone tried the attack. If it happened on a server that was not patched at the time, treat the server as compromised. Look for new files, new users and new scheduled tasks.
What I take from it
A problem can sit far below your own code. Here it was an old Windows habit that nobody had looked at for years. The security check and the system saw two different strings. That gap was enough to give away a whole server.
I updated PHP on every server and turned off CGI mode where I did not need it. Now I check versions on a schedule.
Read more
- DEVCORE, CVE-2024-4577 PHP-CGI argument injection (opens in a new tab), the report with the affected versions, the code pages and the mitigations
- PHP security advisory GHSA-3qgc-jrrr-25jv (opens in a new tab), the bypass of CVE-2012-1823 and the patched versions
- RFC 3875, section 4.4 (opens in a new tab), how a CGI server turns a query string into arguments
- WideCharToMultiByte (opens in a new tab) in the Microsoft documentation, with the note on Best-Fit characters
- PHP security advisory GHSA-p99j-rfp4-xqvq (opens in a new tab), CVE-2024-8926, a later bypass of the fix
- PHP news archive 2026 (opens in a new tab), the October 2026 security releases and the two new critical bugs
Was this post helpful?