Skip to content

fix(mcp): harden OAuth request isolation - #7481

Merged
waleedlatif1 merged 3 commits into
stagingfrom
codex/harden-mcp-oauth-refresh-coordination
Sep 4, 2026
Merged

fix(mcp): harden OAuth request isolation#7481
waleedlatif1 merged 3 commits into
stagingfrom
codex/harden-mcp-oauth-refresh-coordination

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • keep configured MCP headers off OAuth discovery and token requests
  • cancel queued OAuth refresh-lock waits without abandoning an active token rotation
  • preserve ambiguous Redis lock ownership while a fail-open refresh runs

Type of Change

  • Bug fix

Testing

  • 298 tests across 15 MCP, OAuth, execution, and cancellation suites
  • bun run lint
  • bun run check:audits
  • bun run docs-manifest:check
  • bunx tsc --noEmit --incremental false

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 4, 2026 7:51pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR hardens MCP OAuth request isolation and cancellation behavior.

  • Applies configured MCP headers only to the exact MCP endpoint, keeping them off OAuth discovery and token requests.
  • Makes queued and cross-process refresh-lock waits abort-aware without interrupting an already-running token rotation.
  • Preserves uncertain lock ownership when an acquire fails open, resolving the previously reported refresh-serialization race.
  • Adds focused coverage for header scoping, queued cancellation, and ambiguous lock acquisition.

Confidence Score: 5/5

The PR appears safe to merge; no actionable new failure remains, and the previously reported refresh-serialization issue is fully fixed.

The current implementation preserves a potentially acquired owner token while an uncoordinated refresh runs, releases it only when cancellation prevents the refresh callback, and scopes configured MCP headers away from OAuth endpoints. Abort checks prevent cancelled queued work from executing without abandoning an already-running token rotation.

Important Files Changed

Filename Overview
apps/sim/lib/mcp/client.ts Routes OAuth transports through endpoint-scoped fetch handling while retaining configured headers for non-OAuth transports.
apps/sim/lib/mcp/oauth/coordinated-fetch.ts Restricts configured headers to the MCP endpoint and propagates request cancellation into refresh-lock coordination.
apps/sim/lib/mcp/oauth/storage.ts Adds abort-aware queue and Redis-lock waiting while preserving ambiguous lock ownership for fail-open refreshes.
apps/sim/lib/mcp/client.test.ts Verifies OAuth transports use scoped fetch injection rather than globally applied request initialization.
apps/sim/lib/mcp/oauth/coordinated-fetch.test.ts Covers endpoint-only header application and prompt cancellation while waiting for refresh serialization.
apps/sim/lib/mcp/oauth/storage.test.ts Covers queued cancellation and both fail-open and cancelled ambiguous-acquire ownership behavior.

Sequence Diagram

sequenceDiagram
    participant Client as MCP client
    participant Scope as Endpoint-scoped fetch
    participant MCP as MCP endpoint
    participant Lock as OAuth refresh lock
    participant OAuth as OAuth discovery/token endpoint

    Client->>Scope: MCP request with configured headers
    Scope->>MCP: Forward request with configured headers
    MCP-->>Client: 401 OAuth challenge
    Client->>Lock: Wait for serialized refresh
    alt Request is cancelled while queued
        Lock-->>Client: Reject without running refresh
    else Lock acquired or safely falls open
        Lock->>OAuth: Discovery/token request without configured MCP headers
        OAuth-->>Lock: Updated credentials
        Client->>Scope: Retry MCP request
        Scope->>MCP: Forward with configured headers
    end
Loading

Reviews (3): Last reviewed commit: "fix(mcp): preserve ambiguous refresh loc..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 6 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/mcp/oauth/storage.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

Comment thread apps/sim/lib/mcp/oauth/storage.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 713b9e9 into staging Sep 4, 2026
32 checks passed
@waleedlatif1
waleedlatif1 deleted the codex/harden-mcp-oauth-refresh-coordination branch September 4, 2026 19:57
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.

1 participant