---
title: "Supabase MFA: require aal2 in RLS, not only in the UI"
description: "How Supabase MFA marks a session aal1 or aal2, what my local test returned for each under a restrictive RLS policy, and how to enforce it in the database."
url: "https://madsalt.tech/notes/supabase-mfa/"
author: "Denys Zaichenko"
author_url: "https://madsalt.tech/about/"
language: "en"
published: 2026-11-16
---

# Supabase MFA: require aal2 in RLS, not only in the UI

TL;DR

Supabase Auth records the strength of a session in the token: `aal1` after a password, `aal2` after a second factor such as TOTP. A login screen that asks for the code protects nothing on its own, because the Data API serves whatever the token allows. Put the requirement in RLS: on my local stack a restrictive policy returned 0 rows to the same user at `aal1` and 1 row at `aal2`. Enable at least one factor, and require `aal2` on the tables that need it.

My free [Supabase security checker](https://madsalt.tech/tools/supabase-security-check/) reports "No multi-factor method enabled" when a project has neither TOTP nor phone MFA turned on. Turning it on is half of the job. This note is about the other half.

## What do aal1 and aal2 mean in Supabase?

AAL is the authenticator assurance level. When a user signs in with a password, the access token carries `"aal": "aal1"`. After they enroll a factor and verify a code, Supabase Auth issues a new token with `"aal": "aal2"`, and the `amr` claim lists both methods. RLS can read both claims through `auth.jwt()`.

On a local Supabase stack (CLI 2.109.1, Auth v2.192.0) with TOTP enabled, a test user's token said `aal1` with `amr: password` after sign-in, and `aal2` with `amr: totp, password` after enrolling a TOTP factor and verifying a code.

## Why is the MFA screen in the app not enough?

The second-factor screen runs in the browser. The data comes from the Data API, which checks only the token and your policies. A session at `aal1` is a valid session: if no policy asks for `aal2`, a client that skips the screen and calls the API directly gets the same rows as one that entered the code.

## How do you require aal2 in RLS?

Supabase's [RLS guide](https://supabase.com/docs/guides/database/postgres/row-level-security) shows the pattern: a restrictive policy, which must pass in addition to the normal ones. I tested it on a table of private notes with one owner policy and one restrictive policy:

```sql
create policy "own notes" on public.private_notes
for select to authenticated
using ((select auth.uid()) = user_id);

create policy "needs aal2" on public.private_notes
as restrictive for select to authenticated
using ((select auth.jwt()->>'aal') = 'aal2');
```

![One user, one note, two session levels. Local Supabase, restrictive policy requiring aal2. After password sign-in: password → aal1 token → 0 rows; After TOTP verify: password + TOTP → aal2 token → 1 row.](https://madsalt.tech/charts/en/supabase-mfa.svg)

*My reproduction on a local Supabase stack, 23 October 2026.*

| Same user, own note    | Token  | Rows returned |
| ---------------------- | ------ | ------------- |
| After password sign-in | `aal1` | 0             |
| After TOTP verify      | `aal2` | 1             |

A restrictive policy is the right tool because it cannot be widened by another permissive policy someone adds later.

## What should you enable?

1. Turn on at least TOTP in the project's Auth settings; this is what the checker's rule looks for.
2. Decide which data needs `aal2`: admin tables, billing, exports, anything a stolen password should not open. Add a restrictive policy per operation there.
3. Users who enrolled a factor should be asked for it on every new session. Supabase's `mfa.getAuthenticatorAssuranceLevel()` returns the current and the next level, so the app knows when to show the code screen.
4. MFA does not replace the rest: the per-company checks of your policies still decide which rows a verified user sees. How I test those is in [how to test Supabase RLS](https://madsalt.tech/blog/how-to-test-supabase-rls/).

Supabase also limits MFA challenge and verify calls to 15 per minute per IP, per its rate limits guide. Other Auth settings that are easy to leave at their defaults are in [Supabase CAPTCHA](https://madsalt.tech/notes/supabase-captcha/) and [Supabase email confirmation off](https://madsalt.tech/notes/supabase-email-confirmation-off/).

If you want a person to go through the whole app rather than one setting, I do a [Supabase security audit](https://madsalt.tech/services/vibe-coded-app-audit/) with a keep, fix or rewrite verdict for each part.

## My similar case

Building a time tracker for an audit firm, I found 4 errors no screen showed, including a confidential client leaking through report totals and tag counts. Every access rule now lives in the database and is tested before each deploy; the full story is in the [audit firm case](https://madsalt.tech/work/audit-firm-time-tracking/).

Need two-factor sign-in done right? Write to me and we'll set it up and test it.

Need two-factor sign-in done right?

Tell me what you have now and what you need. I'll reply with the option I'd pick.

[Write to me](https://madsalt.tech/#contact)
