Nginx PHP code execution via FastCGI

Description
  • A critical security issue was reported on servers that run Nginx and PHP via FastCGI. This issue may allow attackers to execute their own PHP code on the system.The problem is not caused by nginx itself, it's related with the PHP option cgi.fix_pathinfo. When this option is enabled, PHP will rewrite SCRIPT_FILENAME and PATH_INFO parameters. When combined with Nginx, this turns into a security issue.
Remediation
  • set <strong>cgi.fix_pathinfo = 0</strong> in php.ini <br/> <br/> or<br/> <br/> configure nginx using the code below:<br/> <br/> <pre> if ( $fastcgi_script_name ~ \..*\/.*php ) { return 403; } </pre>
References