gloss

Claude Code Followed MCP Redirects With Your Refresh Token

Claude Code 2.1.321, released 9 November, stops MCP OAuth requests from following a redirect to another host.

A silver key protrudes from an open brown padded envelope on a worn workbench, with a tape dispenser and stacked envelopes behind it.
  • Claude Code 2.1.321, released 9 November, has a one-line fix: MCP OAuth requests no longer send secrets "such as refresh tokens" to another host when a server redirects them. I ran 2.1.319 against a fake MCP server on my laptop to see what that meant. When the token endpoint answered with a 307, the second host received the authorization code, the PKCE verifier and, on the next refresh, the refresh token.
  • The Authorization header never made the trip. The HTTP client already drops it on a cross-host redirect. OAuth keeps its secrets in the form body, and a 307 or 308 replays the body untouched. 2.1.319 also accepted whatever tokens the second host sent back and printed "Authenticated".
  • 2.1.321 and 2.1.322 stop the request and name both hosts in the error. Same-host redirects still work. Two things to know: a legitimate server whose token endpoint hops to another domain now fails to log in, and redirects on the MCP endpoint itself are still followed, without the bearer token but with the request body.

The changelog for 2.1.321 opens with Fable 5.2. The third bullet is this: "Fixed MCP OAuth requests sending secrets such as refresh tokens to another host when a server redirected them." No advisory, no CVE number that I could find, no detail on which requests or which redirects.

I had 2.1.319, 2.1.321 and 2.1.322 on disk, so I tested it.

The setup

Two small Python servers, both on loopback. Server A, on 127.0.0.1:48711, plays a remote MCP server with its own OAuth: discovery metadata, dynamic client registration, an authorize endpoint, a token endpoint, and a minimal MCP endpoint behind a bearer check. Server B, on localhost:48722, is the other host. It logs whatever arrives and answers token requests with tokens of its own.

Every token is a fake string like FAKE-REFRESH-2, and each run used a throwaway config directory. I drove the real CLI: claude mcp add --transport http, then claude mcp login --no-browser through a pseudo-terminal, then claude mcp get to force a reconnect after the one-second access token had expired.

That made 18 scripted runs across the three versions. Apart from one baseline with no redirect, each run had A answer one endpoint with a redirect.

What 2.1.319 sent

With the token endpoint returning 307 to B during login, B logged this body:

grant_type=authorization_code&code=FAKE-AUTH-CODE&code_verifier=7Ssd1ycMKzfy...&redirect_uri=http%3A%2F%2Flocalhost%3A55424%2Fcallback

That is the one-time code plus the PKCE verifier. PKCE exists so that a stolen code is useless without the verifier, and here they travel in the same request. B answered with its own access and refresh tokens. The CLI printed Authenticated with "probe". Its tools are now available in Claude Code.

With the redirect on the refresh path instead, login went to A as normal. On the next reconnect B logged:

grant_type=refresh_token&refresh_token=FAKE-REFRESH-2&resource=http%3A%2F%2F127.0.0.1%3A48711%2Fmcp

claude mcp get showed Status: Connected. Nothing on screen suggested the refresh had been answered by a different machine.

A refresh token is the long-lived one. Whoever holds it can keep minting access tokens until someone revokes it, and on a remote MCP server those tokens are your account on Sentry, Linear, Notion, or whatever sits behind it.

The header was protected, the body wasn't

Claude Code sent the client ID and secret to A as a Basic Authorization header. At B, that header was gone, on every run. The same happened to the bearer token on MCP requests. That is standard behaviour for a fetch-style HTTP client: cross-host redirect, credentials header removed.

The body gets no such treatment. A 307 or 308 means "repeat this exact request over there", so the form body goes along. OAuth's token endpoint takes the code, the verifier and the refresh token as form fields. In my setup the client secret happened to ride in the header; a server that asks for client_secret_post puts that in the body too, though I didn't test that variant.

The status code decides it. With a 302 or 303, the POST turned into a GET and B received an empty request. With 307 or 308, B got everything. Pointing the redirect at a different port on the same IP made no difference on 2.1.319. B still got the body.

The registration request followed the redirect as well. It carries no secret, but B got to answer it, which means B picked the client ID.

What 2.1.321 does

Same servers, same redirects, 2.1.321 and 2.1.322. B's log stayed empty for every OAuth request. Login failed with:

Couldn't complete authentication for "probe": Stopped an OAuth request, which can hold secrets: http://127.0.0.1:48711 redirected it to http://localhost:48722. Ask the owner of http://127.0.0.1:48711 to remove that redirect.

That string appears in the 2.1.321 and 2.1.322 binaries and not in 2.1.319.

The refresh case is quieter. claude mcp get prints no error at all, only Status: ! Needs authentication. If you see a remote server drop to that state after updating, a redirect on its token endpoint is one thing to check.

The check is about the host, not about redirects in general. When A redirected /token to /moved/token on the same host and port, 2.1.322 followed it, kept the Authorization header, and logged in fine.

Two things the fix leaves alone

First, legitimate servers. If an auth server answers its token endpoint with a hop from example.com to auth.example.com, or to a new domain after a migration, users on 2.1.321 and later can't log in until the metadata advertises the final URL. That is the right trade. It will still show up as "your MCP server broke".

Second, the MCP endpoint itself. I redirected /mcp on A to B and ran it on both 2.1.319 and 2.1.322. The result was identical: the bearer token was stripped, but the initialize and tools/list bodies arrived at B, B's answers were accepted, and the status read Connected. So on the current version, a redirect can still hand the conversation to another host, and that host gets to serve the tool list. I only ran the reconnect handshake through it, not a tool call, but a tool call is the same POST.

That is a smaller problem than a leaked refresh token, since the other host gets no credentials. It is still worth knowing that "connected" does not tell you which host answered.

Who can trigger this

The server you connected to already sees your tokens, so a redirect only matters when it sends them to someone who shouldn't have them. The cases I can think of: an open redirect or a compromised proxy in front of an identity provider, an expired domain still listed in old metadata, or a server that advertises a trusted token endpoint to pass an issuer check and then bounces the request elsewhere. I have no evidence any of these was used against Claude Code. The changelog doesn't say how the bug was found.

What I'd do this week

  1. Run claude --version. Anything below 2.1.321 follows these redirects. Update.
  2. If you run a remote MCP server, POST to your token and registration endpoints with curl -i and look for a 3xx. Advertise the final URL in your metadata instead.
  3. If a server you use did redirect its token endpoint while you were on an older version, revoke that grant on the provider's side, then claude mcp logout <name> and log in again.
  4. Test your other MCP clients the same way. Following a 307 with the body is the default in most HTTP libraries, and I only tested Claude Code.

The harness is one Python file and every run stayed on loopback. One changelog bullet turned into a before and after I could read in a server log, which is more than the bullet itself gives you.