[PR #9205] [MERGED] fix(two-factor): revert enforcement broadening from #9122 #25401

Closed
opened 2026-04-15 22:52:14 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/9205
Author: @gustavovalverde
Created: 4/15/2026
Status: Merged
Merged: 4/15/2026
Merged by: @gustavovalverde

Base: mainHead: fix/revert-9122


📝 Commits (2)

  • 28dfc9e fix(two-factor): revert enforcement broadening from #9122
  • 3255fa1 test(two-factor): lock in v1.6.2 enforcement scope

📊 Changes

3 files changed (+32 additions, -23 deletions)

View changed files

.changeset/fix-revert-2fa-broadening.md (+9 -0)
📝 packages/better-auth/src/plugins/two-factor/index.ts (+3 -8)
📝 packages/better-auth/src/plugins/two-factor/two-factor.test.ts (+20 -15)

📄 Description

Reverts #9122

Why

The broadening shipped in #9122 caused unintended 2FA prompts on non-credential sign-in paths (magic link, email OTP, OAuth, SSO, passkey, SIWE, one-tap, phone-number OTP, device authorization, email-verification auto-sign-in) for users who had 2FA enabled. Apps that had not wired up 2FA handling on those surfaces reported that users were locked out.

What this PR does

Restores the pre-#9122 enforcement scope. 2FA is challenged only on /sign-in/email, /sign-in/username, and /sign-in/phone-number, matching v1.6.2 behavior.

What happens next

The broader enforcement, with per-method opt-outs and alignment to NIST SP 800-63B-4 authenticator assurance levels, is planned for a future minor release with migration guidance in #9203.


Summary by cubic

Reverts the broadened 2FA enforcement in better-auth. Restores v1.6.2 behavior by challenging 2FA only on /sign-in/email, /sign-in/username, and /sign-in/phone-number; non-credential sign-ins are no longer prompted.

  • Bug Fixes
    • Restricts the two-factor middleware matcher to the three credential paths and removes the now-redundant session check.
    • Adds regression tests to lock the scope: no 2FA on magic-link sign-in and no 2FA on authenticated non-sign-in endpoints.

Written for commit 3255fa1521. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/9205 **Author:** [@gustavovalverde](https://github.com/gustavovalverde) **Created:** 4/15/2026 **Status:** ✅ Merged **Merged:** 4/15/2026 **Merged by:** [@gustavovalverde](https://github.com/gustavovalverde) **Base:** `main` ← **Head:** `fix/revert-9122` --- ### 📝 Commits (2) - [`28dfc9e`](https://github.com/better-auth/better-auth/commit/28dfc9ec44298dcc546cbcecc79f697687b60a63) fix(two-factor): revert enforcement broadening from #9122 - [`3255fa1`](https://github.com/better-auth/better-auth/commit/3255fa1521c1bdeadd3aa83bf2a6cbb596f984d4) test(two-factor): lock in v1.6.2 enforcement scope ### 📊 Changes **3 files changed** (+32 additions, -23 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/fix-revert-2fa-broadening.md` (+9 -0) 📝 `packages/better-auth/src/plugins/two-factor/index.ts` (+3 -8) 📝 `packages/better-auth/src/plugins/two-factor/two-factor.test.ts` (+20 -15) </details> ### 📄 Description Reverts #9122 ## Why The broadening shipped in #9122 caused unintended 2FA prompts on non-credential sign-in paths (magic link, email OTP, OAuth, SSO, passkey, SIWE, one-tap, phone-number OTP, device authorization, email-verification auto-sign-in) for users who had 2FA enabled. Apps that had not wired up 2FA handling on those surfaces reported that users were locked out. ## What this PR does Restores the pre-#9122 enforcement scope. 2FA is challenged only on `/sign-in/email`, `/sign-in/username`, and `/sign-in/phone-number`, matching v1.6.2 behavior. ## What happens next The broader enforcement, with per-method opt-outs and alignment to NIST SP 800-63B-4 authenticator assurance levels, is planned for a future minor release with migration guidance in #9203. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Reverts the broadened 2FA enforcement in `better-auth`. Restores v1.6.2 behavior by challenging 2FA only on `/sign-in/email`, `/sign-in/username`, and `/sign-in/phone-number`; non-credential sign-ins are no longer prompted. - **Bug Fixes** - Restricts the two-factor middleware matcher to the three credential paths and removes the now-redundant session check. - Adds regression tests to lock the scope: no 2FA on magic-link sign-in and no 2FA on authenticated non-sign-in endpoints. <sup>Written for commit 3255fa1521c1bdeadd3aa83bf2a6cbb596f984d4. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:52:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25401