test(supabase): GoTrue MFA behaviour proven on the sandbox (V1-2.5 A)

Ten cases on the pinned GoTrue: aal1 cannot enrol a second factor or remove a verified one (no STOP); removal downgrades only the sessions verified with that factor; password change and reset need aal2 once a factor is verified. Findings in IDENTITY.md §4.1.
This commit is contained in:
bchanot committed 2026-11-02 16:19:47 +01:00
1 parent a701b04210
commit 78791bfb6b
3 files changed
+289 -1

No files matched your search

+36
View File
@@ -99,6 +99,42 @@ into the policies of the first admin table) with pgTAP allowed/denied cases;
enrolment + challenge screens in Mon compte; step-up at sign-in for accounts
holding a platform role.
### 4.1 GoTrue v2.197.0 behaviour, measured on the sandbox (V1-2.5)
`packages/supabase/tests/sandbox/mfa-behaviour.sandbox.ts` (real GoTrue, run by
`pnpm db:sandbox test`) asserts what the pinned image does; V1-2 contract §5.6,
§5.7.1, §5.7.3, §5.7.4. None of it is assumed elsewhere.
- First factor: enrolled from `aal1`, stored `unverified`; until verified a new
sign-in stays `aal1`.
- Verify: challenge and verify upgrade the same session (same `session_id`) to
`aal2`, `amr` password + totp, and delete the account's other `aal1`
sessions. GoTrue refuses their tokens at once; PostgREST keeps accepting
their access token until it expires.
- Second factor from `aal1`: 403 `insufficient_aal`; from `aal2`: allowed.
- Removing a verified factor from `aal1`: 422 `insufficient_aal`; an
unverified one: allowed. The STOP condition of §5.6 did not fire.
- Removing a verified factor from `aal2`: only the sessions last verified with
that factor drop to `aal1`. Their access token keeps its `aal2` claim until it
expires: `has_mfa()` stays true for it, `has_aal2_session()` turns false, so
the role and rights RPCs refuse it at once. Their next refresh is `aal1`.
- Dormant unverified factor: one left before any verification is deleted when
another factor is verified. One enrolled from `aal2` after verification is
kept and can later be verified from a password-only session, reaching
`aal2`. Planting it needs an `aal2` session and its secret (shown once), so it
stays within the stolen-session residual (§5.7.8). Factor lists show
unverified factors.
- Password change or reset with a verified factor: refused at `aal1` (401
`insufficient_aal`), including from a recovery-link session (`amr` otp). From
`aal2` it succeeds, keeps that session and deletes the account's others. The
recovery screens and the §5.7.7 runbook must reach `aal2` first. Without a
factor, `aal1` changes the password and stays `aal1`.
- Refresh keeps `aal2`; a new password sign-in starts at `aal1`.
- Email change: refused at `aal1`; from `aal2` the confirmation link opens a
new `aal1` session. Identity linking: 404 `manual_linking_disabled`.
- A TOTP code accepted twice within its 30 s window by two sessions of one
factor (observed, not asserted).
## 5. Manual validation (local stack)
```bash