DeepSeek V4.1 Flash · Heavy
feat-2fa-backup-codes-cal-com
cal.com · TypeScript · M · 100–299 lines · 6 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.
- Gold bugs found
- 1 of 1
- Comments published
- 8
- Comments matching a bug
- 1
- Comments not matching
- 7
- Cost of this PR
- $0.320
Published comments (8)
Backup code login bypasses password when totpCode is present — Anyone with a leaked backup code and the account email gets a session without the password, since the `!credentials.totpCode` gate skips password verification in this branch. Verify `credentials.password` inside the backup-code branch, or drop that gate when `backupCode` is present.
Modal dismissal leaves stale backup-code step and cleared codes — Escape or an overlay click leaves `step` at `DisplayBackupCodes` with codes wiped, so reopening renders a stale screen with no controls. Reset `step`, `backupCodes` and `backupCodesUrl` whenever `open` goes false, not only in the button handlers.
Backup-code lookup is sensitive to input formatting and case — `indexOf` only strips dashes, so a code with any uppercase letter never matches and a valid recovery code is rejected. Normalize to `replace(/[^a-zA-Z0-9]/g, "").toLowerCase()` before matching, and apply the same at `totp/disable.ts:61`.
Backup code consumption is non-atomic and can be reused — The decrypt-null-write-back in the backup-code path is not atomic, so two concurrent requests can both pass `indexOf` and one code authenticates twice. Consume it with a conditional update that checks the unchanged `backupCodes` value.
2FA stays disabled when backup-codes dialog is dismissed without Close — Dismissing with Escape or an overlay click after 2FA is enabled server-side never calls `onEnable`, so the switch still shows 2FA as disabled and the modal shows stale backup codes. Invoke `onEnable()` on `onOpenChange(false)` once the codes are generated.
Backup code field validation never runs, so empty submissions give no feedback — The `required`/`minLength`/`maxLength` attributes never run because the form is `noValidate` and `formSchema` omits `backupCode`, so an empty submit sends `backupCode: ""` and shows no error. Validate `backupCode` in the schema or show an error when it is empty.
Clipboard copy test only asserts toast, not copied content — The `backup-codes-copy` handler shows the toast without checking the clipboard promise, so this test passes even when the copied content is wrong or the copy never happens. Read the clipboard back and assert it equals the dash-formatted codes shown in the dialog.
Backup code verification uses non-constant-time indexOf — `indexOf` on a live backup code reachable from the unauthenticated login endpoint leaks match position and prefix length through timing. Iterate all codes and compare equal-length buffers with `crypto.timingSafeEqual`, recording the match without early exit. **Also found in:** - `apps/web/pages/api/auth/two-factor/totp/disable.ts:58-64`
Gold bugs found (1)
Gold bugs missed (0)
None.