Repository navigation
feat(auth): verify an MFA recovery code to reach aal2 - #627
Merged
Merged
Conversation
Tr00d
force-pushed
the
feat/auth.mfa_recovery_codes.verify
branch
from
November 2, 2026 12:34
c7eec4e to
d336d05
Compare
Tr00d
marked this pull request as ready for review
November 2, 2026 12:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A signed-in user can redeem one of their single-use MFA recovery codes to upgrade the session to
aal2, for example after losing their authenticator app.Capability:
auth.mfa_recovery_codes.verify: MFA Recovery Codes Verify. No capability spec exists; the contract is the auth OpenAPI (POST /factors/recovery-codes/verify).Public API
New types: none.
Behavior
Operation:
POST /factors/recovery-codes/verifywith body{"code":"..."}, the session's access token as Bearer, and theapikeyheader.Inputs:
codeis required and sent exactly as typed. The server ignores letter case, whitespace and-.Output: the 200
AccessTokenResponsedeserializes into aSession, which is returned.State on success:
CurrentSessionand is persisted.UserUpdatedand thenMfaChallengeVerified, the same sequence as the TOTPVerify.aal1sessions.Failures before the wire:
ArgumentException(ParamName = "code") when the code is null, empty or whitespace.GotrueExceptionwith ReasonOfflinewhen the client is offline.GotrueExceptionwith ReasonNoSessionFoundwhen there is no session or access token.No request is sent in any of these cases.
Failures from the server or response. The current session is kept on every failure.
ErrorCodeaccess_tokenMfaChallengeUnverifiedMfaChallengeUnverifiedmfa_verification_failedMfaChallengeUnverifiedmfa_verification_rejectedUserTooManyRequestsmfa_recovery_codes_lockedUserTooManyRequestsover_request_rate_limitmfa_recovery_codes_verify_not_enabledno_authorizationThese reasons come from the existing mappings; no new
FailureHint.Reasonvalues are added.Cancellation: the
CancellationTokenreaches the HTTP call. It is not passed to the local store and announce steps, which run only after the server has consumed the code. This matches the TOTPVerify.Instrumentation: the
gotrue.verify_recovery_codedomain span parents the HTTP span.Deviations from supabase-js
experimental.recoveryCodesopt-in flag, consistent with the shipped recovery codes methods.UserUpdatedthenMfaChallengeVerified, matching the C#Verify. supabase-js emits onlyMFA_CHALLENGE_VERIFIED.ArgumentExceptionbefore the wire. supabase-js sends it and getsvalidation_failed.{ data, error }.Tests
VerifyRecoveryCodeTestsmfa_recovery_codes_verify_not_enabledfor a signed-up user,no_authorizationfor an anonymous userVerifyRecoveryCodeContractTestsUserUpdatedthenMfaChallengeVerified; empty 200 and session without access token;mfa_verification_failed,mfa_verification_rejected(session kept),mfa_recovery_codes_locked,verify_not_enabled; missing code; no session; offline; cancellation; no context capture, including with a synchronous transport and a session store that saves asynchronouslyVerifyRecoveryCodeApprovalTests{"code":"K4M9-X7QP-2AB8-HT3Z"}ObservabilityContractTestsPOST /factors/recovery-codes/verifyChanged-line coverage: 100% (22 lines). Mutation: 22/22 on changed lines (21 killed, 1 timeout), 0 survivors.
Notes
GOTRUE_MFA_RECOVERY_CODES_VERIFY_ENABLEDoff by default, and the Supabase CLI exposes noconfig.tomlkey for it. A successful verification is therefore pinned by contract tests only.ConfigureAwait(false)mutants after the request. Over a real HTTP call those mutants are unobservable, because the continuation has already left the caller's context.