Amazon Ergo 1.0 · 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 Opus 5.5.
- Gold bugs found
- 3 of 8
- Comments published
- 5
- Comments matching a bug
- 3
- Comments not matching
- 2
- Cost of this PR
- $3.818
Published comments (5)
Backup-code redemption is a non-atomic read-modify-write — Concurrent logins can redeem the same backup code twice or overwrite each other's updates, resurrecting a consumed code. Replace the unconditional `prisma.user.update` with an atomic conditional update or transaction that confirms the stored `user.backupCodes` ciphertext is unchanged and checks the affected-row count.
Backup code login bypasses password verification when totpCode is present — A valid `credentials.backupCode` plus any non-empty `credentials.totpCode` skips password verification, letting the backup code replace the password instead of serving as a second factor. Require the password whenever `user.password` exists, or at minimum whenever `credentials.backupCode` is used, before accepting it.
Login shows settings-oriented backup-code guidance to locked-out users — Unauthenticated users cannot generate codes in settings, so `missing_backup_codes` leaves them without an actionable recovery path. Use login-specific guidance, such as authenticating with an authenticator code or contacting an administrator.
onEnable is skipped when the 2FA dialog is dismissed after enabling — If `onOpenChange` dismisses the dialog after server-side enablement, `onEnable` never runs, leaving the parent stale and 2FA apparently disabled. Call it on successful enablement or on every close path from the backup-codes step, not just the Close button. **Also found in:** - `apps/web/components/settings/EnableTwoFactorModal.tsx:132-135`
Backup codes verified with short-circuiting indexOf (timing side channel) — Verification time depends on the matched code's position and shared prefix, leaking information about these authentication credentials. Replace `backupCodes.indexOf` with SHA-256 digests compared via `crypto.timingSafeEqual`, scanning every entry without early exit. **Also found in:** - `apps/web/pages/api/auth/two-factor/totp/disable.ts:61-64`