Repository navigation
Conversation
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.
Fixes #2877
Summary of Fix
Delegated third-party OAuth 2.1 client tokens (such as MCP connectors) should only have authorization according to their consented scopes and should not possess account-management privileges. I have addressed Issue #2877 by restricting OAuth client access tokens from modifying credentials, factors, or account state, while scope-limiting user profile reads.
Changes Made
OAuth Client Detection (
Session.IsOAuth()):s.IsOAuth()on*models.Sessionto check ifsession.OAuthClientIDis set.isOAuthClientRequest(ctx)ininternal/api/auth.gochecking both JWT claims (client_id) and session data.Route Middleware (
requireNotOAuthClient):403 Forbidden(no_authorization).internal/api/api.go:PUT /user/factors/*(enrollment, challenge, verify, unenroll, recovery codes)/passkeys/*(registration options & verify, delete, patch)/user/identities/*(link, unlink)/user/oauth/grants(grant management)/oauth/authorizations/*(authorization view and consent)/reauthenticate/logoutDefense-in-Depth Handler Checks:
UserUpdate,EnrollFactor,requirePasskeyManagementAAL,DeleteIdentity,LinkIdentity,Reauthenticate,Logout,OAuthServerConsent,UserListOAuthGrants,UserRevokeOAuthGrant).Scope-Limiting on
GET /auth/v1/user:@supabase/supabase-jswith OAuth tokens (getUser()),GET /auth/v1/usernow runs throughsanitizeUserForOAuth():app_metadata,identities,factors) are always stripped.email,phone, anduser_metadataare only included if the respective scopes (email,phone,profile) were explicitly consented.Unit Tests:
internal/api/oauth_client_restriction_test.goandinternal/api/oauthserver/oauth_client_restriction_test.goverifying that OAuth client tokens are blocked from account modification and correctly scope-limited onGET /user.