Claude Sonnet 5.5 · Balanced

feat-2fa-backup-codes-cal-com

cal.com · TypeScript · M · 100–299 lines · 6 files

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
1 of 1
Comments published
3
Comments matching a bug
1
Comments not matching
2
Cost of this PR
$0.613

Published comments (3)

criticalsecuritypackages/features/auth/lib/next-auth-options.ts:128-131

Backup code login bypasses password check when junk totpCode is supplied — A junk `totpCode` plus a valid `backupCode` skips the password check, so a backup code alone authenticates. Make the password check run whenever `backupCode` is present, for example `if (user.password && (!credentials.totpCode || credentials.backupCode))`.

mediumbugpackages/features/auth/lib/next-auth-options.ts:139-156

Backup code consumption is non-atomic and allows concurrent reuse — Two concurrent logins can both find the same code in the decrypted `backupCodes` before either update commits, so a one-time code gets reused. Replace `prisma.user.update` with an `updateMany` conditioned on the original `user.backupCodes`, and throw `IncorrectBackupCode` when no rows change.

mediumbugapps/web/components/settings/EnableTwoFactorModal.tsx:134-136

Dismissing dialog on backup codes step skips onEnable and state reset — Closing via Esc or overlay click on the `DisplayBackupCodes` step skips `resetState` and `onEnable`, so the parent never learns 2FA was enabled and the modal reopens on that step. Run both in `onOpenChange` for that step, or call `onEnable` right after the enable succeeds.

Gold bugs found (1)

criticalThe credentials authorize() skips the password check when any totpCode is present, and the new backup-code branch never validates that totpCode, so a backup code plus a dummy totpCode logs in without the account password.

Gold bugs missed (0)

None.