Repository navigation
fix(github): encode owner and repo in request paths - #10085
Merged
Merged
Conversation
Route owner, repo, numeric ids, gist ids, usernames and workflow ids through safeUrlPathSegment, and branches/refs through a slash-preserving encoder, so a model-supplied value cannot steer the authenticated request to another api.github.com endpoint. Real names produce byte-identical URLs.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
[Medium impact] The PR appears safe to merge. SummaryAdds shared GitHub path helpers and applies them across tool requests and internal operations.
Reviews (3) · Last reviewed commit: "fix(github): await comment operations so..." · Reviewed by Greptile |
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 78 files
Reply with feedback, questions, or to request a fix.
Turn on auto-fix | Re-trigger cubic
Collaborator
Author
Collaborator
Author
|
@cubic-dev-ai review this PR |
Contributor
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
This branch was previously deployed
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
GitHub tools built REST URLs by interpolating
owner,repo, numeric ids, gist ids, usernames, workflow ids and branch names raw (https://api.github.com/repos/${params.owner}/${params.repo}/...). An LLM- or upstream-supplied value such asorgs/acme,x?yor1/../../usercould steer the request, with the user's token, to a different api.github.com endpoint.tools/github/request-path.ts:githubRepoPath(owner, repo): both go throughsafeUrlPathSegment. Empty values,./..and/or\are rejected, and anything else is percent-encoded.githubPathSegment(value, name): for single-segment ids (issue, pull, run, milestone, release, comment and reaction numbers, plusgist_id,usernameandworkflow_id).githubRefPath(ref, name): for the params GitHub's OpenAPI marksx-multi-segment(branch,commit-ref,git-ref,basehead). It keeps/, encodes each segment so?/#can't end the path, and rejects./..segments. Numbers are accepted.lib/internal/github/operations.ts(PR comment and latest-commit) now use these helpers. In the internal operations a rejected segment surfaces as a 400GitHubOperationError.list_workflow_runsand latest-commit already usedencodeURIComponent, so they keep that encoding viasafeUrlPathSegment(..., { allowSeparators: true }). Their bytes are unchanged; dot segments are now rejected too.Backward compatibility
Every value that worked before produces a byte-identical URL:
[A-Za-z0-9._-], and numbers are unchanged.$ & + , : ; = @ [ ] |) thatencodeURIComponentadds. Branches likerelease+1and workflow files likedeploy@v2.ymlstill send the same bytes.I compared old and new URLs after WHATWG parsing for every printable ASCII character. They differ only for:
#and?: before, the URL was cut off at these, so those requests were already broken.\: before, it was turned into a/.%: before, it was sent raw and GitHub decoded it as an escape. It is now sent as%25, which is the correct form.Values are trimmed. Surrounding whitespace in an owner, repo, id or ref only ever produced a 404 before; gist ids were already trimmed.
remove_labelkeeps its existingencodeURIComponent(name). Labels can contain/, and dot segments are already rejected for every tool request byassertNoDotPathSegmentsinrequest-transport.ts.Out of scope:
branch/refkeep raw/because the OpenAPI declares them multi-segment and GitHub matches them greedily. A branch likemain/protectioncan therefore still reach a GET sub-resource under the same repo, as it could before. DELETE stays confined under/git/refs/heads/.Test plan
tools/github/request-paths.test.tscovers:..,.,orgs/acmeanddemo\..owner/repo being rejectedx?yandocto#zbeing escaped/,+and@staying identicaljob_logs.test.tswas updated: an owner containing/is now rejected instead of encoded.bun run test tools/github/ lib/internal/github/: 199 tests pass. tsgo is clean on the changed files.github/rest-api-description.🤖 Generated with Claude Code