Kimi K3.1 Pro · 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
- 13
- Comments matching a bug
- 1
- Comments not matching
- 12
- Cost of this PR
- $2.289
Published comments (13)
Backup-code login bypasses `verifyPassword` and both authentication factors — A valid `backupCode` plus any non-empty `totpCode` authenticates without the CAL account password or authenticator. Require `verifyPassword` before accepting either second factor, regardless of additional credential fields.
Escape or outside dismissal leaves stale 2FA state after enablement — Because `onEnable()` no longer runs here, `viewer.me.invalidate()` is reached only by the custom Close button; Escape or outside dismissal leaves 2FA shown as disabled after server enablement. Invalidate on successful enablement and separate that from closing, or route every exit through completion.
Clipboard failures falsely trigger the recovery-code success toast — A rejected `writeText` promise, such as denied clipboard permission, still shows the success toast and falsely tells users their recovery codes were copied. Await the write, show success only when it resolves, and show an error toast when it rejects.
Backup code field has no effective submission validation — Because the form uses `noValidate` and `register("backupCode")` has no rules, an empty submission bypasses native validation and returns `SecondFactorRequired` without a visible error. Add React Hook Form rules to the registration or validate explicitly in lost-access mode before calling `signIn`.
Backup-code mode persists after the modal is canceled or dismissed — Canceling or dismissing while using a backup code leaves `twoFactorLostAccess` set, so the next opening shows the backup-code form instead of the default TOTP form. Reset `twoFactorLostAccess` on every close path, not only after a successful disable.
Backup-code recovery message directs logged-out users to settings — Before credentials are authorized, the user has no session and cannot reach settings, making the `missing_backup_codes` recovery instruction unusable; no standalone regeneration flow is added. Provide logged-out guidance or add that flow.
Backup-code disable path logs a misleading login error — The `console.error` message refers to “backup code login” although this handler disables 2FA, sending operators debugging a missing encryption key toward the wrong flow. Describe the backup-code disable operation instead.
Empty backup codes incorrectly fall through to TOTP validation — Treating `backupCode` by truthiness sends an empty submission to TOTP validation; from the backup-code view, cleared `totpCode` then yields `SecondFactorRequired` with no visible error. Detect backup-code submissions explicitly and reject missing or empty strings with backup-code-specific validation.
This check would still pass if copying backup codes were broken — Waiting only for `toast-success` does not prove anything was copied: the component does not await `navigator.clipboard.writeText(...)`, so rejected or no-op writes and incorrect contents still satisfy the test. Read the clipboard and compare its contents with the displayed backup codes.
This verifies only that some download occurs with the hard-coded filename — Checking only `suggestedFilename()` allows empty, malformed, or incorrect backup-code downloads to pass. Read the downloaded file and compare its complete contents with the formatted codes displayed in the dialog.
Close sequence does not verify the backup-code dialog closes — The checked settings switch can remain visible to Playwright beneath an open modal, so this sequence can pass without the backup-code dialog closing. After clicking close, assert that the dialog or its backup-code content is hidden.
Non-atomic `backupCodes` updates permit reuse and restore consumed codes — Checking and rewriting the decrypted `backupCodes` list separately lets concurrent requests reuse one code; with different codes, the last write can restore the other as unused. Consume the code and authorize login only in an atomic, retrying serializable or row-locked transaction.
Backup code verification uses timing-sensitive string equality — Because `indexOf` uses ordinary string equality and can stop at the first mismatch, verification time may reveal how much of a guessed authentication secret matches. Compare the normalized fixed-length code with every stored code using equal-length buffers and `crypto.timingSafeEqual`, while retaining rate limiting. **Also found in:** - `apps/web/pages/api/auth/two-factor/totp/disable.ts:58-64`
Gold bugs found (1)
Gold bugs missed (0)
None.