CVE-2012-1823: PHP-CGI Query String Parameter Vulnerability
sapi/cgi/cgi_main.c in PHP before 5.3.12 and 5.4.x before 5.4.2, when configured as a CGI script (aka php-cgi), does not properly handle query strings that lack an = (equals sign) character, which allows remote attackers to execute arbitrary code by placing command-line options in the query string, related to lack of skipping a certain php_getopt for the 'd' case.
CVE-2012-1823 is a vulnerability in PHP when it is run in CGI mode. Improper handling of query strings in the CGI front end can let a remote attacker reach code-execution paths that should not be exposed. For IT and security teams, this matters because PHP-CGI is still found on legacy web stacks, shared hosting, and appliances; successful abuse can lead to full compromise of the web tier and anything it can reach.
Public detail is limited to the CISA description and the CWE classification. Confirm exact affected builds, fixed releases, and configuration prerequisites against the vendor advisory before you act.
How it works
The weakness is CWE-20 (Improper Input Validation). In the PHP CGI SAPI (sapi/cgi/cgi_main.c), query-string data is not validated tightly enough when PHP is configured as a CGI script. An attacker who can send crafted HTTP requests can influence how the CGI process interprets those parameters, ultimately causing the interpreter to execute attacker-controlled code or options.
At a high level, the abuse path is: remote HTTP request containing a specially formed query string → CGI layer mishandles the input → PHP process runs with unintended arguments or code. No further exploit mechanics are provided in the given facts; treat any public proof-of-concept material as untrusted until you have validated it in a lab and cross-checked the vendor write-up.
Am I affected? How to find it in your systems
PHP configured as CGI (as opposed to mod_php, php-fpm, or other SAPIs) is the configuration class in scope. Typical locations include older Apache/nginx setups that invoke php-cgi or php.cgi via ScriptAlias, Action/AddHandler, or wrapper scripts; some appliance and shared-hosting images still ship this layout.
- Inventory: search package managers, container images, and host filesystems for php-cgi or php.cgi binaries; review web-server configs for CGI handlers that point at PHP.
- Version and mode check: on each host run the PHP binary with -v and confirm the SAPI in use (php -i or a phpinfo page). Only CGI-mode deployments are described as affected; still confirm the precise version range in the vendor advisory.
- Configuration review: look for query-string rewriting, exposed cgi-bin directories, and any front-end that forwards raw query strings to the PHP CGI process.
- Telemetry: watch web-access logs for unusual query strings aimed at PHP CGI endpoints, spikes in 500s from the CGI wrapper, or unexpected child processes spawned by the web server user. IDS/WAF rules that flag CGI parameter smuggling or unexpected PHP command-line switches can surface scanning or exploitation attempts.
If you cannot determine the SAPI or version with certainty, assume the service needs review until the advisory clears it.
How to remediate
Patch first. Apply the updates specified by the PHP vendor (or your OS/distribution packager) exactly as directed in the advisory. CISA’s required action is to apply updates per vendor instructions; do not rely on partial back-ports unless your vendor explicitly supports them.
- After patching, restart the web server and any PHP CGI processes, then re-verify the running binary version and SAPI.
- Prefer migrating off CGI mode entirely where possible—php-fpm or a supported module SAPI removes the vulnerable code path class.
- Harden remaining CGI usage: restrict which URLs can invoke the CGI binary, run it under a dedicated low-privilege account, and ensure the document root and cgi-bin directories are not world-writable.
- Re-scan with your vulnerability management tool and confirm the finding is closed against the vendor’s fixed versions.
If you can't patch immediately
Reduce exposure until the vendor update can be installed:
- Network segmentation: limit inbound access to the web tier to trusted reverse proxies or internal networks only.
- Virtual patching: deploy WAF or reverse-proxy rules that block or normalize suspicious query-string patterns aimed at PHP CGI endpoints; tune to avoid breaking legitimate traffic.
- Disable or isolate the affected feature: if CGI mode is not required, disable the PHP CGI handler and switch to a different SAPI; if it must stay, move it behind authentication and strict path allow-lists.
- Monitoring: increase logging verbosity on the web server and PHP CGI wrapper, alert on anomalous query strings, unexpected process arguments, or new outbound connections from the web user. Retain logs for later forensic use.
- Least privilege: ensure the CGI process cannot write to web content directories or read sensitive configuration beyond what it needs.
These steps only buy time; they are not a substitute for the vendor patch.
If your data may have been exposed
Actively exploited remote-code-execution flaws on web tiers frequently precede broader intrusion and data theft. If you have evidence of exploitation—or simply cannot rule it out—treat the host as potentially compromised: isolate it, preserve volatile evidence, rotate credentials that the web application could access, and begin incident-response triage. Known ransomware use is not documented for this CVE in the supplied facts, but that does not mean post-exploitation activity is impossible. As a quick additional check, you can run a free exposure scan of your email addresses against known breach data sets to see whether related accounts have already appeared in public dumps.
AICompiled with AI assistance from public sources and published under our editorial standards.
Details
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:HReferences
- eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/
- h20000.www2.hp.com/bizsupport/TechSupport/Document.jsp?objectID=c03360041
- lists.apple.com/archives/security-announce/2012/Sep/msg00004.html
- lists.opensuse.org/opensuse-security-announce/2012-05/msg00002.html
- lists.opensuse.org/opensuse-security-announce/2012-05/msg00007.html
- lists.opensuse.org/opensuse-security-announce/2012-05/msg00011.html
- marc.info/?l=bugtraq&m=134012830914727&w=2
- rhn.redhat.com/errata/RHSA-2012-0546.html