| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
url.URL.JoinPath normalizes ".." segments before producing the final URL. A path containing enough parent-directory segments could therefore consume the owner, repo, and ref components already joined onto the base URL, rebinding the raw.githubusercontent.com request to a different owner/repository/ref than the caller specified. Reject any owner, repo, ref/sha, or path component whose "/"-separated segments are, or percent-decode to, ".." before building the URL. Benign filenames such as "file..txt" or "..hidden" are unaffected. URLFromOpts, refURL, and commitURL now return an error alongside the URL string so this can be enforced at construction time; GetRawContent propagates it. Adds table-driven tests covering normal, nested, and benign double-dot paths as well as literal and percent-encoded traversal attempts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Adds traversal validation to raw-content URL construction to prevent repository/ref rebinding.
Changes:
| File | Description |
|---|---|
| pkg/raw/raw.go | Adds URL traversal validation and error propagation. |
| pkg/raw/raw_test.go | Tests valid paths and traversal rejection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
…tors rejectPathTraversal split components on literal "/" before checking each segment, so a segment containing an encoded separator (e.g. "%2e%2e%2fsecret.txt") decoded to "../secret.txt" instead of "..", and the check never caught it. Percent-decoding a segment can therefore introduce new "/"-separated subsegments that were invisible to the original literal split. Recursively re-split and re-check the decoded form whenever decoding changes a segment, so a ".." revealed by one or more layers of percent-decoding (including through an encoded separator, or double-encoding) is rejected regardless of where it appears. Add regression tests for encoded-separator traversal, encoded separators in other components, and double percent-encoded dot-dot segments, plus a benign percent-encoded filename case to confirm non-traversal decodes still pass through. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ntent-path-traversal-hardening
| Back | FazBrowse Home | New Git URL |
Summary
raw.Client builds raw.githubusercontent.com URLs with
url.URL.JoinPath(owner, repo, ref, path). JoinPath normalizes ..
segments before producing the final URL, so a path (or, in principle,
owner/repo/ref) containing enough parent-directory segments could
consume the already-joined components and rebind the outbound request
to a different owner, repository, or ref than the one identified by
the resource URI.
Change
of owner, repo, ref/sha, and path and rejects the request if
any segment is, or percent-decodes to, "..".
so the check happens at URL-construction time; GetRawContent
propagates the error instead of issuing the request.
..hidden) are left untouched.
Tests
Added table-driven cases to pkg/raw/raw_test.go covering: normal and
nested paths, refs/heads/... behavior, benign double-dot filenames,
literal .. segments (including a full owner/repo/ref rebinding
attempt), and percent-encoded (%2e%2e, partially-encoded) traversal
segments.
Validation
No MCP tool schemas changed, so toolsnaps/docs regeneration was not needed.
Fixes #3103
Acknowledgments
Thanks @Mirr2 for the report that led to this hardening.