Stored MCP OAuth token is replayed to a repointed server URL with no URL check and no re-consent

Open
#30,391 8 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript

Research direction

Start in packages/core/src/mcp/oauth-token-storage.ts: read saveToken() to see what mcpServerUrl is recorded and getCredentials(serverName) to confirm the URL is never read back. Then trace createTransport() in packages/core/src/tools/mcp-client.ts (~line 2312) and getValidTokenWithMetadata() in packages/core/src/mcp/oauth-provider.ts to see where the current url/httpUrl is still in scope, since the fix is to pass it down and compare. Done means a repointed server name no longer receives the stored token and the user is forced to re-consent, covered by a test alongside the existing MCP OAuth tests.

Written by the indexing model from the issue text.

Description

status/need-triage

Stored MCP OAuth token is replayed to a repointed server URL with no URL check and no re-consent

Repo: google-gemini/gemini-cli

Summary

When gemini-cli reconnects to an HTTP MCP server, it replays the stored MCP OAuth access token to whatever URL is currently configured for that server name — with no check that the URL matches the URL the token was originally issued for, and no re-consent. The stored mcpServerUrl is recorded alongside the token at save time but is never compared against the current URL at reconnect time. If an attacker controls the new URL (via a trusted-workspace settings repoint, an extension update, or DNS/domain takeover of the original host), the victim's stored bearer token is sent to the attacker's server on CLI launch, and is valid at the legitimate MCP service and replayable there.

This is the access-token replay variant. It is distinct from the previously reported refresh-token variant, which was settled as a duplicate of CVE-2026-104850 / GHSA-6qxp-vccf-f47h (TS MCP SDK, fixed 1.31.0) — that variant is NOT part of this report.

Root cause

In packages/core/src/ (verified first-hand at repo HEAD cd1b45c):

  • tools/mcp-client.ts createTransport() (:2312): if MCPOAuthTokenStorage.getCredentials(serverName) returns anything, it attaches DynamicStoredOAuthProvider — with NO comparison of the stored mcpServerUrl against the current url/httpUrl anywhere in that branch.
  • mcp/oauth-token-storage.ts getCredentials(serverName) (:177): keyed by server name only, no URL parameter. saveToken() records mcpServerUrl alongside the token; nothing ever reads it back for comparison.
  • mcp/oauth-provider.ts getValidTokenWithMetadata(serverName, config) (:720): no URL parameter; returns the stored access token as-is when unexpired. The refresh path uses the STORED tokenUrl/mcpServerUrl only for the refresh call, then hands the fresh access token to the SDK, which sends it to the CURRENT URL.
  • mcp/stored-token-provider.ts tokens(): returns the stored/fresh access token; the refresh token itself is never sent to the new host — only access tokens leak.

So a stored token is bound to a server name, not to a server URL.

Reproduction (live proof, loopback only, fake token)

Build a small proof against the repo at HEAD cd1b45c, using the exported createTransport() + MCP SDK Client.connect():

  1. Store a fake OAuth token for a server named victim-server, with stored mcpServerUrl=https://real-mcp.example.com/mcp.
  2. Reconfigure the same server name to point at a local capture server (http://127.0.0.1:<ephemeral>/mcp).
  3. Connect. The capture server receives the stored token in the Authorization header on the initialize POSTs.

Verbatim output (second independent live confirmation — the same script and command shape also confirmed it in an earlier run, identical 2/2 header capture):

Found stored OAuth token for server 'victim-server'
REQUESTS_SEEN: ["POST /mcp","POST /mcp"]
AUTH_HEADER_COUNT: 2
AUTH_PREFIX: Bearer  TOKEN_MATCHES_STORED_FAKE: true TOKEN_LEN: 51
AUTH_PREFIX: Bearer  TOKEN_MATCHES_STORED_FAKE: true TOKEN_LEN: 51
RESULT: REPOINT-CONFIRMED — stored token sent to repointed URL

No real credentials were used (fake token only), no real MCP service was contacted (loopback capture server only).

Preconditions (all required)

(a) The victim already holds a stored MCP OAuth token under that server name.
(b) The attacker controls the new URL — via a trusted-workspace .gemini/settings.json repoint (cloned repo + trust click), a model write in an already-trusted folder, an extension update changing a URL, or DNS/domain takeover of the original host.
(c) The victim launches the CLI in that folder context (startup auto-connects HTTP MCP servers).

Honest limits (please read before triaging)

  • The proof is at the code-path level via exported createTransport() + MCP SDK Client.connect() — NOT a full gemini binary relaunch.
  • The token in the proof was unexpired, so the refresh leg (expired token → refresh against the stored tokenUrl → fresh access token sent to the repointed URL) was NOT executed live; its code path was re-read first-hand but not executed.
  • The refresh token is NOT sent to the new host — only access tokens leak.
  • Token scope is whatever the legitimate MCP service grants that token (service-dependent).
  • There is NO proof here that workspace settings alone can repoint without trust (workspace settings are emptied when untrusted); that gating was re-read from code, not re-tested live.
  • The vulnerable path is still present at upstream HEAD d4cb1713f (2026-11-19): the latest commit touching oauth-token-storage.ts is 2026-09-11 and the latest touching mcp-client.ts is 2026-10-20, both predating the local HEAD — no change to either file between local HEAD and upstream HEAD.

Severity

High-candidate credential theft / token replay (Medium-to-High in VRP terms, depending on the MCP service's token scope). It is NOT RCE and NOT payload-run class — no code execution is shown, and it should not be presented as such. The natural fix is to bind the stored token to its URL: compare the stored mcpServerUrl against the current URL at reconnect time and require re-consent (or re-authentication) when it differs.

Dup-screen note

Fresh searches on 2026-11-21 (this issue's filing day) in google-gemini/gemini-cli for the repoint-replay shape (mcp oauth token url repoint, mcpServerUrl, stored token repointed URL MCP) returned no matching open or closed issue. The closest results are all auth-flow-time or different defects: #15289 (OAuth resource validation at auth time), #20017 (auth-flow origin check), #18851 (auth-flow URL comparison), #18132 (consent at initial OAuth), #29081 (SSRF in OAuth metadata discovery), #29079 (MCP server command not validated), #28128 (cross-server resource URI confusion), #26785 (SSRF via unvalidated MCP server URLs), #26832 (unauthenticated MCP metadata access). None describes a stored token being sent to a changed URL without re-consent.

Dominant language
TypeScript
Stars
109k
Forks
15k
Avg merge
1d 1h
Merged PRs (30d)
106

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google-gemini/gemini-cli

All issues in google-gemini/gemini-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.