Skip to content

Refuse .php URLs under /storage/ by default in the frankenphp images - #16

Merged
michaelaguiar merged 3 commits into
mainfrom
aliasbot/ali-1116-storage-php-default
Oct 22, 2026
Merged

michaelaguiar merged 3 commits into
mainfrom
aliasbot/ali-1116-storage-php-default

Conversation

@michaelaguiar

@michaelaguiar michaelaguiar commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

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 .php file 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%2ephp and s.p%68p all 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 404 into the hardening snippet, on by default. It refuses URLs that name a .php file and directory URLs (/storage/, /storage/dir/), because php_server answers a directory by running its index.php without the URL naming any .php file (found in review, see the comment below). /storage/dir without the slash is redirected to the slash form, so it is covered too. Only off/0/false/no disable it (PHP_DENY_STORAGE_PHP); any other value, including a typo or true, leaves it on. The Dockerfile ENV lists the default, as for the other settings.
  • Not PHP_NO_EXEC_PATHS=/storage/*: that is a terminal handle with only file_server, so it also 404s requests with no file behind them. Tested: a PHP route at /storage/private/report.pdf (Laravel 11+'s local-disk serve route) returns 200 by default and 404 under that setting. The new rule keys on the .php name only.
  • README "Laravel hardening" rewritten for the new default, the serve route, and PHP_NO_EXEC_PATHS for other writable directories.
  • smoke-test.sh now asserts: /storage/shell.php and /storage/shell.php/foo are 404, the directory URLs /storage/ and /storage/idx/ (which holds an index.php) are 404, a plain upload there is served, and a non-file /storage/ URL reaches the app.

Tested locally (real containers)

URL Before After
/storage/ok.txt 200 200
/storage/s.php, .PHP, d/e.php, s.php/foo, s.php/, //, ./, ../, encoded executed 404
/storage/private/report.pdf (PHP route) 200 200
/storage/missing.png app app
/storage/a.php.jpg raw bytes, not executed same
/storage/, /storage/idx/ (dir with index.php) executed 404
  • PHP_DENY_STORAGE_PHP=off: s.php executes again and the rule is absent from the snippet.
  • The updated smoke test fails against today's published image (/storage/shell.php returns 200) and passes with the change, for base, dev, wordpress and wordpress-dev.
  • shellcheck clean on the script.

Behavior change to know about

A site that really serves PHP from a /storage/ URL will now get 404; set PHP_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).

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).
@michaelaguiar

Copy link
Copy Markdown
Member Author

Review round 1 (fresh-context reviewer)

Finding Outcome
P2: directory-index bypass. GET /storage/ and GET /storage/idx/ never name a .php file, but php_server answers a directory by running its index.php; /storage/idx redirects (308) to the slash form. Fixed in cdb79f0. I reproduced it first: with the first version of the rule both URLs returned 200 and executed index.php. The rule now also matches any URL ending in a slash, plus /storage/ itself; /storage and /storage/idx redirect into a blocked URL (checked with curl -L: final status 404). This also means my claim in ALI-1116 that "a rule keyed on a .php file is enough" was wrong; the ticket is corrected.
P3: only exactly on enabled the rule, so PHP_DENY_STORAGE_PHP=true, 1, ON or a typo silently disabled the protection. Fixed in cdb79f0. Inverted: only off/0/false/no (common casings) disable it. Verified over 13 values: '', on, ON, true, 1, yes, enabled, typo keep the rule on (404); off, OFF, 0, false, no turn it off (200). README updated to say so.
P3: the smoke test did not cover the bypass. Fixed in cdb79f0. The fixture now has storage/idx/index.php and the script asserts /storage/ and /storage/idx/ are 404. Checked both ways: the first version of the rule fails the new check (GET /storage/ returned '200'), the fixed rule passes for base, dev, wordpress and wordpress-dev.

Confirmed by the reviewer and unchanged: the .php variants (case, //, ./, ../, %2e, %68, %2f, query, ;, trailing dot/space/NUL) all 404 or reach the app without executing; path_regexp sees the decoded, cleaned path; the PHP_NO_EXEC_PATHS combination still works; the four docker-configure copies are identical; the escaping produces the intended regex.

Cost of the fix: directory-style URLs under /storage/ (for example /storage/d/) now 404 even when the directory has no index.php. Nothing in the Laravel serve route or public/storage uploads uses a trailing slash. PR description updated to match.

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.
@michaelaguiar

Copy link
Copy Markdown
Member Author

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 (//storage//, /Storage/idx/), dot and encoded segments, parent segments outside /storage/, symlinks inside storage (/storage/link/ -> 404), HEAD/OPTIONS/POST/PUT, h2c prior knowledge, absolute-form targets, spoofed Host/X-Forwarded-*/X-Original-URL headers, the front-controller fallback (/index.php/storage/idx/ reaches only the app's own index.php), and other index names (default.php is not an index; index.phtml is returned as plain text, not executed). The case statement is valid under busybox ash.

Finding Outcome
P3: README said any value other than off/0/false/no leaves the rule on, but the code also accepts OFF, Off, FALSE, False, NO, No Fixed in the next commit: README lists the exact spellings. Verified oFF, off and off leave the rule on.
P3: (?i) makes /STORAGE/... and /Storage/... URLs ending in a slash, or naming .php, 404 as well Declined. Harmless; no real app route lives at a differently cased /Storage/x/.
P3: a Laravel route /storage/{path} whose path ends in / now 404s Declined. Intended (it is the directory-URL rule), and not a use case: serve paths are files.
Out of scope: another alias or symlink exposing the same directory outside /storage/ (the reviewer's public/stor2 -> storage) still runs index.php there Not a defect of this PR. The rule covers only the literal /storage/ URL prefix, as the README says; PHP_NO_EXEC_PATHS is the tool for other paths.

Confirmed: the extended smoke test cannot false-pass for the bug fixed in round 1 (the old rule fails it).

@michaelaguiar
michaelaguiar marked this pull request as ready for review October 22, 2026 00:18
@michaelaguiar
michaelaguiar merged commit b241d7d into main Oct 22, 2026
2 checks passed
@michaelaguiar
michaelaguiar deleted the aliasbot/ali-1116-storage-php-default branch October 22, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant