Skip to content

fileserver: only match a dir when the pattern ends by / - #8352

Merged
francislavoie merged 1 commit into
caddyserver:masterfrom
dunglas:fileserver-dir-index-fallback
Nov 4, 2026
Merged

francislavoie merged 1 commit into
caddyserver:masterfrom
dunglas:fileserver-dir-index-fallback

Conversation

@dunglas

@dunglas dunglas commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes caddyserver/caddy#8353.
This is because of #8326 (released in v2.11.8). Sorry, this endless.

Details

The file matcher keeps the trailing slash of the expanded request path, so a pattern without a trailing slash like {path} now matches directories. With php_fastcgi's default try_files {path} {path}/index.php index.php, a request for /dir/ matches the directory /dir/ instead of /dir/index.php. The request is no longer sent to PHP, and file_server answers it, usually with a 404. This breaks every PHP app that serves a directory index through a trailing-slash URL, such as WordPress's /wp-admin/. FrankenPHP's php_server is affected the same way.

Before that change, {path} never matched a directory: the slash was restored only when the pattern itself ended in /, and strictFileExists requires a path without a trailing slash not to be a directory.

Fix

A candidate whose path ends in / now matches nothing unless the pattern ends in / too. So /dir/ falls through to {path}/index.php again, as in v2.11.7, and /file.txt/ still can't match the regular file, which keeps the protection that change added. The root path / and split paths like /index.php/ are unchanged.

TestPHPFileMatcher gets two cases (/foo.php.php/ and /foo.php.php/./) that fail without the fix.

This probably deserves a v2.11.9.

Assistance Disclosure

Generated by Claude Code (Opus 5.5), reviewed by me.

Since caddyserver#8326, the trailing slash
of the expanded request path was kept, so `{path}` started to match
directories: with php_fastcgi's `try_files {path} {path}/index.php
index.php`, a request for `/dir/` matched the directory instead of
`/dir/index.php`, and was no longer sent to PHP.

A candidate ending in a slash now matches nothing unless the pattern
itself ends in one, as before, while still never matching a regular
file.
@francislavoie
francislavoie merged commit b5d67d6 into caddyserver:master Nov 4, 2026
27 checks passed
@francislavoie francislavoie modified the milestones: v2.12.0, v2.11.9 Nov 4, 2026
francislavoie pushed a commit that referenced this pull request Nov 5, 2026
@github-actions github-actions Bot mentioned this pull request Nov 5, 2026
5 tasks
dunglas added a commit to dunglas/caddy that referenced this pull request Nov 7, 2026
The literal candidate built for the final entry of first_exist_fallback cleaned the path without the rules of caddyserver#8326 and caddyserver#8352. With "{path}" as that entry, "/.env/" and "/.env/./" matched the regular file "/.env", bypassing path matchers that see the trailing slash.

Both candidate builders now share the same cleaning and splitting.
steadytao pushed a commit to dunglas/caddy that referenced this pull request Nov 8, 2026
The literal candidate built for the final entry of first_exist_fallback cleaned the path without the rules of caddyserver#8326 and caddyserver#8352. With "{path}" as that entry, "/.env/" and "/.env/./" matched the regular file "/.env", bypassing path matchers that see the trailing slash.

Both candidate builders now share the same cleaning and splitting.
steadytao pushed a commit that referenced this pull request Nov 8, 2026
* fileserver: apply slash rules to fallback entry

The literal candidate built for the final entry of first_exist_fallback cleaned the path without the rules of #8326 and #8352. With "{path}" as that entry, "/.env/" and "/.env/./" matched the regular file "/.env", bypassing path matchers that see the trailing slash.

Both candidate builders now share the same cleaning and splitting.

* fileserver: handle Windows separators in file matcher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2.11.8: php_fastcgi returns 404 for directory URLs ending in / (index.php not served)

2 participants