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

Gold bugs found
1 of 1
Comments published
7
Comments matching a bug
1
Comments not matching
6
Cost of this PR
$2.063

Published comments (7)

highbugapps/web/pages/api/auth/two-factor/totp/setup.ts:60-68

Existing 2FA users permanently lack backup codes; enable endpoint never generates them — Every pre-existing 2FA user has `backupCodes` = null, so the lost-access login path always fails with `MissingBackupCodes` and their only recourse is disabling 2FA. Generate codes in the enable endpoint when `backupCodes` is null, or add a regeneration path for already-enabled users.

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

Backup code login skips password verification, allowing single-factor auth — Any non-empty garbage `totpCode` skips the password gate, so a stolen backup code plus a wrong password authenticates — turning a static downloaded secret into single-factor login. Verify the password inside the backup-code branch, or only allow the skip when the TOTP path is actually taken. **Also found in:** - `packages/features/auth/lib/next-auth-options.ts:128-131`

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

2FA switch assertion is vacuous: unchecked Promise is always truthy — The un-awaited `isChecked()` Promise is always truthy, so `toBeTruthy()` never fails and the test cannot catch an unchecked switch. Replace it with `toBeChecked()` (or the `data-state="checked"` visibility check) and drop the FIXME.

mediumbugapps/web/playwright/login.2fa.e2e.ts:110-127

Backup-codes test never verifies the actual codes; passes on malformed output — The checks pass even when generation is broken: the download check compares only the filename, and `toast-success` fires without awaiting the clipboard write. Assert the rendered codes (10 entries matching `XXXXX-XXXXX`) or the downloaded file's contents.

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

Backup code check-then-act race lets one code mint multiple sessions — Between reading `backupCodes` and writing the consumed array sit a bcrypt check and a rate-limit call, so two concurrent requests can both pass `indexOf` and mint sessions from one code. Consume it atomically, e.g. an `updateMany` filtered on the stored codes being unchanged. **Also found in:** - `packages/features/auth/lib/next-auth-options.ts:128-149`

mediumbugapps/web/components/settings/EnableTwoFactorModal.tsx:261-272

Dialog close at backup-codes step skips onEnable() and leaves stale state — Closing the dialog via X, Escape, or outside click skips `onEnable()` and `resetState()`, so the parent never invalidates `viewer.me` and re-opening resurrects the stale codes step. Handle `onOpenChange` to enable and reset at this step. **Also found in:** - `apps/web/components/settings/EnableTwoFactorModal.tsx:134-136`

mediumsecuritypackages/features/auth/lib/next-auth-options.ts:139-146

Backup code verified with non-constant-time indexOf, leaking timing data — `indexOf` compares the submitted secret with plain equality on an unauthenticated endpoint, leaking match position and prefix length via timing, unlike the adjacent TOTP and bcrypt paths. Use `timingSafeEqual` over fixed-length digests of each code instead. **Also found in:** - `apps/web/pages/api/auth/two-factor/totp/disable.ts:58-64`

Gold bugs found (1)

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.

Gold bugs missed (0)

None.