GLM-5.3 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 Opus 5.5.

Gold bugs found
4 of 8
Comments published
6
Comments matching a bug
4
Comments not matching
2
Cost of this PR
$0.088

Published comments (6)

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

Backup-code login skips password verification, allowing passwordless login with leaked code — A single leaked backup code grants full account access instead of acting as a second factor, because the backup-code branch in `authorize` never verifies the password. Verify `credentials.password` there, or gate the branch on the same `credentials.totpCode` check used for password verification.

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

Backup-code consumption is racy: non-atomic check-then-write allows code reuse — Two concurrent sign-ins can both accept the same single-use code, or a lost update can resurrect an already-consumed one. Perform validate-and-consume atomically, for example a conditional update on `backupCodes` that fails when the stored value changed.

highbugapps/web/pages/api/auth/two-factor/totp/disable.ts:54-56

MissingBackupCodes guidance is unactionable; no backup-code path for enabled 2FA — The setup endpoint refuses code generation while 2FA is already enabled (`TwoFactorAlreadyEnabled` in setup.ts), so a user who lost their authenticator is locked out with no working remedy. Expose a generation path for existing 2FA users, or replace the message with actionable recovery guidance.

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

Dismissing modal after enabling 2FA skips onEnable, leaving viewer.me stale — The server has enabled 2FA but `viewer.me` is never invalidated, so settings keeps showing two-factor auth as disabled until a manual refresh. Call `onEnable()` from the dialog's close path too, or invalidate `viewer.me` as soon as the enable call returns 200.

mediumbugapps/web/pages/api/auth/two-factor/totp/disable.ts:48-64

Non-string backupCode throws TypeError instead of returning 400 — A JSON body with a number, object, or array for `backupCode` throws a `TypeError` from `replaceAll` and escapes as an unhandled 500 instead of a clean 400. Guard with a `typeof` check before calling `replaceAll`, and apply the same check to `credentials.backupCode` in next-auth-options.ts.

mediumbugapps/web/components/auth/BackupCode.tsx:17-26

Backup code validation never enforced on login form with zodResolver and noValidate — An empty or too-short code still reaches the server and leaves the user with no error feedback, because the login form renders with `noValidate` and its zod schema only covers email and password. Validate `backupCode` in the login schema or pass register rules instead.

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.
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.
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.

Gold bugs missed (4)

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.