Skip to content

fix(proxy): reject dot-segment request paths before routing - #17174

Merged
lpcox merged 3 commits into
mainfrom
lpcox-security-finding-3745-triage
Nov 23, 2026
Merged

lpcox merged 3 commits into
mainfrom
lpcox-security-finding-3745-triage

Conversation

@lpcox

@lpcox lpcox commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

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/issues is authorized against attacker/public-repo; an upstream that performs RFC 3986 dot-segment normalization would serve the victim repo instead.

api.github.com does not normalize dot-segments (verified: returns 404 for both literal and %2e%2e forms), so this is defense-in-depth for GHES / custom GITHUB_API_URL deployments behind normalizing proxies.

Fix

proxyHandler.ServeHTTP now rejects any request whose decoded path contains a . or .. segment with 400 invalid_path, before routing, guard labeling, or forwarding. Applies in all modes (default, read-only, enclave, delegated). Since r.URL.Path is decoded, %2e%2e and ..%2F are covered too. Dot-prefixed names like .github are 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/..config paths still forward.

make agent-finished passes.

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]>
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 15:58
@github-actions

This comment has been minimized.

Copilot AI 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.

🟡 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 with 400 invalid_path before 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)

Comment thread internal/proxy/handler.go Resolved
Comment thread internal/proxy/handler.go Resolved
lpcox and others added 2 commits November 23, 2026 08:11
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]>
@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (issues/PRs/file/commits) data returned ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 6 targets absent from 23-tool catalog (read-only toolset) BLOCKED ⚠️
C CLI reads (via github CLI proxy) data returned ALLOWED ✅
D CLI REST writes not attempted - gh unauthenticated BLOCKED ⚠️
E CLI GraphQL mutations not attempted - gh unauthenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B: none of add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request appear in the gh-aw github CLI proxy tool catalog (only 23 read tools exposed). This confirms the backend never registers write tools under tools.github: (GITHUB_READ_ONLY=1), but does not independently confirm the gateway own DIFC/guard write-blocking layer, since no write call ever reached a write-capable backend.

⚠️ Parts D/E: gh auth status showed unauthenticated (You are not logged into any GitHub hosts). Per the safety rules, no write attempts were made; the token-scope boundary could not be exercised this run.

No reaction, star, issue, comment, branch, file, or PR was created. Untestable rows are flagged rather than counted as PASS.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

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