Conversation
requireDualFactor called auth.api.verifyTOTP, which requires either an active Better Auth session or the TWO_FACTOR_COOKIE_NAME cookie. The OAuth-MFA finalize path runs after interceptOauthCallback has destroyed the session and leaves only the pending_oauth_mfa cookie, so verifyTOTP threw for every request and every OAuth-with-TOTP sign-in failed with "Invalid authenticator code" regardless of the code submitted. Live in prod since 2026-05-26 22:17 UTC (KEEP-619 PR #1355). Replace the verifyTOTP call with a direct read of two_factor.secret plus verifyUserTotp() — the same session-less primitive that strict-signin already uses in production. Same RFC 6238 window, same constant-time compare, no behavior change for the 15 callers that already have a session. Test: tests/unit/dual-factor.test.ts covers the regression case (valid TOTP + email OTP without a session ⇒ ok=true) plus mfa_code_invalid on wrong code, mfa_code_invalid on missing two_factor row (don't leak enrollment state), email_code_invalid on missing verifications row, and factors_required on missing codes. Refs KEEP-619.
Three small follow-ups from the multi-agent review on PR #1394: - Refresh the requireDualFactor docstring; it still claimed TOTP was verified via Better Auth's verifyTOTP endpoint after the fix moved that off to verifyUserTotp. - Assert resetDualFactor is called on the happy path. Without this, the rate-limit counter could silently stop clearing on success and the suite would still go green. - The "no two_factor row" test was passing a live TOTP code that was never reached; replace with "000000" so the test name and the input match what is actually being asserted.
…sion-less fix(auth): verify TOTP session-lessly in dual-factor gate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Promote the following merged PRs from staging to prod:
Post-deploy verification
deploy-keeperhubworkflow finishes greencurl -fsS https://app.keeperhub.com/api/healthreturns 200