DeepSeek V4 Pro · 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 Opus 5.5.

Gold bugs found
2 of 8
Comments published
2
Comments matching a bug
2
Comments not matching
0
Cost of this PR
$0.453

Published comments (2)

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

Backup code consumption is non-atomic and can allow code reuse — Two concurrent requests using the same backup code can both pass the indexOf check before either update commits, and concurrent requests with different codes can overwrite each other and resurrect a consumed code. Make the consume atomic with a single conditional UPDATE or a transaction.

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

Successful /enable response does not call onEnable — If the user closes the backup-codes screen via Escape or the overlay, onEnable never runs, so the switch shows 2FA as disabled and reopening shows the stale DisplayBackupCodes step. Invoke onEnable() as soon as /enable returns 200.

Gold bugs found (2)

mediumAfter enabling 2FA, onEnable is only called from the backup-codes Close button; dismissing the dialog by Escape/overlay never notifies the parent, so the settings page keeps showing 2FA disabled.
highBackup-code consumption is a non-atomic read-modify-write, so concurrent logins can accept the same backup code more than once or overwrite each other's removal.

Gold bugs missed (6)

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.
mediumThe backup-code copy e2e test only waits for the success toast, which is shown unconditionally, so it never verifies the clipboard content.
highThe hand-built `mockUser: User` fixture in inviteMemberUtils.test.ts lacks the new backupCodes field, so it no longer satisfies the Prisma User type and type-checking that file fails.
lowThe backup-code field became a PasswordField but keeps an explicit type="password" prop that overrides the internal visibility state, so the show/hide toggle never unmasks the input.
mediumEnableTwoFactorModal resets its step only from the footer buttons; dismissing the new backup-codes step via Escape or overlay leaves step at DisplayBackupCodes (and skips onEnable, so the settings switch is not refreshed), so reopening the enable modal shows the old backup-codes screen instead of the password step.
mediumIn lost-access mode the backup-code field's native required/length attributes are inert because the login form uses noValidate and has no RHF/zod rule for backupCode; submitting an empty code returns SecondFactorRequired, which the client handles silently, so the user gets no feedback.