Amazon Ergo 1.0 · 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
3 of 8
Comments published
3
Comments matching a bug
3
Comments not matching
0
Cost of this PR
$2.415

Published comments (3)

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

Backup-code login bypasses password verification — A direct credentials-callback request with an email, valid `backupCode`, and any non-empty `totpCode` can create a session without a password because `if (user.password && !credentials.totpCode)` is the only check. Verify the password in the backup-code branch or bind the second-factor step to server-side state from the password step.

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

Backup-code consumption is a non-atomic read-modify-write — Concurrent `authorize` requests can read the same `backupCodes` array and pass `indexOf` before either writes, letting one one-time code create multiple sessions; different codes can also lose an update and resurrect a consumed code. Consume codes atomically with a transaction, conditional update, or per-code used markers.

mediumbugapps/web/components/settings/EnableTwoFactorModal.tsx:135

onEnable skipped when backup-code step is dismissed via overlay or Escape — The parent skips viewer query invalidation, the success toast, and state refresh, leaving the 2FA switch stale and the one-time backup-code display effectively lost. Call `onEnable()` whenever the backup-code step is dismissed, not only from the Close button. **Also found in:** - `apps/web/components/settings/EnableTwoFactorModal.tsx:261-272`

Gold bugs found (3)

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.
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 (5)

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.