You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OAuth 2.1 server: OAuth client access tokens can call /user and /factors (modify user, enroll MFA) #2877
Access tokens issued by the OAuth 2.1 server to third-party clients (e.g. MCP connectors) are accepted by the end-user account endpoints of Supabase Auth. A delegated third-party client can therefore change the user's account data and credentials, which goes beyond what a user expects to grant when authorizing a client.
With an access token obtained through /oauth/authorize + /oauth/token (session has oauth_client_id set, token is aal1):
GET /auth/v1/user → 200
PUT /auth/v1/user with { "data": {...} } → 200, user_metadata updated
PUT /auth/v1/user with { "password": "..." } → 200 for an account without verified MFA (password changed)
POST /auth/v1/factors → 200 for an account without verified MFA (new factor enrolled)
For an account with a verified TOTP factor, the password change returns 401 insufficient_aal and factor enrollment 403 — so MFA mitigates, but only for accounts that already have it.
(The plain /auth/v1/token?grant_type=refresh_token endpoint correctly rejects the OAuth refresh token with 400 invalid_client.)
Expected
Tokens whose session belongs to an OAuth client (auth.sessions.oauth_client_id IS NOT NULL) should be rejected — or scope-limited — on the account-management endpoints (PUT /user, /factors, and email change), or there should be a project setting to restrict them. A third-party client should not be able to change the user's credentials, factors or email.
Workarounds we use
Requiring a verified TOTP factor before a user may authorize an OAuth client, "Secure email change" on, and never using user_metadata for authorization decisions. There is no hook to block these endpoints for OAuth sessions.
Related: #2838 (no way to require aal2 for OAuth client access tokens).
Reacted by 4scht, chriswhitekiwi and Bianca Vieira
I've submitted a pull request (#2878 ) addressing this issue.
What was fixed & how:
Endpoint Protection (requireNotOAuthClient):
Added middleware and handler-level checks that detect OAuth 2.1 client sessions (auth.sessions.oauth_client_id IS NOT NULL / client_id claim) and reject requests with 403 Forbidden (no_authorization).
Third-party client tokens are now blocked from modifying credentials or account state:
PUT /user (prevents changing password, email, phone, and user_metadata)
/factors/* (prevents factor enrollment, challenge, verification, unenrollment, and recovery codes)
/passkeys/* (prevents registering, updating, or deleting passkeys)
/user/oauth/grants, /oauth/authorizations/*, /reauthenticate, and /logout
Scope-Limiting GET /auth/v1/user:
For applications using @supabase/supabase-js with OAuth tokens (getUser()), responses are now sanitized according to granted scopes (email, phone, profile).
Internal security metadata (app_metadata, identities, factors) is always stripped.
Tests:
Added unit test suites verifying route rejection, handler guards, scope filtering, and OAuth server authorization isolation.
Future Scope & Extensibility:
Granular OAuth Scopes: If Supabase later wants to allow third-party clients to update user metadata or profiles via OAuth consent, a dedicated scope (e.g. user:metadata:write) can be introduced into models.IsSupportedScope() and scoped strictly to user_metadata without exposing credential changes.
Thanks @cemalkilic for the explanation and for #2898, the deny-by-default approach makes sense.
While reading the merged change I noticed the route-level test (TestOAuthClientTokenRouteAccess) only covers GET /user and GET /admin/users. The other routes listed in the PR description (PUT /user, /factors, /passkeys, /user/identities, /user/oauth/grants, /oauth/authorizations/*, /reauthenticate, /logout) have no regression test.
I'd be happy to send a small test-only PR with a table-driven test covering those routes, plus a check that /oauth/userinfo still returns 200. No behavior change. Let me know if that would be useful or if you'd rather not.
Thanks @cemalkilic for the fix and the clear write-up in #2898. Deny-by-default with an explicit opt-in for /oauth/userinfo is exactly the behavior I was hoping for. I checked our MCP connector: it verifies tokens locally with getClaims (asymmetric keys) and doesn't call /user, so it works unchanged. And thanks @Denx00 for the early PR as well!
Activity
Denx00 commentedon Oct 18, 2026
Hi @antonovicsgergely and team,
I've submitted a pull request (#2878 ) addressing this issue.
What was fixed & how:
Endpoint Protection (
requireNotOAuthClient):auth.sessions.oauth_client_id IS NOT NULL/client_idclaim) and reject requests with403 Forbidden(no_authorization).PUT /user(prevents changing password, email, phone, anduser_metadata)/factors/*(prevents factor enrollment, challenge, verification, unenrollment, and recovery codes)/passkeys/*(prevents registering, updating, or deleting passkeys)/user/identities/*(prevents identity linking/unlinking)/user/oauth/grants,/oauth/authorizations/*,/reauthenticate, and/logoutScope-Limiting
GET /auth/v1/user:@supabase/supabase-jswith OAuth tokens (getUser()), responses are now sanitized according to granted scopes (email,phone,profile).app_metadata,identities,factors) is always stripped.Tests:
Future Scope & Extensibility:
user:metadata:write) can be introduced intomodels.IsSupportedScope()and scoped strictly touser_metadatawithout exposing credential changes.Feel free to review the PR and share your thoughts!
Denx00 commentedon Nov 4, 2026
Thanks @cemalkilic for the explanation and for #2898, the deny-by-default approach makes sense.
While reading the merged change I noticed the route-level test (
TestOAuthClientTokenRouteAccess) only coversGET /userandGET /admin/users. The other routes listed in the PR description (PUT /user,/factors,/passkeys,/user/identities,/user/oauth/grants,/oauth/authorizations/*,/reauthenticate,/logout) have no regression test.I'd be happy to send a small test-only PR with a table-driven test covering those routes, plus a check that
/oauth/userinfostill returns 200. No behavior change. Let me know if that would be useful or if you'd rather not.cemalkilic commentedon Nov 17, 2026
@Denx00 thank you, I guess that won't be necessary!
Closing this issue as #2898 is merged and released with v2.198.0
antonovicsgergely commentedon Nov 17, 2026
Thanks @cemalkilic for the fix and the clear write-up in #2898. Deny-by-default with an explicit opt-in for
/oauth/userinfois exactly the behavior I was hoping for. I checked our MCP connector: it verifies tokens locally withgetClaims(asymmetric keys) and doesn't call/user, so it works unchanged. And thanks @Denx00 for the early PR as well!