-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
caddyhttp: Test cases for %2F
and %252F
#6084
Conversation
%2F
and %252F
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love tests 💯
We still have more to discuss about this topic. I think we need to do something like this: diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go
index 1f0b6a5e..adc09d21 100644
--- a/modules/caddyhttp/fileserver/staticfiles.go
+++ b/modules/caddyhttp/fileserver/staticfiles.go
@@ -258,13 +258,20 @@ func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
return caddyhttp.Error(http.StatusNotFound, fmt.Errorf("filesystem not found"))
}
+ // we want the raw path without URL decoding, because
+ // target filenames may contain %2F and such
+ rawPath := r.URL.Path
+ if r.URL.RawPath != "" {
+ rawPath = r.URL.RawPath
+ }
+
// remove any trailing `/` as it breaks fs.ValidPath() in the stdlib
- filename := strings.TrimSuffix(caddyhttp.SanitizedPathJoin(root, r.URL.Path), "/")
+ filename := strings.TrimSuffix(caddyhttp.SanitizedPathJoin(root, rawPath), "/")
fsrv.logger.Debug("sanitized path join",
zap.String("site_root", root),
zap.String("fs", fsName),
- zap.String("request_path", r.URL.Path),
+ zap.String("request_path", rawPath),
zap.String("result", filename))
// get information about the file But if we do this, we also kinda need to take it a step further to adjust how the The thought would be to make a new I don't see a clean way to deal with it. Some prior art #5278 and #5504, we merged in a hack in |
We just need to be very careful when dealing with encoding-related patches...
|
Yeah, I'm always 11/10 nervous about making changes to that stuff. The trouble IMO is |
True, that directive is overloaded. So we'll need to use discretion when replacing |
As per the discussion in https://caddy.community/t/serving-static-files-with-encoding/22382, I just wanted to add a test case as a sanity check that
%252F
behaves correctly, i.e. it would result in%2F
after being joined.