Repository navigation
fix(mcp): keep the refresh token stable for Google Connected Apps MCP OAuth clients - #260
Open
agent-relay-code[bot] wants to merge 2 commits into
Conversation
… OAuth clients Google's connector keeps the refresh token it first received and expects every refresh to return that same token. Rotation left it presenting a retired token on the next refresh, which ended the connection. For a client whose every redirect URI is a Google Connected Apps callback, refresh now returns the presented refresh token, extends its expiry and issues each new access token as a child session linked to the root session (migration 0085, parent_session_id). Earlier access tokens stay valid until their own expiry; expired children are deleted on the next refresh and a child's own refresh token is never accepted. Revoking the refresh token or the grant ends the root and its children. Continuation detection counts root sessions only, and a replayed continuation code revokes its session together with its children. All other clients keep rotation. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Google's Gemini connector keeps the refresh token it first received and expects every refresh to return that same token (Google's requirement). This server rotated the refresh token on every refresh, so the connector's next refresh presented a retired token and the connection ended.
For an MCP OAuth client whose every registered redirect URI is a Google Connected Apps callback, refresh now:
All other clients keep rotation unchanged.
Stacked on #259 (base
fix/mcp-oauth-lost-refresh-response). Land #259 first, then retarget this tomain.Decision for the owner
This is a weaker bearer lifecycle for one client class: a stolen refresh token for a Google callback client is not detected by reuse, because reuse is the normal case. It is limited to clients whose whole redirect set is one of three Google hosts (
oauth-redirect,oauth-redirect-sandbox,oauth-redirect-testongoogleusercontent.com) with a single/r/<id>or/a/<id>path. Revocation, grant revocation, membership loss and the 30-day idle expiry still end the connection.Behaviour changes
mcp_oauth_sessions.parent_session_id(self-reference,ON DELETE CASCADE) and a child-only partial index. Existing rows keepNULLand are root sessions.child_session).extended.Concurrency
Refresh and code redemption (including replay) both take the per-user and per-organisation advisory transaction locks before reading, so a refresh that is adding a child cannot interleave with a replay that revokes the family. No separate family lock is added. The stable refresh itself is one guarded
UPDATEon the root row; a refresh that loses to a revoke is refused.Upgrade notes
Not changed
Originguard on the OAuth endpoints is not relaxed.token_endpoint_auth_methodother thannoneand over-long or reserved client names. If Gemini registers with another auth method this would make it ask for a client ID and secret; no captured registration request exists to confirm that, so it is left for a follow-up.Checks
Local, on this head, one at a time:
tsc --noEmit: passmcp-oauth-token-flow: 46/46 (ten new stable-refresh tests)migrations: 11/11Run before the last two edits (a test-only clock change and the index predicate), source unchanged since:
mcp-oauth-protocol20/20,mcp-oauth-sessions10 pass + 1 skip,mcp-oauth-store11/11,mcp-oauth-admission57/57,mcp-oauth-http16/16,mcp-oauth-public-handlers5/5,mcp-oauth-departure4/4,mcp-oauth-oidc6/6,grok-routines21/21,mcp61/61.Not covered by tests: two stable refreshes racing in separate connections, single-tenancy mode on the stable path, and the rolling-upgrade case.
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by cubic
Stops rotating refresh tokens for MCP OAuth clients whose every registered redirect URI is a Google Connected Apps callback; Google's connector expects the same refresh token back on every refresh, and rotation made it present a retired token on the next refresh, ending the connection. For those clients, refresh returns the presented refresh token, extends its expiry to 30 days after that refresh, and issues the new access token as a child session row linked to the root session, so earlier access tokens stay valid until their own one-hour expiry. All other clients keep rotation.
Behavior changes
mcp_oauth_sessions.parent_session_id(self-reference,ON DELETE CASCADE) and a child-only partial index; existing rows stay NULL as root sessions.extended.Upgrade notes
Written for commit e940e35. Summary will update on new commits.