Skip to content

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

Open

Description

@jhurleyai

Problem. Tokens issued by the OAuth 2.1 server always carry aal: "aal1" and amr: [{"method":"oauth_provider/authorization_code"}]. The OAuth session is created fresh at AAL1 (/oauth/token → IssueRefreshToken → models.NewSession), and the consenting session's AAL is never considered. The consent endpoints (GET /oauth/authorizations/{id}, POST …/consent) only require authentication, not a particular AAL, and the GET auto-approves a previously consented client. So a resource server that requires aal2 (e.g. an MCP server fronting sensitive data in a project that enforces TOTP for its users) cannot accept any OAuth token, and has no supported way to know that consent was given from an MFA-verified session.

Request (any of):

  1. Stamp the OAuth session with the consenting session's AAL/AMR (e.g. aal2, amr including totp), as suggested as an alternative fix in OAuth 2.1 server: MFA verification deletes OAuth client sessions (InvalidateSessionsWithAALLessThan does not exclude oauth_client_id) #2801.
  2. An OAuth server setting to require aal2 on the consenting session for the authorize/consent endpoints, including the auto-approve path.
  3. At minimum, pass the authorization/consent context (authorization id, or the consenting session's AAL) into the Custom Access Token Hook input, so projects can implement this themselves without relying on internal tables.

Related: #2801 (MFA verification deletes OAuth client sessions). Together these make MFA-enforced projects unable to use the OAuth 2.1 server for MCP clients.

Activity

  1. added
    bug
    on Sep 28, 2026
  2. RidderH commented on Nov 12, 2026

    @RidderH

    We hit this in production: an MCP server behind the OAuth 2.1 server, in a project that enforces TOTP with a restrictive RLS policy on aal. It is reproducible on v2.197.0.

    What we saw

    • A user who holds a verified TOTP factor and consents from an aal2 session gets an access token with aal: "aal1".
    • The session created at the token exchange is a new auth.sessions row at aal1, with no factor recorded and no link back to the consenting session.
    • So the resource server cannot tell "consented with the second factor" from "consented with a stolen password". GET /oauth/authorizations/{id} and POST …/consent both accept an aal1 JWT, and the GET auto-approves a previously consented client.
    • Trusting client_id does not help either, for the same reason: a password-only attacker can mint a client_id token without ever reaching the app's consent page.

    What we did meanwhile

    Our consent page writes a proof row through the service role, keyed on authorization id and user, after GoTrue returns success to an aal2 session. An AFTER INSERT trigger on auth.sessions (oauth_client_id IS NOT NULL) binds the new session to that proof. It binds only when exactly one approved, unexpired authorization for that user and client exists and carries a proof. This works because handleAuthorizationCodeGrant issues the session before destroying the authorization, in one transaction.

    It works, but it depends on two internals we would rather not depend on: that ordering, and the shape of auth.oauth_authorizations.

    What would let us delete it, in order of preference:

    1. Carry the consenting session's aal and amr into the OAuth session at the exchange (option 1 in this issue).
    2. Pass the authorization id, or the consenting session's aal, into the Custom Access Token Hook input (option 3), so projects can decide this in a supported way.
    3. A setting that requires aal2 on the authorize and consent endpoints, including the auto-approve path (option 2). It would close the hole, but it does not give the token an aal2 claim, so RLS would still need a workaround.

    Thanks for #2801 and #2898. The first stops MFA verification from deleting OAuth sessions. The second will need a change on our side, which we have already made: identity now comes from /oauth/userinfo.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions