-
-
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
the change to SanitizedPathJoin in v2.8.x can cause routing to break in certain configurations #6352
Comments
my guess is it has something to do with the changes to SanitizedPathJoin
after adding some debug logging, it seems that a different 'r.URL.Path' is being used in staticfiles.go:270 |
it seems the origin of the different r.URL.Path is in fileserver/matcher.go:365. pre this commit, if i query for after this change, i get this causes the different r.URL.Path down the line, as the fullpath in the matchcandidate is now different. |
@mholt we ran into this during smoke tests before production. is this change intended? we are changing all our configs to be explicitly |
I think @elee1766 is definitely on the right track here. The lack of trailing slash causes this strictFileExists check to fail since requests must have a trailing slash if and only if they map to a directory. The change that fixes this for me is to update SanitizePathJoin to consider a path unsafe only if the cleaned path is non-empty. So update this block to be: if relPath != "" && !filepath.IsLocal(relPath) {
// path is unsafe (see https://github.com/golang/go/issues/56336#issuecomment-1416214885)
return root
} I'm still walking through the code to verify that this makes sense and is the best place to fix it. I'm not 100% convinced yet, but am getting closer. |
SanitizePathJoin protects against directory traversal attacks by checking for requests whose URL path look like they are trying to request something other than a local file, and returns the root directory in those cases. The method is also careful to ensure that requests which contain a trailing slash include a trailing slash in the returned value. However, for requests that contain only a slash (requests for the root path), the IsLocal check returns early before the matching trailing slash is re-added. This change updates SanitizePathJoin to only perform the filepath.IsLocal check if the cleaned request URL path is non-empty. Fixes caddyserver#6352
SanitizePathJoin protects against directory traversal attacks by checking for requests whose URL path look like they are trying to request something other than a local file, and returns the root directory in those cases. The method is also careful to ensure that requests which contain a trailing slash include a trailing slash in the returned value. However, for requests that contain only a slash (requests for the root path), the IsLocal check returns early before the matching trailing slash is re-added. This change updates SanitizePathJoin to only perform the filepath.IsLocal check if the cleaned request URL path is non-empty. Fixes caddyserver#6352
SanitizePathJoin protects against directory traversal attacks by checking for requests whose URL path look like they are trying to request something other than a local file, and returns the root directory in those cases. The method is also careful to ensure that requests which contain a trailing slash include a trailing slash in the returned value. However, for requests that contain only a slash (requests for the root path), the IsLocal check returns early before the matching trailing slash is re-added. This change updates SanitizePathJoin to only perform the filepath.IsLocal check if the cleaned request URL path is non-empty. Fixes caddyserver#6352
SanitizePathJoin protects against directory traversal attacks by checking for requests whose URL path look like they are trying to request something other than a local file, and returns the root directory in those cases. The method is also careful to ensure that requests which contain a trailing slash include a trailing slash in the returned value. However, for requests that contain only a slash (requests for the root path), the IsLocal check returns early before the matching trailing slash is re-added. This change updates SanitizePathJoin to only perform the filepath.IsLocal check if the cleaned request URL path is non-empty. --- This change also updates the existing SanitizePathJoin tests to use filepath.FromSlash rather than filepath.Join. This makes the expected value a little easier to read, but also has the advantage of not being processed by filepath.Clean like filepath.Join is. This means that the exact expect value will be compared, not the result of first cleaning it. Fixes caddyserver#6352
Will's patch is elegant and simple. I'll tag a release momentarily. |
SanitizePathJoin protects against directory traversal attacks by checking for requests whose URL path look like they are trying to request something other than a local file, and returns the root directory in those cases. The method is also careful to ensure that requests which contain a trailing slash include a trailing slash in the returned value. However, for requests that contain only a slash (requests for the root path), the IsLocal check returns early before the matching trailing slash is re-added. This change updates SanitizePathJoin to only perform the filepath.IsLocal check if the cleaned request URL path is non-empty. --- This change also updates the existing SanitizePathJoin tests to use filepath.FromSlash rather than filepath.Join. This makes the expected value a little easier to read, but also has the advantage of not being processed by filepath.Clean like filepath.Join is. This means that the exact expect value will be compared, not the result of first cleaning it. Fixes #6352
in previous versions, this would work to route an SPA. i got this through google result showing matt's post here:
https://caddy.community/t/how-to-serve-a-single-page-app-spa-with-caddy-2/12770
however, in v2.8.0, this breaks. and must be replaced with
after a git bisect, i find the commit where the behavior changed to be
doing some more digging, but i thought i would raise this asap since perhaps other people were surprised by this change.
The text was updated successfully, but these errors were encountered: