Repository navigation
fix(proxy): reject dot-segment request paths before routing - #17174
Conversation
The generic /repos/:owner/:repo catch-all labels only the first two path segments, while the full path is forwarded upstream. A literal or encoded '..' segment in the suffix could let an upstream that normalizes paths serve a different repository than the one the guard authorized. Reject '.' and '..' segments in all proxy modes before routing. Co-authored-by: Copilot App <[email protected]>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
A crafted /api/v3.. path can bypass guard labeling in default mode with a root API URL and a normalizing upstream, while separator-heavy paths can cause excessive memory allocation before authorization.
2 open issues
What changed in this PR
Adds early path validation to MCP Gateway’s GitHub API proxy as defense-in-depth against upstream dot-segment normalization in GHES and custom API deployments.
Changes:
- Rejects decoded
.and..path segments with400 invalid_pathbefore routing and guard processing. - Adds rejection tests for literal and encoded variants while preserving dot-prefixed names such as
.github. - Documents the path restrictions across proxy modes.
| File | Description |
|---|---|
| internal/proxy/handler.go | Adds dot-segment detection and early request rejection. |
| internal/proxy/handler_difc_test.go | Tests rejection without guard calls or forwarding, plus valid dot-prefixed paths. |
| docs/PROXY_MODE.md | Documents rejected paths and the error response. |
Review effort: Max (adaptive)
Refactor hasDotSegment to use strings.Cut for better efficiency. Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No reaction, star, issue, comment, branch, file, or PR was created. Untestable rows are flagged rather than counted as PASS.
|


Addresses githubnext/gh-aw-security#3745.
Problem
The generic
/repos/:owner/:repo(?:/.*)?catch-all route labels only the first two path segments, but the full path is forwarded upstream. A path like/repos/attacker/public-repo/../../victim-org/secret-repo/issuesis authorized againstattacker/public-repo; an upstream that performs RFC 3986 dot-segment normalization would serve the victim repo instead.api.github.comdoes not normalize dot-segments (verified: returns 404 for both literal and%2e%2eforms), so this is defense-in-depth for GHES / customGITHUB_API_URLdeployments behind normalizing proxies.Fix
proxyHandler.ServeHTTPnow rejects any request whose decoded path contains a.or..segment with400 invalid_path, before routing, guard labeling, or forwarding. Applies in all modes (default, read-only, enclave, delegated). Sincer.URL.Pathis decoded,%2e%2eand..%2Fare covered too. Dot-prefixed names like.githubare unaffected.Tests
TestServeHTTP_RejectsDotSegmentPaths: literal, encoded, encoded-slash,/api/v3-prefixed, and.variants are rejected without guard calls or upstream hits (all 5 fail without the fix).TestServeHTTP_AllowsDotPrefixedSegments:.github/..configpaths still forward.make agent-finishedpasses.