net/url: fix JoinPath to clean percent-encoded dot-dot traversals#78562
net/url: fix JoinPath to clean percent-encoded dot-dot traversals#78562mohammadmseet-hue wants to merge 1 commit intogolang:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
3470b49 to
f1c328c
Compare
|
This PR (HEAD: f1c328c) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/763541. Important tips:
|
JoinPath passes path elements directly to path.Join after
prepending the base URL's escaped path. path.Join only
recognises literal "." and ".." tokens, so an element like
"..%2Fadmin" is treated as an opaque single filename.
When setPath later decodes the percent-encoding, URL.Path
contains an unresolved "../" traversal.
This directly contradicts the documented guarantee:
The result is cleaned of any ./ or ../ elements.
All five percent-encoded variants are affected:
..%2Fadmin, %2E%2E/admin, %2E%2E%2Fadmin,
.%2E%2Fadmin, and %2E.%2Fadmin
Fix: decode each caller-supplied element with PathUnescape
before joining so that path.Join can see and clean any
traversal sequence, then re-encode each decoded segment
with PathEscape so the result round-trips correctly. The
base URL's own escaped path is left unchanged.
f1c328c to
0f7d6d3
Compare
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/763541. |
|
This PR (HEAD: 0f7d6d3) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/763541. Important tips:
|
|
Message from Mohammad Seet: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/763541. |
JoinPath and (*URL).JoinPath document that:
This guarantee fails for percent-encoded variants of traversal
sequences. path.Join only recognises the literal tokens "." and
".." so it treats "..%2Fadmin" as an opaque single filename. When
setPath later decodes the percent-encoding, URL.Path contains an
unresolved "../" traversal.
Concrete example:
All five encoding variants are affected:
This enables auth bypass in any Go application that uses JoinPath
to build a URL from untrusted user input and enforces access
control based on a path prefix:
Fix: decode each caller-supplied element with PathUnescape before
joining so that path.Join can see and clean the real traversal
tokens, then re-encode each decoded segment with PathEscape so the
result round-trips correctly. The base URL's own escaped path is
left unchanged.
Added five new test cases covering all encoding variants.
Fixes #78564