GLM-5.3 Flash · 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
- 3 of 8
- Comments published
- 9
- Comments matching a bug
- 3
- Comments not matching
- 6
- Cost of this PR
- $0.186
Published comments (9)
Backup-code login bypasses password verification — A leaked backup code alone then grants full account access, since the password check is skipped when a `backupCode` is posted with any dummy `totpCode`. Verify `credentials.password` inside the backup-code branch before authenticating.
twoFactorLostAccess state persists after modal is closed or cancelled — Reopening the modal then shows the backup-code screen with stale `backupCode`/`totpCode` values instead of the default TOTP view. Reset `twoFactorLostAccess` and the form values when the modal closes or opens.
Non-string backupCode throws TypeError instead of returning 400 — A truthy non-string `backupCode` (number, object, array) passes the guard and `replaceAll` throws an unhandled TypeError, surfacing as a generic 500. Check `typeof req.body.backupCode === "string"` and return the 400 `IncorrectBackupCode` response otherwise.
2FA switch assertion passes a Promise to expect and never fails — The unawaited Promise from `isChecked()` is always truthy, so the assertion can never fail and this test proves nothing about the 2FA switch. Await `expect` on the `[data-state="checked"]` locator or use `toBeChecked()` instead.
Closing backup code dialog asserts nothing, test passes if dialog stays open — A broken close button would go unnoticed, because the follow-up switch assertion still passes behind an open modal and the next step discards the dialog. After the click, assert the dialog is gone, e.g. `toBeHidden()` on `backup-codes-close`.
Dialog close via ESC/overlay skips onEnable() and resetState(), leaving stale 2FA state — ESC or overlay clicks skip both `onEnable()` and `resetState()`, leaving `viewer.me` stale in `two-factor-auth.tsx` so 2FA still shows disabled and the modal reopens on backup codes. Trigger `onEnable()` from the dialog's close path too, not just the Close button.
Backup-code consumption is a non-atomic read-modify-write race — Two concurrent logins can both pass the `indexOf` check, leaving a consumed code valid or letting the same one authenticate twice. Make the write conditional — `updateMany` matching the previously read `backupCodes` — and fail when no rows change.
Backup code comparison is case-sensitive while stored codes are lowercase hex — Stored codes are lowercase hex from `crypto.randomBytes(5).toString("hex")`, so a valid code typed with uppercase is wrongly rejected with `IncorrectBackupCode`. Compare both sides lowercased, here and in `disable.ts`.
Backup-code comparison is not constant-time, leaking match info via timing — Response times reveal how many leading characters of a submitted `backupCode` match a stored one, which is enough to reconstruct a code that together with the password authenticates the account. Compare hashes with `crypto.timingSafeEqual` over equal-length buffers instead of `indexOf`. **Also found in:** - `apps/web/pages/api/auth/two-factor/totp/disable.ts:58-64`