Repository navigation
fix(mcp): fail clearly on cross-origin OAuth redirects - #138263
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Good narrow security boundary. Rejecting body-preserving cross-origin redirects only for OAuth avoids credential/body replay while keeping ordinary MCP resource redirect compatibility. The hardened fetch being explicit in refresh and code-exchange paths is important.
|
Codex review: blocked before merge. Reviewed September 28, 2026, 3:51 PM ET / 19:51 UTC (Revision 9). ClawSweeper reviewWhat this changesThe branch routes MCP OAuth discovery, token exchange, and refresh through a guarded fetch that refuses cross-origin redirects carrying request bodies, while retaining ordinary MCP resource redirects. Merge readiness⛔ Blocked before merge - 3 items remain Current main and the latest release still allow the reported OAuth redirect replay. The repair appears sound, but its intentional break for existing redirecting OAuth providers needs an explicit maintainer decision. Priority: P1 Review scores
Verification
How this fits togetherMCP transports connect OpenClaw agents and CLI sessions to remote servers. OAuth discovery and token exchange supply credentials to those connections; the guarded fetch determines whether a redirected request reaches another origin. flowchart LR
A[Configured MCP server] --> B[MCP transport]
B --> C{Request type}
C -->|OAuth| D[Guarded OAuth fetch]
C -->|Resource| E[Resource fetch]
D --> F[Token response or clear refusal]
E --> G[MCP resource response]
Decision needed
Why: This is a deliberate security and upgrade tradeoff: those deployments may lose login or refresh, and the PR body still makes acceptance subject to maintainer review. Before merge
Agent review detailsSecurityNone. PR surfaceSource +72, Tests +271. Total +343 across 12 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep credential-bearing OAuth redirects fail-closed, preserve ordinary MCP resource behavior, and give affected operators clear guidance to advertise direct token endpoints once the upgrade tradeoff is approved. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main supplies an unsafe-replay fetch to MCP OAuth, and the pinned SDK uses it for token POSTs. This read-only review did not execute a current-main reproduction. Is this the best way to solve the issue? Yes, the separate OAuth fetch is a narrow repair and the first-hop guard blocks the reported replay. Maintainers still need to decide whether the intentional upgrade break is acceptable. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 89c0030e4c45. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Co-authored-by: hansraj <[email protected]>
|
* fix(mcp): constrain OAuth redirect replay Co-authored-by: hansraj <[email protected]> * test: make MCP OAuth checks hermetic * test: split guarded fetch redirect policy coverage * fix(mcp): preserve OAuth refresh redirect errors * test: keep Doctor OAuth fixture hermetic * test(mcp): adapt OAuth redirect proof to state worker --------- Co-authored-by: hansraj <[email protected]>
* fix(mcp): constrain OAuth redirect replay Co-authored-by: hansraj <[email protected]> * test: make MCP OAuth checks hermetic * test: split guarded fetch redirect policy coverage * fix(mcp): preserve OAuth refresh redirect errors * test: keep Doctor OAuth fixture hermetic * test(mcp): adapt OAuth redirect proof to state worker --------- Co-authored-by: hansraj <[email protected]> (cherry picked from commit 738b864)
What Problem This Solves
Fixes an issue where MCP OAuth login could follow a cross-origin 307/308 response by replaying its POST body to the redirected origin. The redirect crossed an origin boundary without giving the operator a clear failure at that boundary.
Why This Change Was Made
OAuth network calls now use one canonical guarded fetch that refuses cross-origin redirects when following them would preserve a non-GET/HEAD body. Ordinary MCP resource requests intentionally retain their existing redirect-body replay behavior, so the repair does not remove that transport capability.
The narrower OAuth/resource split incorporates the useful direction from #92021 while avoiding its broader compatibility impact. The earlier contributor is credited in the commit trailer.
User Impact
Normal direct token endpoints, same-origin OAuth redirects, cross-origin discovery redirects, and ordinary MCP resource requests keep working as before. A custom OAuth deployment that depends on a body-preserving cross-origin 307/308 token redirect now receives an explicit refusal and should advertise a direct token endpoint instead.
The compatibility choice for this patch is to accept that OAuth-only behavior change without a configuration escape hatch: replaying credentials across an origin boundary is not behavior to preserve. This remains subject to maintainer review.
No configuration, schema, persisted state, CLI syntax, or dependency changes are included.
Evidence
pnpm test src/agents/mcp-oauth-redirect.test.ts src/agents/mcp-transport.test.ts src/agents/mcp-http-fetch.test.ts src/agents/mcp-auth-profile.test.ts src/agents/mcp-oauth.test.ts src/agents/mcp-oauth-refresh.test.ts src/infra/net/fetch-guard.ssrf.test.ts— 192 tests passed across three repository-owned shards.pnpm check:changed— all selected formatting, core/core-test typecheck, dead-export, lint, and policy lanes passed.@modelcontextprotocol/sdk1.30.0 source at commit2d889f2:auth()preserves its suppliedfetchFnacross retries and passes it to discovery, dynamic registration, authorization-code/noninteractive token exchange, and refresh. The credential-bearing helpers call that same function for token POSTs and registration POSTs, so none of those exchanges falls back to global fetch when OpenClaw supplies the guarded fetch.