0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/modules/caddyhttp/fileserver
Francis Lavoie 74f5d66c48
fileserver: Fix file matcher with empty try_files (#4147)
* fileserver: Fix `file` matcher with empty `try_files`

Fixes https://github.com/caddyserver/caddy/issues/4146

If `TryFiles` is empty, we fill it with `r.URL.Path`. In this case, this is `/`. Then later, in `prepareFilePath()`, we run the replacer (which turns `{path}` into `/` at that point) but `file` remains the original value (and the placeholder is still the placeholder there).

So then `strings.HasSuffix(file, "/")` will be `false` for the placeholder, but `true` for the empty `TryFiles` codepath, because `file` was `/` due to being set to the actual request value beforehand.

This means that `suffix` becomes `//` in that case, so after `sanitizedPathJoin`, it becomes `./`, so `strictFileExists`'s `strings.HasSuffix(file, separator)` codepath will return true.

I think we should change the `m.TryFiles == nil` codepath to `m.TryFiles = []string{"{http.request.uri.path}"}` for consistency. (And maybe consider hoisting this to `Provision` cause there's no point doing this on every request). I don't think this "optimization" of directly using `r.URL.Path` is so valuable, cause it causes this edgecase with directories.

* Update modules/caddyhttp/fileserver/matcher.go

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
2021-05-04 09:49:13 -06:00
..
testdata fileserver: Fix try_files for directories; windows fix (#3684) 2020-09-16 18:09:28 -06:00
browse.go fileserver: Share template logic for both templates and file_server browse (#4093) 2021-04-30 22:17:23 -04:00
browse_test.go fileserver: Share template logic for both templates and file_server browse (#4093) 2021-04-30 22:17:23 -04:00
browsetpl.go fileserver: Browse listing supports dark mode (#4066) 2021-03-19 11:41:02 -06:00
browsetplcontext.go fileserver: Share template logic for both templates and file_server browse (#4093) 2021-04-30 22:17:23 -04:00
browsetplcontext_test.go fileserver: Share template logic for both templates and file_server browse (#4093) 2021-04-30 22:17:23 -04:00
caddyfile.go fileserver: Add status code override (#4076) 2021-04-08 11:09:12 -06:00
command.go cmd: file-server: add --access-log flag (#3454) 2020-05-26 15:04:04 -06:00
matcher.go fileserver: Fix file matcher with empty try_files (#4147) 2021-05-04 09:49:13 -06:00
matcher_test.go fastcgi: Set PATH_INFO to file matcher remainder as fallback (#3739) 2020-12-04 17:12:13 -07:00
staticfiles.go fileserver: Share template logic for both templates and file_server browse (#4093) 2021-04-30 22:17:23 -04:00
staticfiles_test.go fileserver: Improve and clarify file hiding logic (#3844) 2020-11-02 14:20:12 -07:00