Skip to content

fix: restrict OAuth client access tokens to OAuth endpoints - #2898

Merged
cemalkilic merged 1 commit into
masterfrom
cemal/scope-oauth-tokens-to-oauth-endpoint
Nov 3, 2026
Merged

cemalkilic merged 1 commit into
masterfrom
cemal/scope-oauth-tokens-to-oauth-endpoint

Conversation

@cemalkilic

Copy link
Copy Markdown
Contributor

What

Access tokens issued by the OAuth 2.1 server (sessions with oauth_client_id set) are now only accepted on endpoints intended for OAuth clients. Today that's only GET /oauth/userinfo.

  • requireAuthentication rejects OAuth client tokens with 403 no_authorization. Every route that uses it is covered by default, including new routes added later.
  • New requireAuthenticationAllowOAuthClient is the explicit opt-in, used only by /oauth/userinfo.
  • requireAdminCredentials also rejects OAuth client tokens. This covers /admin/*, /invite and the admin captcha bypass, even if the user's role is in JWT.AdminRoles.
  • The check uses session.oauth_client_id from the DB rather than the client_id claim, because a custom access token hook can rewrite claims.

Behavior change

This only affects access tokens issued to OAuth clients. Regular user sessions are unchanged.

OAuth client access tokens were previously accepted on the end-user account endpoints. They now get 403 no_authorization on:

  • GET /user and PUT /user
  • /factors/*
  • /passkeys/*
  • /user/identities/*
  • /user/oauth/grants
  • /oauth/authorizations/*
  • /reauthenticate
  • /logout
  • /admin/*, /invite

Migration for OAuth clients: clients that read the user with an OAuth access token (e.g. GET /user / supabase.auth.getUser()) should use GET /oauth/userinfo instead. It returns claims based on the granted scopes:

  • sub, always
  • email, email_verified with the email scope
  • name, picture, preferred_username with the profile scope
  • phone claims with the phone scope

app_metadata, the full user_metadata, identities and factors are no longer available to OAuth clients. This is intentional: they go beyond what the user consented to.

@cemalkilic
cemalkilic requested a review from a team as a code owner November 3, 2026 16:15
Comment thread internal/api/auth.go Resolved
Access tokens issued by the OAuth 2.1 server are now only accepted on
endpoints intended for OAuth clients (/oauth/userinfo). Other
authenticated endpoints and admin endpoints return 403 for these tokens.

OAuth clients should use /oauth/userinfo to read user information
instead of GET /user.
@cemalkilic
cemalkilic force-pushed the cemal/scope-oauth-tokens-to-oauth-endpoint branch from e642e6d to 4a54228 Compare November 3, 2026 16:39
Comment thread internal/api/middleware.go Resolved
@cemalkilic
cemalkilic merged commit 384d83a into master Nov 3, 2026
13 checks passed
@cemalkilic
cemalkilic deleted the cemal/scope-oauth-tokens-to-oauth-endpoint branch November 3, 2026 17:11
cstockton pushed a commit that referenced this pull request Nov 13, 2026
…locked (#2926)

## What

#2898 restricted OAuth client access tokens to OAuth endpoints. That
also blocked `GET /user`, which breaks existing projects that read the
user with these tokens (e.g. `supabase.auth.getUser()`).

This PR **temporarily** allows OAuth client access tokens on `GET /user`
only. All modifying actions still reject them with `403
no_authorization`:

- `PUT /user`
- `/user/identities/*`, `/user/oauth/grants`
- `/factors/*`, `/passkeys/*`
- `/logout`, `/reauthenticate`
- `/admin/*`, `/invite`

## How

The `/user` group used to apply `requireAuthentication` to every route
in it. Now each route sets its own middleware: `GET /user` uses
`requireAuthenticationAllowOAuthClient`, and every other `/user` route
keeps `requireAuthentication`. A comment on the route group says that
new `/user` routes must add `requireAuthentication`.

## Note: this is temporary

`GET /user` returns `app_metadata`, the full `user_metadata`, identities
and factors. That is more than the scopes an OAuth client is granted. We
are reopening it for now so existing projects don't break. We will
revisit this soon and reject OAuth client tokens on `/user` entirely.
OAuth clients should move to `GET /oauth/userinfo`.

## Tests

`TestOAuthClientTokenRouteAccess` now covers:

- `GET /user` and `/oauth/userinfo` return 200 with an OAuth client
token.
- The modifying endpoints above return 403 with an OAuth client token.
- A rejected `PUT /user` leaves the user unchanged.
artex-x added a commit to artex-x/daggerheart-loot that referenced this pull request Nov 14, 2026
…e database

A reader can now allow an app or AI assistant on the consent page
/connect/<id> and see and disconnect it in «Подключённые приложения» on
the account page. A connected app's token works at PostgREST directly, so
the migration 20261113120000_api_client_guard bounds it there: a
pre-request guard refuses every table and function outside the account
API's list and a token whose session a revoke ended, and restrictive
policies cover user_prefs, print_sets and Storage updates and deletes.
The app's own token and anon are unchanged.

supabase/config.toml now owns [auth.oauth_server], so config:push is the
switch. Production stays off until Supabase's fix (supabase/auth#2898) is
deployed and probes P1-P4 pass on the hosted project; the consent and
privacy texts state what is true with that fix.

Task: ai-mcp (B5a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants