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

Aperta
#30,391 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
109k
Fork
15k
Merge medio
1g 1h
PR unite (30g)
106

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google-gemini/gemini-cli

Tutte le issue di google-gemini/gemini-cli

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.