Skip to content

fix(mfa): remove recovery codes with last factor to avoid lockout - #2974

Closed
fadymak wants to merge 1 commit into
masterfrom
fm/recovery-codes-removed-with-last-factor
Closed

fadymak wants to merge 1 commit into
masterfrom
fm/recovery-codes-removed-with-last-factor

Conversation

@fadymak

@fadymak fadymak commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Unenrolling a user's last usable second factor now removes their recovery codes in the same transaction instead of failing with mfa_recovery_codes_sole_factor. Previously a user who signed in with a recovery code had to delete the codes first, which downgraded their session to AAL1 and left them unable to remove the factor they had lost.

  • DELETE /factors/{factorId} deletes the recovery-code factor, audits it and downgrades its sessions when no other usable second factor remains
  • DELETE /factors/recovery-codes is kept for existing clients and marked deprecated in the OpenAPI spec

Comment on lines 1233 to +1234
// A verified phone factor does not count while phone verification is disabled,
// so the TOTP factor is still the last usable second factor.
// so the TOTP factor is still the last usable second factor and takes the codes with it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, wouldn't that mean the user becomes stuck in aal1 and can't enroll a new MFA factor without intervention? Auth counts the verified phone as a factor, but since phone verification is disabled and recovery codes were removed together with TOTP, they can't get to aal2 to enroll a new factor.

Comment thread openapi.yaml Resolved
Comment thread internal/api/mfa.go Resolved
@fadymak fadymak closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants