Repository navigation
Refuse .php URLs under /storage/ by default in the frankenphp images - #16
Conversation
The Livewire upload RCE (GHSA-29cq-5w36-x7w3) was exploited by dropping a .php file into Laravel's storage and requesting it, and the base image executed it (verified: /storage/x.php, /storage/X.PHP, x.php/foo, //, ./, .. and percent-encoded forms all ran). docker-configure now renders a rule that 404s any /storage/ URL naming a .php file; PHP_DENY_STORAGE_PHP=off disables it. A no-exec handle on /storage/* was not used because it also 404s requests with no file behind them, which breaks Laravel 11+'s local-disk serve route (GET /storage/{path}, answered by PHP). The new rule keys on the .php name only, so that route, uploads and other URLs still work. The smoke test now asserts the rule, so CI keeps proving it. ALI-1116
Review of #16 found a bypass: GET /storage/ or /storage/dir/ never names a .php file, but php_server answers it by running that directory's index.php (verified: both returned 200 and executed it with the first version of the rule; /storage/dir redirects to the slash form). The rule now also matches any URL ending in a slash, plus /storage/ itself. Also make only an explicit off/0/false/no disable the rule, so a value like 'true' or a typo cannot silently turn the protection off, and add the directory case to the smoke test (the first version of the rule fails it).
Review round 1 (fresh-context reviewer)
Confirmed by the reviewer and unchanged: the Cost of the fix: directory-style URLs under Because the fix is for a P2, it gets its own review round before this leaves draft. |
Review of #16: the README said any other value than off/0/false/no leaves the rule on, but the code also accepts OFF, Off, FALSE, False, NO and No. Verified: oFF, 'off ' and ' off' leave it on.
Review round 2 (fresh reviewer, aimed at the round 1 fix)No P1 or P2 findings, no bypass. The reviewer ran about 60 probes against the fixed rule with the real image: odd slashes and case (
Confirmed: the extended smoke test cannot false-pass for the bug fixed in round 1 (the old rule fails it). |
Closes ALI-1116 (https://linear.app/alias-project-inc/issue/ALI-1116), option 3 from the ticket. Follows PR #14, which only documented the opt-in recipe.
Why
Before this, any
.phpfile under/storage/executed. Tested on the base image with today's defaults:/storage/s.php,s.PHP,d/e.php,s.php/foo,s.php/,//s.php,./,../,s%2ephpands.p%68pall ran. That is the Livewire RCE path (GHSA-29cq-5w36-x7w3).What
docker-configure(all four versions, still identical) renders@storage_php path_regexp (?i)^/storage/(.*\.php(/|$)|(.*/)?$)+respond 404into the hardening snippet, on by default. It refuses URLs that name a.phpfile and directory URLs (/storage/,/storage/dir/), becausephp_serveranswers a directory by running itsindex.phpwithout the URL naming any.phpfile (found in review, see the comment below)./storage/dirwithout the slash is redirected to the slash form, so it is covered too. Onlyoff/0/false/nodisable it (PHP_DENY_STORAGE_PHP); any other value, including a typo ortrue, leaves it on. The Dockerfile ENV lists the default, as for the other settings.PHP_NO_EXEC_PATHS=/storage/*: that is a terminalhandlewith onlyfile_server, so it also 404s requests with no file behind them. Tested: a PHP route at/storage/private/report.pdf(Laravel 11+'s local-diskserveroute) returns 200 by default and 404 under that setting. The new rule keys on the.phpname only.serveroute, andPHP_NO_EXEC_PATHSfor other writable directories.smoke-test.shnow asserts:/storage/shell.phpand/storage/shell.php/fooare 404, the directory URLs/storage/and/storage/idx/(which holds anindex.php) are 404, a plain upload there is served, and a non-file/storage/URL reaches the app.Tested locally (real containers)
/storage/ok.txt/storage/s.php,.PHP,d/e.php,s.php/foo,s.php/,//,./,../, encoded/storage/private/report.pdf(PHP route)/storage/missing.png/storage/a.php.jpg/storage/,/storage/idx/(dir withindex.php)PHP_DENY_STORAGE_PHP=off:s.phpexecutes again and the rule is absent from the snippet./storage/shell.phpreturns 200) and passes with the change, for base, dev, wordpress and wordpress-dev.shellcheckclean on the script.Behavior change to know about
A site that really serves PHP from a
/storage/URL will now get 404; setPHP_DENY_STORAGE_PHP=off. Checked alios and aguiarshomecrumb: none do. Customer apps deployed through Alios were not checked.After merging
The change touches the Dockerfiles and
docker-configure, so the push rebuilds every frankenphp image (cli is untouched) through the smoke-tested pipeline. Don't merge while a build-and-push run is in progress (it cancels it).