caddy/modules/caddyhttp
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
..
caddyauth go.mod: Migrate to golang.org/x/term (#4073) 2021-03-29 12:39:08 -06:00
encode reverseproxy: Add handle_response blocks to reverse_proxy (#3710) (#4021) 2021-05-02 12:39:06 -06:00
fileserver fileserver: Fix file matcher with empty try_files (#4147) 2021-05-04 09:49:13 -06:00
headers headers: Fix Caddyfile parsing for request_header with matchers (#4085) 2021-03-29 10:55:29 -06:00
map map: Accept regex substitution in outputs (#3991) 2021-03-10 14:22:33 -07:00
push headers: Support default header values in Caddyfile with '?' (#3807) 2020-11-20 12:38:16 -07:00
requestbody Revert "requestbody: Allow overwriting remote address" 2021-01-19 18:43:01 -07:00
reverseproxy reverseproxy: Add handle_response blocks to reverse_proxy (#3710) (#4021) 2021-05-02 12:39:06 -06:00
rewrite rewrite: Implement regex path replacements 2021-03-01 18:27:59 -07:00
standard encode,staticfiles: Content negotiation, precompressed files (#4045) 2021-03-29 18:47:19 -06:00
templates fileserver: Share template logic for both templates and file_server browse (#4093) 2021-04-30 22:17:23 -04:00
app.go reverseproxy: Add duration/latency placeholders (close #4012) (#4013) 2021-02-22 11:57:21 -07:00
autohttps.go caddyhttp: Implement better logic for inserting the HTTP->HTTPS redirs (#4033) 2021-04-19 19:54:12 -06:00
caddyhttp.go httpcaddyfile: Configure servers via global options (#3836) 2020-11-23 12:46:50 -07:00
celmatcher.go caddyhttp: Add support to resolve DN in CEL expression (#3608) 2020-07-31 15:06:30 -06:00
celmatcher_test.go caddyhttp: Add support to resolve DN in CEL expression (#3608) 2020-07-31 15:06:30 -06:00
errors.go ci: Use golangci's github action for linting (#3794) 2020-11-22 14:50:29 -07:00
marshalers.go ci: Use golangci's github action for linting (#3794) 2020-11-22 14:50:29 -07:00
matchers.go reverseproxy: Add handle_response blocks to reverse_proxy (#3710) (#4021) 2021-05-02 12:39:06 -06:00
matchers_test.go reverseproxy: Add handle_response blocks to reverse_proxy (#3710) (#4021) 2021-05-02 12:39:06 -06:00
metrics.go metrics: Always track method label in uppercase (#3742) 2020-09-22 20:10:34 -06:00
metrics_test.go metrics: Fix panic when headers aren't written (#3737) 2020-09-21 13:42:47 -06:00
replacer.go reverseproxy: Add duration/latency placeholders (close #4012) (#4013) 2021-02-22 11:57:21 -07:00
replacer_test.go caddyhttp: New placeholder for PEM of client certificate (#3662) 2020-09-16 15:06:51 -06:00
responsematchers.go reverseproxy: Add handle_response blocks to reverse_proxy (#3710) (#4021) 2021-05-02 12:39:06 -06:00
responsematchers_test.go reverseproxy: Add handle_response blocks to reverse_proxy (#3710) (#4021) 2021-05-02 12:39:06 -06:00
responsewriter.go caddyhttp: Fix trailers when recording responses (fixes #3236) 2020-04-22 11:10:13 -06:00
routes.go metrics: Fix hidden panic while observing with bad exemplars (#3733) 2020-09-17 21:46:24 -06:00
server.go caddyhttp: Implement better logic for inserting the HTTP->HTTPS redirs (#4033) 2021-04-19 19:54:12 -06:00
staticerror.go httpcaddyfile: Add error directive for the existing handler (#4034) 2021-03-12 13:25:49 -07:00
staticresp.go caddyhttp: Check for invalid subdirectives of static_response 2021-02-02 16:19:58 -07:00
staticresp_test.go Implement config adapters and beginning of Caddyfile adapter 2019-08-09 12:05:47 -06:00
subroute.go reverseproxy: Enable changing only the status code (close #2920) 2020-06-04 12:06:38 -06:00
vars.go caddyfile: Add support for vars and vars_regexp matchers (#3730) 2020-09-25 17:50:26 -06:00