Hi all!
First time poster. Developing my first app that uses Supabase. About 6.5 months in :)
When a user has enrolled a TOTP factor, Supabase currently still accepts aal1 JWTs for API queries. That essentially makes MFA very easy to bypass by any bad actor that has a user's password, unless you take certain cumbersome precautions. Enforcement of aal2 is only possible by manually adding (auth.jwt() ->> 'aal') = 'aal2' to every RLS policy — which is error-prone, easy to miss on new tables, and requires developers to remember to do this consistently (you could also add it as conditional so it only requires aal2 if the user has opted into TOTP).
Requested behavior:
An option (per-project or per-user) that causes PostgREST/the API gateway to automatically reject any request bearing an aal1 token if the authenticated user has one or more verified MFA factors enrolled. This would mirror how Azure AD Conditional Access works: MFA enrollment triggers automatic token-level enforcement, not just UI-layer enforcement.
Proposed implementation surface:
"Require AAL2 for MFA-enrolled users" (boolean toggle)Why this matters:
Without this, an attacker who obtains a user's password can call signInWithPassword() directly, receive a valid aal1 JWT, and query the PostgREST API with the aal1 JWT to exfiltrate data — bypassing MFA entirely. MFA provides UI-layer protection only, not data-layer protection. This is a meaningful distinction for apps storing sensitive user data.
Workaround today:
Add AND (auth.jwt() ->> 'aal') = 'aal2' to every RLS SELECT/INSERT/UPDATE/DELETE policy. This works but is fragile — any new table or missed policy is a silent vulnerability.
Could we get this feature implemented? I would LOVE this. It would make every supabase project able to be much more resilient to sophisticated penetration attacks.
The user requests a feature to automatically enforce AAL2 for MFA-enrolled users at the API gateway level. Currently, developers must manually add conditions to RLS policies, which is error-prone and can be bypassed by attackers using AAL1 tokens. The user suggests a project-level setting or a user-level metadata flag to enhance security.
You can get most of the way there today without editing every existing policy, by adding one RESTRICTIVE policy per table. Permissive policies are OR'd together, but restrictive policies are AND'd with them, so a single extra policy can gate access no matter what the other policies say:
create policy "Require aal2 for MFA-enrolled users"
on public.your_table
as restrictive
to authenticated
using (
array[(select auth.jwt()->>'aal')] <@ (
select
case
when count(id) > 0 then array['aal2']
else array['aal1', 'aal2']
end
from auth.mfa_factors
where (select auth.uid()) = user_id and status = 'verified'
)
);
This is the conditional version from the Supabase MFA docs: users with a verified factor need an aal2 token, and users without one can still use aal1. If you want to require aal2 for everyone, the body can be just (select auth.jwt()->>'aal') = 'aal2'.
Because it is a separate policy, it also does not interfere with your existing permissive policies, and you can create it for every table in a loop over pg_tables in a migration. That addresses the "easy to miss on new tables" part a bit: you can add a check in CI that lists tables in public that have no restrictive aal2 policy.
Two caveats: this only covers tables that go through RLS, so it does not protect Storage buckets (you would add the same kind of restrictive policy on storage.objects), security definer functions, or anything that uses the service role key. A gateway-level option would still be nicer, I agree.