Skip to main content
CVE Vulnerability Database

CVE-2024-8927: PHP Path Traversal Vulnerability

CVE-2024-8927 is a path traversal vulnerability in PHP that allows attackers to bypass cgi.force_redirect through HTTP header manipulation, enabling arbitrary file inclusion. This article covers technical details, affected versions, impact, and mitigation strategies.

Updated:

CVE-2024-8927 Overview

A critical vulnerability has been identified in PHP's CGI binary implementation where the HTTP_REDIRECT_STATUS variable, used to verify whether the CGI binary is being executed by the HTTP server, can be manipulated by attackers through HTTP headers. This bypass of the cgi.force_redirect security option can lead to arbitrary file inclusion in certain server configurations, potentially allowing attackers to read sensitive files or execute malicious code.

Critical Impact

Attackers can bypass CGI security controls via HTTP header manipulation, potentially leading to arbitrary file inclusion and unauthorized access to sensitive system files in PHP-based web applications.

Affected Products

  • PHP 8.1.* versions before 8.1.30
  • PHP 8.2.* versions before 8.2.24
  • PHP 8.3.* versions before 8.3.12

Discovery Timeline

  • 2024-10-08 - CVE-2024-8927 published to NVD
  • 2025-11-03 - Last updated in NVD database

Technical Details for CVE-2024-8927

Vulnerability Analysis

This vulnerability exists within PHP's CGI security mechanism. The cgi.force_redirect directive is a critical security feature designed to prevent direct execution of the PHP CGI binary by users, ensuring it is only invoked through a properly configured web server. The security check relies on the HTTP_REDIRECT_STATUS environment variable to verify that the request originated from the web server.

However, the vulnerability allows attackers to inject values into the HTTP_REDIRECT_STATUS variable through crafted HTTP headers. When successful, this manipulation tricks PHP into believing it was invoked by a legitimate web server redirect, bypassing the cgi.force_redirect protection entirely.

The impact of this bypass is significant: in certain configurations, an attacker can leverage this flaw to perform arbitrary file inclusion attacks. This could expose sensitive configuration files, application source code, or lead to remote code execution if combined with other attack vectors such as log poisoning or uploaded files.

Root Cause

The root cause stems from insufficient access control verification in PHP's CGI handling (CWE-1220). The HTTP_REDIRECT_STATUS variable was not properly validated to ensure it could only be set by the web server, allowing request submitters to influence its value through HTTP headers. This design flaw violates the principle of least privilege by trusting user-controllable input for security-critical decisions.

Attack Vector

The attack is network-based and requires no authentication or user interaction. An attacker can send specially crafted HTTP requests to a vulnerable PHP CGI endpoint with manipulated headers that set the HTTP_REDIRECT_STATUS value. When the PHP CGI binary processes these requests, it incorrectly determines that the security redirect has occurred, disabling the cgi.force_redirect protection.

The attack flow involves:

  1. Identifying a target running PHP in CGI mode with vulnerable versions
  2. Crafting HTTP requests with headers that manipulate the HTTP_REDIRECT_STATUS variable
  3. Bypassing the cgi.force_redirect security check
  4. Exploiting the bypass to include arbitrary local files via file inclusion vectors

For detailed technical information about this vulnerability, refer to the PHP Security Advisory on GitHub.

Detection Methods for CVE-2024-8927

Indicators of Compromise

  • Unusual HTTP requests targeting PHP CGI endpoints with non-standard headers
  • Web server logs showing attempts to access sensitive files like /etc/passwd, configuration files, or PHP source code
  • Requests containing suspicious HTTP_REDIRECT_STATUS header values or manipulations
  • Error logs indicating file inclusion attempts on unexpected paths

Detection Strategies

  • Monitor web server access logs for requests attempting to directly invoke the PHP CGI binary
  • Implement Web Application Firewall (WAF) rules to detect and block requests with suspicious header manipulation patterns
  • Review PHP error logs for file inclusion warnings or attempts to access files outside the web root
  • Deploy intrusion detection signatures for known file inclusion attack patterns

Monitoring Recommendations

  • Enable detailed logging for PHP CGI execution and monitor for anomalous behavior
  • Configure alerting on failed file access attempts that may indicate exploitation attempts
  • Implement file integrity monitoring on critical system and configuration files
  • Monitor for unusual process execution patterns from the web server

How to Mitigate CVE-2024-8927

Immediate Actions Required

  • Upgrade PHP to the latest patched versions: 8.1.30, 8.2.24, or 8.3.12 or later
  • Review server configurations to ensure cgi.force_redirect is properly enabled
  • Consider migrating from PHP-CGI to PHP-FPM for improved security
  • Audit existing deployments for signs of compromise before patching

Patch Information

PHP has released security patches addressing this vulnerability in versions 8.1.30, 8.2.24, and 8.3.12. Organizations should update to these versions or later immediately. The official security advisory is available at the PHP GitHub Security Advisory.

Additional vendor advisories have been published:

Workarounds

  • If immediate patching is not possible, consider disabling PHP-CGI mode and switching to PHP-FPM
  • Implement strict Web Application Firewall rules to filter suspicious HTTP headers
  • Configure the web server to validate and sanitize the HTTP_REDIRECT_STATUS variable before passing it to PHP
  • Restrict direct access to the PHP CGI binary through server configuration
bash
# Example: Apache configuration to restrict CGI access
# Add to httpd.conf or virtual host configuration
<Directory "/usr/lib/cgi-bin">
    Options -ExecCGI
    AllowOverride None
    Require all denied
</Directory>

# For nginx, ensure PHP-FPM is used instead of CGI
# In nginx.conf or site configuration:
location ~ \.php$ {
    fastcgi_pass unix:/var/run/php/php-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.