DeepSeek V4.1 Flash · 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
5
Comments matching a bug
1
Comments not matching
4
Cost of this PR
$0.149

Published comments (5)

highsecuritypackages/features/auth/lib/next-auth-options.ts:131-156

Backup-code login bypasses password when TOTP code is supplied — A request with a valid backup code and any `totpCode` logs in without the password, so a copied backup code alone unlocks the account. Verify the password unconditionally in the backup-code path before accepting the code.

highbugpackages/features/auth/lib/next-auth-options.ts:144-145

Backup code comparison is case-sensitive, rejecting uppercase codes — Codes are stored as lowercase hex but `indexOf` matches them case-sensitively, so a user typing uppercase codes gets `IncorrectBackupCode` and is locked out. Normalize both sides with `toLowerCase()` before comparing, and apply the same fix in `apps/web/pages/api/auth/two-factor/totp/disable.ts`.

highsecuritypackages/features/auth/lib/next-auth-options.ts:147-156

Backup code redemption has a non-atomic read-modify-write — Two parallel requests with the same code both pass `indexOf` and both authenticate, and concurrent redemptions of different codes can overwrite each other, breaking the single-use guarantee. Consume the code with an atomic conditional update, such as `prisma.user.updateMany` guarded by the original `backupCodes`, and fail when the count is not one.

mediumbugapps/web/components/settings/EnableTwoFactorModal.tsx:71-75

resetState not called when modal is dismissed via X, Escape or backdrop — Closing the dialog with X, Escape, or the backdrop leaves `step` at `SetupStep.DisplayBackupCodes`, so reopening shows the previous codes with no Cancel button to escape. Call `resetState` from the dialog's open/close handler, not only from the footer buttons.

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

2FA backup-code dismissal skips onEnable and leaves stale step — Once the enable request succeeds, dismissing the dialog never calls `onEnable`, so the security page still shows 2FA as disabled, and the stale backup-codes step reappears on reopen. Call `onEnable` and `resetState` on dialog dismissal after the request 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.