Stored MCP OAuth token is replayed to a repointed server URL with no URL check and no re-consent
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
- Ambito
- authentication, security
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
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.tscreateTransport()(:2312): ifMCPOAuthTokenStorage.getCredentials(serverName)returns anything, it attachesDynamicStoredOAuthProvider— with NO comparison of the storedmcpServerUrlagainst the currenturl/httpUrlanywhere in that branch.mcp/oauth-token-storage.tsgetCredentials(serverName)(:177): keyed by server name only, no URL parameter.saveToken()recordsmcpServerUrlalongside the token; nothing ever reads it back for comparison.mcp/oauth-provider.tsgetValidTokenWithMetadata(serverName, config)(:720): no URL parameter; returns the stored access token as-is when unexpired. The refresh path uses the STOREDtokenUrl/mcpServerUrlonly for the refresh call, then hands the fresh access token to the SDK, which sends it to the CURRENT URL.mcp/stored-token-provider.tstokens(): 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():
- Store a fake OAuth token for a server named
victim-server, with storedmcpServerUrl=https://real-mcp.example.com/mcp. - Reconfigure the same server name to point at a local capture server (
http://127.0.0.1:<ephemeral>/mcp). - Connect. The capture server receives the stored token in the
Authorizationheader 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 SDKClient.connect()— NOT a fullgeminibinary 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 touchingoauth-token-storage.tsis 2026-09-11 and the latest touchingmcp-client.tsis 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
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google-gemini/gemini-cli
-
status/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
google-gemini/gemini-cli#30412 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
--acp never answers initialize when a sandbox is enabled (stdin read as a piped prompt before the sandbox hop)Forse già presa @Raamia l’ha presa 1 giorno fa. Apertastatus/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
google-gemini/gemini-cli#30398 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
** Docs: `/shells` slash command (and `/bashes`) is documented but was removed in #22740 — tutorial and tip tell users to run a command that doesn't existForse già presa @DZH166 l’ha presa 1 giorno fa. Apertastatus/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
google-gemini/gemini-cli#30396 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
** Docs: System Prompt Override guide links "Persisting Environment Variables" to an anchor that does not exist in authentication.mdxForse già presa @DZH166 l’ha presa 2 giorni fa. Apertastatus/need-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
google-gemini/gemini-cli#30394 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
core tests: orphan PTY slave fd test fails on Macs where /dev/ttys001 existsForse già presa @Anoshor l’ha presa 2 giorni fa. Apertastatus/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
google-gemini/gemini-cli#30384 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di google-gemini/gemini-cli
Issue simili
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaForse già presa @lijy91 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
libnativeapi/nativeapi#53 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
KilledByAPixel/LittleJS#188 ·
-
enhancement
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 88/100
stfc/goldilocks-agent#156 ·
I maintainer di solito rispondono entro 1 giorno
-
Add: BRIDGE Jazz SDApertastreams:add
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG] iOS - Share extension crashes when the shared page contains "%s" or "% s" (NSLog format string)Forse già presa @kexhest l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
achorein/expo-share-intent#244 ·