Skip to content

fix(oauth-server): inherit approving session's AAL in OAuth tokens - #2869

Open
rudrakshsisodia wants to merge 1 commit into
supabase:masterfrom
rudrakshsisodia:fix/oauth-inherit-consent-aal
Open

rudrakshsisodia wants to merge 1 commit into
supabase:masterfrom
rudrakshsisodia:fix/oauth-inherit-consent-aal

Conversation

@rudrakshsisodia

Copy link
Copy Markdown

Fixes #2838

Tokens issued by /oauth/token were always aal1, even when the user consented from an MFA-verified (aal2) session, so resource servers requiring aal2 could not accept any OAuth token.

Change

  • Record the approving session on oauth_authorizations.session_id (manual consent and auto-approve).
  • On code exchange, the new OAuth session copies that session's AAL, factor and AMR claims (original timestamps preserved).
  • If the approving session is gone (on delete set null), behaviour is unchanged: aal1.

Test
TestAuthCodeGrantInheritsApprovingSessionAAL: fails on master (aal1), passes with this change.

Tokens from /oauth/token were always aal1, even when consent was given
from an MFA-verified session. Record the approving session on the
authorization and copy its AAL, factor and AMR claims into the new
OAuth session.

Fixes supabase#2838
@rudrakshsisodia
rudrakshsisodia requested a review from a team as a code owner October 13, 2026 06:58
if err != nil && !models.IsNotFoundError(err) {
return apierrors.NewInternalServerError("Error finding approving session").WithInternalError(err)
}
grantParams.InheritFrom = approvingSession

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the approving session was deleted before the code exchange (user signed out, and the FK is on delete set null), this falls through with InheritFrom nil and the token gets the default AAL. So someone who consented with MFA ends up with an aal1 token. Should the exchange fail instead when SessionID was set but the session's gone?

@olenzma

olenzma commented Oct 28, 2026

Copy link
Copy Markdown

We use Supabase's OAuth 2.1 server as the authorization server for a remote MCP server, and without this every OAuth token is aal1, so we have to refuse MCP access to members who use two-step sign-in.

On the open edge case: I'd fail the code exchange when SessionID was set but the approving session is gone, rather than silently issuing aal1, a clear error beats a downgraded token.

@jhurleyai

jhurleyai commented Nov 2, 2026 •

Copy link
Copy Markdown

Thanks!

This addresses our production MCP blocker in #2838. Our consent flow already requires AAL2 before resolving or approving authorization, including auto-approval, and our MCP server rejects tokens below AAL2. Inheriting the approving session’s AAL/AMR would let us retain that enforcement.

On the missing approving-session case, we favor rejecting the code exchange rather than silently issuing AAL1.

Could the tests also cover refresh-token exchange preserving AAL2 and the inherited AMR? We’d be happy to validate the hosted rollout against our MCP flow.

@allthehatz

Copy link
Copy Markdown

+1 from Hatz AI. We use the OAuth 2.1 server for our Microsoft Excel add-in. Our consent flow already requires aal2, but the exchanged token is always aal1, so MFA users are asked for a second TOTP in the add-in. Inheriting the approving session's AAL/AMR at code exchange, as this PR does, would fix it for us. We are happy to test a release on a hosted project.

@JROtto5

JROtto5 commented Nov 11, 2026

Copy link
Copy Markdown

I ran the full OAuth flow against real builds of this PR, its base and current master. The goal was to check the fix end to end, plus the two edge cases raised above (approving session gone, and when the AAL is read).

Setup: four images built from full SHAs (each one's /health version checked): base ce9a8eee, this PR ee1adb71, master 1357a5b9, and master with this PR merged (91d11dbb, merges cleanly). Each run used fresh Postgres 15, GOTRUE_OAUTH_SERVER_ENABLED=true and TOTP. A stdlib Python client signs users up and steps them up to aal2 through /factors enroll/challenge/verify. It then registers a confidential client, runs /oauth/authorize → GET /oauth/authorizations/{id} → consent → /oauth/token (PKCE) and decodes aal/amr from the issued access token. Each row ran 3 times with new users and clients, and all 3 runs matched.

case base / master PR / master + PR
consent from an aal2 session (password + TOTP) aal1, amr oauth aal2, amr oauth, password, totp
refresh of that OAuth token aal1 aal2, same amr
second authorization, auto-approved (existing consent) aal1 aal2
control: user without MFA consents (aal1) aal1, amr oauth aal1, amr oauth, password
approving session signs out (/logout?scope=local) before the code exchange aal1 aal1, amr oauth
consent from aal1, then the same session steps up to aal2 before the exchange aal1 aal2, amr oauth, password, totp

oauth = oauth_provider/authorization_code. On a database migrated by master first (newest migration 20261030120000), the master + PR image still applies 20261013000000 (session_id column present) and gives the same results as a fresh database.

Behaviour changes, beyond the fix itself:

  • The OAuth token's amr now includes the approver's methods even at aal1 (password in the control row).
  • The AAL is read from the approving session when the code is exchanged, not when consent is given (last row). If the session steps up between consent and exchange, the token is aal2 even though consent was given at aal1.
  • When the approving session is gone, the exchange still succeeds and silently issues aal1. That is the case notlakshitha and olenzma asked about; the PR doesn't change it into an error.

Not tested: WebAuthn/phone factors, SSO/SAML amr, the custom access token hook, OrioleDB, or the Go test suite (including the new TestAuthCodeGrantInheritsApprovingSessionAAL).

@wiley-sayvant

Copy link
Copy Markdown

Any updates on this? We are currently gated on adopting supabase fully for oauth

@holm

holm commented Nov 18, 2026

Copy link
Copy Markdown

This also broke our MCP flows, so it would be very nice to get this fixed as soon as possible

This branch has not been deployed

No deployments
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.

OAuth 2.1 server: no way to require MFA (aal2) for OAuth client access tokens

8 participants