Skip to content

[Bug]: MCP OAuth credentials keyed by server URL, not authorization-server issuer (breaks SEP-2352 issuer-bound credentials under 2026-07-28) #6019

Open

Description

@branben

Bug Description

The 2026-07-28 MCP spec clarifies client-credential binding: client credentials are bound to the authorization server that issued them — clients MUST key persisted credentials by the issuer identifier, MUST NOT reuse them with a different authorization server, and MUST re-register when the authorization server changes (SEP-2352). The spec also tightens authorization-response validation (iss per RFC 9207 — MCP clients MUST validate a present iss against the recorded issuer before redeeming the code, SEP-2468), resource-server discovery via Protected Resource Metadata (RFC 9728), and per-server Resource Indicators (RFC 8707).

OpenHands' OAuth token store and refresh logic key everything by server URL instead of issuer:

  • openhands-agent-server/openhands/agent_server/mcp_oauth_store.py builds FastMCP token-store keys like <server-url>/tokens, <server-url>/client_info, <server-url>/token_expiry (see _OAUTH_KEY_SPECS), and _find_matching_oauth_server matches by server.url only.
  • openhands-sdk/openhands/sdk/mcp/oauth.py (MCPOAuth._refresh_token) happily refreshes against a discovered authorization-server metadata endpoint without recording/validating the issuer that minted the stored credentials.

Consequences under the new spec:

  1. If a server's authorization-server mapping changes (common with SSO providers, or a mirror/proxy standing in front of the same MCP endpoint), the stored token is reused against the new issuer — exactly what SEP-2352 forbids.
  2. There is no iss validation (RFC 9207) before code redemption, so a malicious/compromised authorization server can substitute its own token for a different issuer.

Expected Behavior

Actual Behavior

  • Token-store keys and refresh matching are per-server-URL (mcp_oauth_store.py _OAUTH_KEY_SPECS, _find_matching_oauth_server); no issuer binding, no iss validation.

Steps to Reproduce

  1. Configure an OAuth-protected MCP server (e.g. GitLab or Atlassian) and complete install-time OAuth — tokens stored under the server URL.
  2. Swap the auth gateway / authorization-server discovery URL (or point the same host at a different AS).
  3. Observe the stored token being reused against the new issuer without re-registration.

Acceptance Criteria

  • OAuth credentials stored/retrieved by issuer identifier (with server-URL fallback for legacy persisted state)
  • iss parameter validated per RFC 9207 before code redemption; mismatch raises instead of silently proceeding
  • Credentials never reused across a changed authorization server (SEP-2352)

Evidence and Additional Context

This issue was filed by an AI agent (OpenHands) on behalf of branben.

Activity

  1. all-hands-bot commented on Oct 15, 2026

    @all-hands-bot
    Collaborator

    No exact or near-exact duplicate exists. The strongest overlap is the open umbrella epic #6017, whose acceptance criteria explicitly enumerate 'OAuth refresh keys by authorization-server issuer, not server URL (SEP-2352)' and whose desired-behavior item 5 covers issuer-bound credentials / RFC 9207 / RFC 9728 / RFC 8707 — i.e. the same root cause this issue reports. However, #6017 is a broad tracking epic (mcp 2.x/fastmcp 4.x upgrade, transport, result shapes), and #6019 is a concrete, reproducible sub-issue with its own acceptance criteria. Consistent with the sibling issue #6018 (same author, same filing burst, resolved by the bot as 'not an exact duplicate' of the epic, keep open but anchor in the epic), this should be treated as overlapping-scope rather than a duplicate and should not be auto-closed. The other OAuth issues (#6020, #5375, #5276, #5863, #5860) are related but distinct root causes (registration/CIMD, redirect URI, callback error handling).

    Found 3 possible duplicate issues:

    1. #6017 — [Epic] MCP 2026-07-28 spec support: upgrade to mcp 2.x / fastmcp 4.x (stateless MCP, server/discover, per-request _meta)
    2. #6020 — [Bug]: MCP OAuth refresh hardcodes loopback redirect without app_type; new-spec authorization servers reject dynamic registrations (RFC 7591 deprecation / CIMD)
    3. #5375 — [Bug]: GitLab MCP OAuth fails with localhost redirect URI

    These may not be exact duplicates, but the scope appears to overlap enough that keeping discussion in one place may be more useful.

    This comment was created by an AI assistant (OpenHands) on behalf of the repository maintainer.

  2. all-hands-bot commented on Oct 16, 2026

    @all-hands-bot
    Collaborator

    The following comments were added by the OpenHands AI agent.

    Decision needed

    I read the repository's root AGENTS.md, CONTRIBUTING.md, openhands-agent-server/AGENTS.md, openhands-sdk/openhands/sdk/AGENTS.md, and .agents/skills/custom-codereview-guide.md, plus the code paths this issue names (mcp_oauth_store.py, openhands/sdk/mcp/oauth.py, openhands/sdk/mcp/config.py, mcp_router.py), the related epic #6017, and the pinned dependencies. One material scope decision cannot be inferred from that evidence, so this issue is not marked ready-for-dev.

    What the repository evidence shows:

    Because the primary acceptance criteria here are only achievable on the upgraded stack that #6017 owns, the smallest coherent scope depends on your intent:

    1. Should this stay a separate issue, or be closed as already covered by epic [Epic] MCP 2026-07-28 spec support: upgrade to mcp 2.x / fastmcp 4.x (stateless MCP, server/discover, per-request _meta) #6017 — i.e. is [Bug]: MCP OAuth credentials keyed by server URL, not authorization-server issuer (breaks SEP-2352 issuer-bound credentials under 2026-07-28) #6019 intended as the repo-owned tracking issue for the OAuth slice, delivered when Unlocked installs resolve browser-use 0.11.13 with mcp 2.x — browser tools silently disappear #5152 unblocks the mcp 2.x / fastmcp 4.x upgrade?
    2. If it stays open, what is the deliverable before that upgrade? Under the current pin the issuer-keying and RFC 9207 iss validation cannot be implemented in this repository. Is the intended scope to wait for the upgrade, or something achievable now (for example persisting the discovered issuer alongside stored OAuth state, which would not by itself satisfy RFC 9207 validation before code redemption)?
    3. Do you have a real reproduction or user report of credentials being reused after an authorization-server change (which provider and workflow), rather than a code-inspection inference? That is what would raise priority above priority:low.
  3. branben commented on Oct 16, 2026

    @branben
    Author

    Thanks for the thorough root-cause analysis — it matches our verification. Decisions (BLUF):

    1. Stay open, anchored in #6017 as the repo-owned OAuth slice → yes.
    This is the tracking issue for the issuer-keying slice (U5 in the epic plan). It stays open; the epic consumes it. Deliverable timing is tied to the stack upgrade — see point 2.

    2. Deliverable before the upgrade → none; this is gated on mcp>=2 / fastmcp>=4.
    Confirmed: mcp 1.28.1 has no issuer binding and no RFC 9207 iss handling, and FastMCP owns the token-store key format (<server-url>/tokens, /client_info, /token_expiry) even in 4.1.0 — so issuer-keying genuinely cannot be implemented under the current pin. Scope: after the upgrade, re-key MCPSettingsOAuthTokenStore by authorization-server issuer (a suffix on the mcp 2.x base keys) and validate iss per RFC 9207 before code redemption. No interim half-measure (e.g. persisting a discovered issuer alongside state) — it would not satisfy RFC 9207 and would be throwaway.

    3. Priority → keep priority:low; hypothesis-backed, not reproduction-backed.
    Trigger is code-inspection inference (credential reuse after authorization-server change), not a confirmed user-triggered failure. We don't have a concrete provider + workflow reproduction. Revisit priority if/when a real user report lands.

    This decision summary was prepared by an AI agent (OpenHands) on behalf of the issue author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions