Skip to content

fix(github): encode owner and repo in request paths - #10085

Merged
waleedlatif1 merged 2 commits into
stagingfrom
sweep3/github-encoding
Nov 16, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
sweep3/github-encoding

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

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 as orgs/acme, x?y or 1/../../user could steer the request, with the user's token, to a different api.github.com endpoint.

  • New tools/github/request-path.ts:
    • githubRepoPath(owner, repo): both go through safeUrlPathSegment. 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, plus gist_id, username and workflow_id).
    • githubRefPath(ref, name): for the params GitHub's OpenAPI marks x-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.
  • All 74 GitHub tool URL builders and lib/internal/github/operations.ts (PR comment and latest-commit) now use these helpers. In the internal operations a rejected segment surfaces as a 400 GitHubOperationError.
  • list_workflow_runs and latest-commit already used encodeURIComponent, so they keep that encoding via safeUrlPathSegment(..., { allowSeparators: true }). Their bytes are unchanged; dot segments are now rejected too.

Backward compatibility

Every value that worked before produces a byte-identical URL:

  • Valid owner/repo names use only [A-Za-z0-9._-], and numbers are unchanged.
  • The helpers restore the raw-safe escapes ($ & + , : ; = @ [ ] |) that encodeURIComponent adds. Branches like release+1 and workflow files like deploy@v2.yml still 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_label keeps its existing encodeURIComponent(name). Labels can contain /, and dot segments are already rejected for every tool request by assertNoDotPathSegments in request-transport.ts.

Out of scope: branch/ref keep raw / because the OpenAPI declares them multi-segment and GitHub matches them greedily. A branch like main/protection can 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.ts covers:
    • real names (dots, dashes, underscores, digits) staying byte-identical
    • .., ., orgs/acme and demo\.. owner/repo being rejected
    • x?y and octo#z being escaped
    • smuggled numeric ids, workflow ids, gist ids and usernames being rejected
    • branches with /, + and @ staying identical
    • numeric refs being accepted
    • branch dot segments being rejected
    • the latest-commit operation returning 400
  • Ran the new tests against the pre-fix code: all 10 guard tests fail, and the byte-identity tests pass on both old and new code.
  • job_logs.test.ts was 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.
  • An independent reviewer checked every changed builder against github/rest-api-description.

🤖 Generated with Claude Code

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.
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 16, 2026 7:01am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Adds shared GitHub path helpers and applies them across tool requests and internal operations.

  • GitHub requests keep caller values inside their intended paths.

Reviews (3) · Last reviewed commit: "fix(github): await comment operations so..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 78 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 79 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 748ee49 into staging Nov 16, 2026
81 checks passed

@waltonsteve147-coder waltonsteve147-coder left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

This branch was previously deployed

1 inactive deployment
Preview — f5c024c6 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants