Skip to content

Commit 3fe2c73

Browse files
caddyhttp: Fix MatchPath sanitizing (caddyserver#4499)
This is a followup to caddyserver#4407, in response to a report on the forums: https://caddy.community/t/php-fastcgi-phishing-redirection/14542 Turns out that doing `TrimRight` to remove trailing dots, _before_ cleaning the path, will cause double-dots at the end of the path to not be cleaned away as they should. We should instead remove the dots _after_ cleaning.
1 parent 5333c35 commit 3fe2c73

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

modules/caddyhttp/matchers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,18 @@ func (m MatchPath) Match(r *http.Request) bool {
325325

326326
lowerPath := strings.ToLower(unescapedPath)
327327

328+
// Clean the path, merges doubled slashes, etc.
329+
// This ensures maliciously crafted requests can't bypass
330+
// the path matcher. See #4407
331+
lowerPath = path.Clean(lowerPath)
332+
328333
// see #2917; Windows ignores trailing dots and spaces
329334
// when accessing files (sigh), potentially causing a
330335
// security risk (cry) if PHP files end up being served
331336
// as static files, exposing the source code, instead of
332337
// being matched by *.php to be treated as PHP scripts
333338
lowerPath = strings.TrimRight(lowerPath, ". ")
334339

335-
// Clean the path, merges doubled slashes, etc.
336-
// This ensures maliciously crafted requests can't bypass
337-
// the path matcher. See #4407
338-
lowerPath = path.Clean(lowerPath)
339-
340340
// Cleaning may remove the trailing slash, but we want to keep it
341341
if lowerPath != "/" && strings.HasSuffix(r.URL.Path, "/") {
342342
lowerPath = lowerPath + "/"

0 commit comments

Comments
 (0)