PHP Execution in Upload Paths

Medium

Checks whether a file that reached an upload directory would be executed as PHP, without uploading anything.

Estimated fix time: 30 minutes

What this check looks for

StackShield asks your server for PHP files that do not exist, under the paths where uploads usually live: /storage, /uploads, /media and similar. Nothing is uploaded. A server that treats those paths as static files answers with its own 404 page. A server that hands the request to PHP-FPM answers with PHP-FPM's File not found., which shows that a real .php file at that path would be executed.

The check then repeats the request with the other extensions PHP can be mapped to (.phtml, .phar, .php5, .pht), and tests whether appending /x.php to a static file makes the server run that file as PHP.

Why it matters

Upload validation fails in many small ways: a missed extension, a trusted MIME type, a double extension. Whether such a mistake is a nuisance or a full server compromise depends on one thing, which is whether the web server will execute what was uploaded. Many common nginx configurations pass every .php path to PHP rather than only the front controller.

What the findings mean

A high finding means static files can be run as PHP by appending /x.php, so an image with PHP code inside it is enough for remote code execution. A medium finding means extensions other than .php are executed, which name-based upload filters usually miss. A warning means .php files under upload paths would run. That needs an upload flaw to exploit, and removing it costs one line of configuration.

In nginx, pass only the front controller to PHP with location ~ ^/index\.php(/|$). Set security.limit_extensions = .php in the PHP-FPM pool and cgi.fix_pathinfo=0 in php.ini. Servers that run PHP through Apache's mod_php cannot be assessed this way and are reported as passing.

Automatically detect this issue

StackShield can automatically scan your Laravel application for this security issue and alert you when it's detected.

Start Free Trial
Was this guide helpful?