Commit 45204a5
fix(plugin-auth): 2FA re-enrollment must not inherit
* fix(plugin-auth): 2FA re-enrollment must not inherit `verified` from the previous enrollment
better-auth's `/two-factor/enable` writes `verified: existingTwoFactor?.verified
=== true` alongside a freshly generated secret, and `sys_two_factor` declares
`user_id` unique — so re-enrolling rewrote the account's one row with a secret
nobody had confirmed while carrying the prior enrollment's flag over. The flag
stopped describing the stored secret, and the sign-in challenge honoured the
replacement immediately.
The vendor already gates that challenge on the flag (`TOTP_NOT_ENABLED` in
`totp/index.mjs`, and `twoFactorMethods` in the post-sign-in hook) — it is what
makes a first enrollment inert until confirmed. Re-enrollment slipped past it
only because the value handed to the gate was inherited, so this restores the
flag instead of adding a second owner of the same decision.
Tightening only: same body, same response shape, same status; first-time
enrollment unaffected; rotation still reachable, now via the same confirmation
step a first enrollment takes.
Part of #10700
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PnJHU45vPJj5UQrxe946Bx
* docs(auth): state that `/two-factor/enable` re-enrollment needs the same confirmation step
The 2FA section already listed TOTP confirmation as part of a complete opt-in
UX, but said nothing about what a SECOND `enable` does to an account that is
already enrolled. Now it does: the replacement secret is unconfirmed, the
sign-in challenge refuses it (`400 TOTP_NOT_ENABLED`) and omits `totp` from
`twoFactorMethods` until the session-lane verify succeeds, the replaced secret
stops working when `enable` returns, and the backup codes in that same response
are the recovery path.
Part of #10700
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PnJHU45vPJj5UQrxe946Bx
---------
Co-authored-by: Claude <noreply@anthropic.com>verified from the previous enrollment (#10994)1 parent cdaa72f commit 45204a5
5 files changed
Lines changed: 654 additions & 0 deletions
File tree
- .changeset
- content/docs/permissions
- packages/plugins/plugin-auth/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
606 | 618 | | |
607 | 619 | | |
608 | 620 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
1716 | 1717 | | |
1717 | 1718 | | |
1718 | 1719 | | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
1719 | 1732 | | |
1720 | 1733 | | |
1721 | 1734 | | |
| |||
0 commit comments