fix(raw): reject traversal segments when constructing raw content URLs - #3108
Merged
SamMorrowDrums merged 3 commits intoAug 19, 2026
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds traversal validation to raw-content URL construction to prevent repository/ref rebinding.
Changes:
- Rejects literal and percent-decoded
..segments. - Propagates URL validation errors.
- Adds traversal and benign-filename tests.
Show a summary per file
| File | Description |
|---|---|
pkg/raw/raw.go |
Adds URL traversal validation and error propagation. |
pkg/raw/raw_test.go |
Tests valid paths and traversal rejection. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
…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
SamMorrowDrums
deleted the
sammorrowdrums-raw-content-path-traversal-hardening
branch
August 19, 2026 13:22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
raw.Clientbuildsraw.githubusercontent.comURLs withurl.URL.JoinPath(owner, repo, ref, path).JoinPathnormalizes..segments before producing the final URL, so a
path(or, in principle,owner/repo/ref) containing enough parent-directory segments couldconsume 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
rejectPathTraversal, which checks every/-separated segmentof
owner,repo,ref/sha, andpathand rejects the request ifany segment is, or percent-decodes to,
"..".refURL,commitURL, andURLFromOptsnow return(string, error)so the check happens at URL-construction time;
GetRawContentpropagates the error instead of issuing the request.
file..txt,..hidden) are left untouched.Tests
Added table-driven cases to
pkg/raw/raw_test.gocovering: normal andnested paths,
refs/heads/...behavior, benign double-dot filenames,literal
..segments (including a full owner/repo/ref rebindingattempt), and percent-encoded (
%2e%2e, partially-encoded) traversalsegments.
Validation
script/lint— 0 issuesscript/test— all packages passNo MCP tool schemas changed, so toolsnaps/docs regeneration was not needed.
Fixes #3103