Skip to content

fix(mcp): fail clearly on cross-origin OAuth redirects - #138263

Merged
mmaps merged 6 commits into
openclaw:mainfrom
mmaps:fix/fix-1014
Sep 29, 2026
Merged

mmaps merged 6 commits into
openclaw:mainfrom
mmaps:fix/fix-1014

Conversation

@mmaps

@mmaps mmaps commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Added boundary regressions for native runtime OAuth, CLI authorization-code completion, refresh without an injected fetch, same-origin OAuth redirects, and ordinary MCP compatibility.
  • 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.
  • Live public HTTPS proof with synthetic values: OAuth mode refused the first cross-origin 307; the ordinary MCP mode reached the redirected endpoint with HTTP 200 and its POST body intact.
  • Directly verified the pinned @modelcontextprotocol/sdk 1.30.0 source at commit 2d889f2: auth() preserves its supplied fetchFn across 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.
  • Local agentic review found no correctness issues after the final current-main rebase.

@mmaps
mmaps requested a review from a team as a code owner September 4, 2026 12:36
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 4, 2026

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

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.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 28, 2026, 3:51 PM ET / 19:51 UTC (Revision 9).

ClawSweeper review

What this changes

The 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
Reviewed head: 02eb3e4c0d725f8fa780cb6bade05d6824a9d8bf
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused guard and SDK-boundary coverage are solid, with a specific live HTTPS result; the remaining obstacle is acceptance of the upgrade behavior.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body reports a public HTTPS run using the changed guarded-fetch path: OAuth mode refused a cross-origin 307, while ordinary MCP mode completed the redirected POST with HTTP 200. Real-SDK tests supplement that observation, and the PR changes no stored-data format.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports a public HTTPS run using the changed guarded-fetch path: OAuth mode refused a cross-origin 307, while ordinary MCP mode completed the redirected POST with HTTP 200. Real-SDK tests supplement that observation, and the PR changes no stored-data format.
Evidence reviewed 13 items Current main retains the reported behavior: The shared MCP fetch opts into unsafe cross-origin body replay, and the OAuth transport supplies that fetch for authorization requests.
Current-main OAuth wiring: The OAuth bearer wrapper receives the resource fetch as its authorization fetch.
Introduced final-effect guard: The PR rejects a cross-origin redirect when the redirected request would retain a non-GET/HEAD body, before issuing the next network request.
Findings None None.
Security None None.

How this fits together

MCP 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]
Loading

Decision needed

Question Recommendation
Should OAuth token and registration POSTs always refuse body-preserving cross-origin 307/308 redirects, including for existing deployments that currently rely on them? Approve OAuth refusal: Accept the OAuth-only upgrade break and tell affected operators to expose direct token and registration endpoints.

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

  • Resolve merge risk (P1) - Existing OAuth providers that return a cross-origin 307/308 for token or registration POSTs will stop completing login or refresh after upgrade; the proposed OAuth-only break has not received explicit maintainer acceptance.
  • Complete next step (P2) - Obtain explicit owner acceptance of the OAuth redirect upgrade behavior and add the new tests’ measured single-worker wall time and CI seconds to the PR body.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +72, Tests +271. Total +343 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 5 125 53 +72
Tests 7 284 13 +271
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 409 66 +343

Review metrics

Metric Value Why it matters
Production and test growth production +72 net lines, tests +271 net lines The stated OAuth/resource split explains the production growth; the added tests cover redirect, code-exchange, and refresh boundaries.

Merge-risk options

Maintainer options:

  1. Accept the OAuth upgrade break (recommended)
    Approve the refusal for credential-bearing cross-origin redirects and communicate the direct-endpoint requirement to affected operators.
  2. Define a legacy exception
    If compatibility takes priority, add an explicit operator-controlled exception with focused proof for both legacy and strict behavior.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Current OAuth traffic can replay credential-bearing POST bodies to a different origin, making this a focused urgent security repair.
  • merge-risk: 🚨 compatibility: The proposed refusal can stop login and refresh for existing OAuth providers that depend on cross-origin body-preserving redirects.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports a public HTTPS run using the changed guarded-fetch path: OAuth mode refused a cross-origin 307, while ordinary MCP mode completed the redirected POST with HTTP 200. Real-SDK tests supplement that observation, and the PR changes no stored-data format.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports a public HTTPS run using the changed guarded-fetch path: OAuth mode refused a cross-origin 307, while ordinary MCP mode completed the redirected POST with HTTP 200. Real-SDK tests supplement that observation, and the PR changes no stored-data format.

Evidence

What I checked:

  • Current main retains the reported behavior: The shared MCP fetch opts into unsafe cross-origin body replay, and the OAuth transport supplies that fetch for authorization requests. (src/agents/mcp-http-fetch.ts:112, 89c0030e4c45)
  • Current-main OAuth wiring: The OAuth bearer wrapper receives the resource fetch as its authorization fetch. (src/agents/mcp-transport.ts:204, 89c0030e4c45)
  • Introduced final-effect guard: The PR rejects a cross-origin redirect when the redirected request would retain a non-GET/HEAD body, before issuing the next network request. (src/infra/net/fetch-guard.ts:715, 02eb3e4c0d72)
  • OAuth and resource paths remain separate: The transport supplies the new guarded OAuth fetch for authorization work and retains the existing resource fetch for MCP requests. (src/agents/mcp-transport.ts:207, 02eb3e4c0d72)
  • Dependency contract: The pinned MCP SDK sends token POST bodies through its supplied fetch function; its refresh path passes that function onward and may absorb a transport failure before starting authorization. (src/client/auth.ts:1248, 2d889f2b329e)
  • Refresh refusal remains visible: The branch retains the last fetch failure when the SDK absorbs a refresh transport error; the new regression exercises code exchange and refresh through the real SDK with an injected transport response. (src/agents/mcp-oauth.ts:208, 02eb3e4c0d72)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed 2026-09-04T12:46:19.637Z sha b83006e024b0cfa6c20f09baa18c43ccea0741fa :: blocked before merge. :: none
  • reviewed 2026-09-04T13:01:55.284Z sha b83006e024b0cfa6c20f09baa18c43ccea0741fa :: blocked before merge. :: none
  • reviewed 2026-09-04T15:50:35.344Z sha 310944c68960dd728b240e2f6573318cc7dee7c7 :: blocked before merge. :: none
  • reviewed 2026-09-16T16:43:18.886Z sha 12cb458c58dc049e4016d393db198a5638dc54f6 :: blocked before merge. :: [P2] Preserve the redirect refusal through SDK token refresh
  • reviewed 2026-09-16T17:02:44.747Z sha e949620b6266c63e3822834468a76e60646ad41a :: blocked before merge. :: none
  • reviewed 2026-09-16T17:27:12.512Z sha e737e8be231a17fc96f365c6bd3f5a9f84e4d8c3 :: blocked before merge. :: none
  • reviewed September 22, 2026, 11:59 PM ET / September 23, 2026, 03:59 UTC (Revision 7) sha unknown :: blocked before merge. :: none
  • reviewed September 22, 2026, 11:59 PM ET / September 23, 2026, 03:59 UTC (Revision 8) sha unknown :: blocked before merge. :: none

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 16, 2026
@mmaps

mmaps commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Sep 16, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 02eb3e4c0d725f8fa780cb6bade05d6824a9d8bf
  • Maintainer: @mmaps
  • Repository role: maintain

These security sensitive changes were made:

  • src/agents/mcp-auth-profile.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/mcp-oauth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@mmaps
mmaps merged commit 738b864 into openclaw:main Sep 29, 2026
210 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
* 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]>
yozakura-ava pushed a commit to yozakura-ava/openclaw that referenced this pull request Oct 6, 2026
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants