OAuth 2.1 server: let projects keep client tokens away from /auth/v1/user and the MFA endpoints #53132
Replies: 1 comment
|
This is a well-run experiment — the three measurements map cleanly onto the underlying design, and I want to add the mechanism behind each, because it changes what the fix looks like. Why revoking the grant leaves the Data API open for up to an hour. Supabase access tokens are stateless JWTs. PostgREST validates the signature locally against JWKS and does not do a per-request revocation lookup, so a granted access token is a bearer credential until its The part I would prioritize differently. Point 2 is the one with real blast radius. A third-party client the user approved once can enrol a TOTP factor or touch What I would ask for, in order:
For your MCP use case specifically, the interim mitigation is to keep the OAuth client for data reads/writes only and require a direct user session for anything that changes identity state — even though that hurts the flow, it is the only line you can currently draw. |
Uh oh!
There was an error while loading. Please reload this page.
We evaluated the OAuth 2.1 server (beta) as the authorization server of an MCP server, so that our users could connect an AI assistant to their data. We stopped before opening it to anyone, because of what an issued token can do on the Auth API.
The docs say that OAuth access tokens have the same access as regular session tokens, and that RLS (with the
client_idclaim) is the way to narrow them. That works for the Data API. It does not reach the Auth endpoints, and we found no setting or hook that does.What we measured (hosted project, 8 November 2026; client registered with dynamic client registration; authorization code flow with PKCE S256; the access token carried
client_id,amr=oauth_provider/authorization_codeandrole=authenticated)PUT /auth/v1/userwith the client's access token, changinguser_metadata: 200. We restored the value afterwards.POST /auth/v1/factorswith the same token, enrolling a TOTP factor: 200. A third-party client that the user approved once can therefore enroll an MFA factor on that user's account. We deleted the factor afterwards.DELETE /auth/v1/user/oauth/grants: 204). The refresh token was refused (400) andGET /auth/v1/userreturned 403, but the access token already issued still worked on the Data API (GET /rest/v1/...: 200) until it expired, one hour later at most. The docs say that revoking a grant invalidates the client's sessions at once; that holds for the Auth API, not for the Data API.We did not test password or email changes, nor MFA challenge and verify.
What would let us use the OAuth server (any one of these)
a. A project setting that keeps OAuth client tokens out of the account endpoints (
PUT /auth/v1/user,/auth/v1/factorsand the other MFA routes), or that limits them to the Data API.b. A hook that runs before a user update and before an MFA enrollment, receives the token's
client_id, and can refuse the call. The custom access token hook already receivesclient_id, but it cannot block these calls.c. For revocation: a sentence in the docs saying that issued access tokens stay valid on the Data API until they expire, and a per-client access token lifetime, so that projects can shorten that window.
Related: #50990 (no way to require
aal2for OAuth client tokens).Meanwhile our MCP server will issue its own opaque tokens and keep the Supabase session on our side. We would rather use the built-in server once its tokens can be scoped.
Environment: hosted Supabase (Pro plan), OAuth 2.1 server and dynamic client registration enabled during the test, supabase-js with auth-js 2.106.2. No project reference, token or user data in this post, on purpose.
All reactions