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