DeepSeek V4 Pro · 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
4 of 8
Comments published
7
Comments matching a bug
4
Comments not matching
3
Cost of this PR
$1.410

Published comments (7)

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

Backup code login bypasses password verification when totpCode is supplied — A valid backup code plus any dummy `totpCode` bypasses the password check above. Verify `credentials.password` against `user.password` before trusting the backup code.

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

Non-atomic backup-code consumption allows double-use or resurrection — Two logins on the same code can both pass `indexOf` before either write commits, or one write can clobber another and resurrect a used code. Use an atomic update keyed on the prior `backupCodes` value.

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

2FA enable invalidation skipped when dialog dismissed via X/Escape after success — The X/Escape path calls `onOpenChange` directly, so `onEnable()` never runs and the parent query stays stale. Trigger `onEnable()` on close as well, or drive invalidation from `onOpenChange`.

mediumbugpackages/features/auth/lib/next-auth-options.ts:144

Backup-code comparison is case-sensitive and rejects uppercase codes — Codes are generated as lowercase hex, so an uppercase entry is rejected as `IncorrectBackupCode` despite being correct. Normalize with `.toLowerCase()` before comparison and set `autoCapitalize="none"` on the input.

mediumbugapps/web/playwright/login.2fa.e2e.ts:119-122

Backup code copy test only waits for toast, not clipboard contents — The toast appears even when the clipboard write rejects or writes empty text, so this test never catches a broken copy. Grant clipboard-read permission and assert the actual contents.

mediumbugapps/web/playwright/login.2fa.e2e.ts:50-53

Loose 2FA switch assertion can pass when switch is not checked — `.isChecked()` returns a truthy-then-falsy value here, so the assertion can pass when the switch is not checked. Wait for `data-state="checked"` or close the backup-code dialog first.

mediumsecuritypackages/features/auth/lib/next-auth-options.ts:143-145

Backup code verification should use constant-time comparison — Early-exit string comparison leaks timing information about the code and its position. Compare the submitted code against every stored code with a fixed-work loop that accumulates differences before deciding. **Also found in:** - `apps/web/pages/api/auth/two-factor/totp/disable.ts:61-63`

Gold bugs found (4)

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.
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.
mediumThe backup-code copy e2e test only waits for the success toast, which is shown unconditionally, so it never verifies the clipboard content.
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 (4)

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.