Skip to content

Consolidate HTTP redirect-suppression policy - #17086

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-checkredirect-helper
Nov 22, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-checkredirect-helper

Conversation

@lpcox

@lpcox lpcox commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Proxy, Azure OIDC, and MCP HTTP clients duplicate the same redirect-suppression callback; the proxy also assigns it redundantly.

  • Shared policy: Introduce httputil.NoRedirectPolicy, returning http.ErrUseLastResponse and documenting the security rationale.
  • Proxy: Remove the constructor assignment; retain the per-request client-copy override without modifying the original client.
  • Scope: Leave schema validation’s redirect limit and HTTPS-downgrade protection unchanged.
client.CheckRedirect = httputil.NoRedirectPolicy

@lpcox lpcox changed the title [WIP] Consolidate CheckRedirect closure into a helper Consolidate HTTP redirect-suppression policy Nov 22, 2026
@lpcox
lpcox marked this pull request as ready for review November 22, 2026 17:26
Copilot AI adaptive review requested due to automatic review settings November 22, 2026 17:26

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.

🟢 Approval recommended

There are no active review issues for the shared redirect-suppression change.

No open issues 🎉

What changed in this PR

Consolidates redirect suppression into a shared HTTP utility, addressing #17057 while preserving the proxy, Azure OIDC, and MCP clients’ existing behavior.

Changes:

  • Adds httputil.NoRedirectPolicy with security documentation and tests covering five redirect status codes.
  • Replaces duplicate callbacks and removes the proxy’s redundant constructor assignment, preserving its per-request override without modifying the original client.
  • Leaves schema validation’s separate redirect protections unchanged.
File Description
internal/​proxy/​proxy.go Uses the shared policy on client copies and removes redundant initialization.
internal/​proxy/​new_comprehensive_test.go Removes the obsolete constructor-policy assertion and updates its comment.
internal/​proxy/​forward_to_github_test.go Checks that the per-request override preserves the original client’s policy.
internal/​oidc/​azure.go Uses the shared policy for Azure token requests.
internal/​mcp/​http_transport_client.go Uses the shared policy for OIDC-authenticated MCP requests.
internal/​httputil/​httputil.go Defines and documents the shared redirect-suppression policy.
internal/​httputil/​httputil_test.go Tests redirect suppression and preservation of response status, headers, and body.

Review effort: Balanced (adaptive)

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

@copilot fix failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/45045964280/job/137291085797?pr=17086

Fixed the two testifylint failures by using require for error assertions. make agent-finished passes, including golangci-lint. Commit: ad75ed4.

@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 (normal AWF container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 6 tools absent from catalog (only 23 read-only tools exposed) BLOCKED ⚠️
C CLI reads (list_issues, get_file_contents via proxied github CLI) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh unauthenticated — no GH_TOKEN set, writes never attempted BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated — no GH_TOKEN set, mutations never attempted BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Part B: all 6 targeted write tools were absent from the exposed MCP tool catalog (backend launched with GITHUB_READ_ONLY=1), so this confirms backend config, not the gateway's independent DIFC write-block layer.
⚠️ Parts D/E: gh CLI had no GH_TOKEN in this environment, so no write/mutation request reached GitHub at all — the token-scope boundary could not be exercised this run.

No writes leaked in any part. Reads succeeded on both surfaces (A, C).

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

@lpcox
lpcox merged commit 2cadab4 into main Nov 22, 2026
30 checks passed
@lpcox
lpcox deleted the copilot/duplicate-code-checkredirect-helper branch November 22, 2026 17:54
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.

[duplicate-code] Duplicate Code Pattern: Redirect-suppression CheckRedirect closure duplicated across HTTP clients

3 participants