Commit ab1c585
fix(auth): the rotating 2FA verify routes echo the live user row, not the pre-rotation snapshot (#17000)
* wip(auth): #16535 user echo alignment + pins
* wip(auth): #16535 lib-target fix, changeset, client doc
* fix(auth): echo the live user row from the rotating 2FA verify routes
On the enrolment lane better-auth writes `twoFactorEnabled: true`, rotates the
session and only then calls the `valid(ctx)` closure it built at entry, so a
successful `/two-factor/verify-totp` answered `user.twoFactorEnabled: false` to
the caller who had just switched 2FA on. `two-factor-rotated-token-echo`
already repaired the body's other stale member, `token`, on exactly these
routes and on exactly this predicate; `user` is stale for the same reason and
is now repaired under the same one.
Narrowed twice: only the members the vendor already echoed are written, so the
published payload shape cannot widen; and the row is re-read through
`internalAdapter` by the id the response itself published, so the repair
travels the same output transform that produced the echo and can never
substitute a different principal. `/two-factor/verify-backup-code` does not
rotate, is in neither path list, and is pinned as a negative control on both
drive legs. A row read that throws degrades to the vendor's own echo, never to
a failed verification and never to a lost `token` repair.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012zTkyNHJ7TkuN2oXtP5x37
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8d4690b commit ab1c585
4 files changed
Lines changed: 659 additions & 23 deletions
File tree
- .changeset
- packages
- client/src
- 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1068 | 1068 | | |
1069 | 1069 | | |
1070 | 1070 | | |
1071 | | - | |
1072 | | - | |
1073 | | - | |
1074 | | - | |
1075 | | - | |
| 1071 | + | |
1076 | 1072 | | |
1077 | 1073 | | |
1078 | 1074 | | |
| |||
1160 | 1156 | | |
1161 | 1157 | | |
1162 | 1158 | | |
1163 | | - | |
1164 | | - | |
1165 | | - | |
1166 | | - | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
1167 | 1166 | | |
1168 | 1167 | | |
1169 | 1168 | | |
| |||
0 commit comments