Skip to content

OAuth 2.1 server: OAuth client access tokens can call /user and /factors (modify user, enroll MFA) #2877

Closed

Description

@antonovicsgergely

Summary

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.

Observed (hosted project, OAuth 2.1 server enabled, dynamic client registration on)

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).

Activity

  1. Denx00 commented on Oct 18, 2026

    @Denx00

    Hi @antonovicsgergely and team,

    I've submitted a pull request (#2878 ) addressing this issue.

    What was fixed & how:

    1. 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/identities/* (prevents identity linking/unlinking)
        • /user/oauth/grants, /oauth/authorizations/*, /reauthenticate, and /logout
    2. 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.
    3. Tests:

      • Added unit test suites verifying route rejection, handler guards, scope filtering, and OAuth server authorization isolation.

    Future Scope & Extensibility:

    Feel free to review the PR and share your thoughts!

  2. Denx00 commented on Nov 4, 2026

    @Denx00

    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.

  3. cemalkilic commented on Nov 17, 2026

    @cemalkilic
    Contributor

    @Denx00 thank you, I guess that won't be necessary!

    Closing this issue as #2898 is merged and released with v2.198.0

  4. antonovicsgergely commented on Nov 17, 2026

    @antonovicsgergely
    Author

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions