Balis 情報マガジン

infophp

📅 October 29, 2026📖 Verified Publication

InfoPHP: A Practical Playbook for Understanding and Mitigating PHP Information Disclosure

  • InfoPHP refers to the unintended exposure of server software versions, operating system details, and application stack components during HTTP requests or error handling.
  • Exposing version numbers via headers or error pages significantly increases the attack surface by allowing attackers to target known vulnerabilities specific to those versions.
  • Hardening requires a multi-layered approach: configuring php.ini settings, customizing web server headers, and implementing centralized error handling to suppress debug output in production environments.
  • Regular auditing of response headers and error pages is essential to ensure that configuration changes are effective and that no new information leaks have been introduced by third-party modules or updates.

What Is InfoPHP and Why It Matters

InfoPHP is not a single exploit but rather a class of security misconfigurations where a PHP application reveals excessive details about its underlying infrastructure. This typically occurs when verbose error reporting is enabled in a live environment or when default HTTP headers are not sanitized. Attackers use this information to map out the specific technology stack, identify outdated software, and select specific exploits that are known to affect those versions. For instance, knowing a site runs PHP 7.4.3 on Apache 2.4.41 allows an attacker to bypass generic fuzzing and focus on CVEs specific to those versions. Therefore, mitigating InfoPHP is a foundational step in application security.

Common Vectors for Information Leakage

  • HTTP Server Header: The Server header often includes the web server name and version (e.g., Apache/2.4.41 (Ubuntu)).
  • X-Powered-By Header: PHP automatically adds this header, revealing the exact PHP version (e.g., PHP/7.4.3).
  • Uncaught Exceptions: If display_errors is set to On in production, uncaught errors may display stack traces containing file paths, variable names, and internal class structures.
  • Default Framework Pages: Many PHP frameworks (like Laravel or Symfony) serve detailed error pages in development mode that list system environment variables if not properly switched to production mode.

Actionable Configuration Checklist

Implement the following steps to harden your PHP environment against information disclosure. Verify each item in your production configuration files.

  • Disable Error Display: Set display_errors = Off in php.ini. Ensure errors are logged to a secure file (log_errors = On) instead of the browser.
  • Remove X-Powered-By Header: In Apache, use Header unset X-Powered-By in the httpd.conf or virtual host block. In Nginx, add fastcgi_hide_header X-Powered-By; in the fastcgi block.
  • Hide Server Version: In Apache, set ServerTokens Prod and ServerSignature Off. In Nginx, set server_tokens off;.
  • Customize Error Pages: Point ErrorDocument directives to generic, static HTML pages that do not reveal internal system details.
  • Set PHP version to "Off": While you cannot easily hide the PHP version from the phpinfo() function if it is exposed, ensure that phpinfo() endpoints are restricted to internal networks or disabled in production via a global config flag.

Comparing Web Server Configurations

The following table illustrates how to suppress version information in the two most common web servers used with PHP.

Setting Apache Configuration Nginx Configuration Result
Server Header ServerTokens Prod server_tokens off; Shows "Apache" or "nginx" only, no version.
X-Powered-By Header unset X-Powered-By fastcgi_hide_header X-Powered-By; Removes PHP version disclosure.
Error Reporting Handled in php.ini Handled in php.ini Must set display_errors = Off globally.
Stack Traces Custom ErrorDocument Custom error_page Replaces detailed PHP errors with generic pages.

Testing Your Mitigations

After applying the configurations above, you must verify that the changes are effective. Do not rely solely on visual inspection.

  • Use cURL: Run curl -I http://yourdomain.com to inspect response headers. Confirm that Server and X-Powered-By are either absent or sanitized.
  • Induce Errors: Create a temporary test file that triggers a fatal error (e.g., calling an undefined function). Access this file via a browser. The response should be a generic 500 error page, not a stack trace.
  • Check phpinfo: Ensure that the phpinfo() URL is inaccessible from the public internet. This can be done via IP whitelisting or by disabling the phpinfo function in the disable_functions directive of php.ini.
  • Scan with Tools: Use online scanners or local tools like Nmap to check open ports and banner grabbing to ensure no other services are leaking version info.

Frequently Asked Questions

Does hiding the PHP version completely prevent attacks?

No. Hiding version information reduces the attack surface by preventing attackers from easily identifying specific vulnerabilities (CVEs) associated with that version. However, determined attackers can still probe for vulnerabilities using generic fuzzing techniques or time-based attacks. Hiding information adds friction and is a defense-in-depth measure, not a bulletproof shield.

Can I hide the server version without affecting performance?

Yes. Modifying headers and error handling has negligible performance impact. These are configuration changes that occur at the response phase. The slight overhead of writing error logs to disk (when display_errors is off) is often faster than rendering complex error pages for the user, and the security benefit far outweighs any minimal resource usage.

What if I need to debug in a shared hosting environment?

Shared hosting providers often restrict access to php.ini and .htaccess files for security reasons. In such cases, use a .user.ini file for PHP settings if allowed by the provider. For web server headers, you may not be able to modify the global server config, but you can often use .htaccess (for Apache) to strip specific headers like X-Powered-By using mod_headers. Always ensure you revert all debug settings immediately after troubleshooting.