[PR #7644] [MERGED] fix(2fa): server-side trust device expiration and configurable maxAge #15707

Closed
opened 2026-04-13 10:11:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7644
Author: @Paola3stefania
Created: 1/27/2026
Status: Merged
Merged: 1/28/2026
Merged by: @himself65

Base: canaryHead: fix/two-factor-trust-device-expiration


📝 Commits (4)

📊 Changes

6 files changed (+571 additions, -38 deletions)

View changed files

📝 packages/better-auth/src/plugins/two-factor/index.ts (+77 -26)
📝 packages/better-auth/src/plugins/two-factor/two-factor.test.ts (+466 -3)
📝 packages/better-auth/src/plugins/two-factor/types.ts (+8 -0)
📝 packages/better-auth/src/plugins/two-factor/verify-two-factor.ts (+16 -5)
📝 packages/better-auth/src/state.ts (+2 -2)
📝 packages/expo/src/routes.ts (+2 -2)

📄 Description

Summary by cubic

Secure 2FA trusted devices with server-side records, rotation, and expiration, and add a configurable trustDeviceMaxAge. Also fix cookie max-age units and revoke trust when 2FA is disabled.

  • New Features

    • Server-side trust device record with HMAC token + identifier; validated on sign-in and rotated on success.
    • trustDeviceMaxAge option (default 30 days) applied to both cookie and DB expiry across TOTP/OTP/backup codes.
    • Preserve trusted device across sign-out.
  • Bug Fixes

    • Expire and clear invalid or expired trust cookies; prevent reuse after rotation.
    • Revoke and delete trust record when disabling 2FA.
    • Correct cookie maxAge units in OAuth state cookies (state.ts and Expo routes).

Written for commit eb4a5e7888. 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/7644 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 1/27/2026 **Status:** ✅ Merged **Merged:** 1/28/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/two-factor-trust-device-expiration` --- ### 📝 Commits (4) - [`bbeca0f`](https://github.com/better-auth/better-auth/commit/bbeca0f98860b466edc66b2bcdd0286aa0030422) adddress security concern - [`eb18591`](https://github.com/better-auth/better-auth/commit/eb18591266a0846259d408eb75162de43179878d) fix issues - [`727a364`](https://github.com/better-auth/better-auth/commit/727a364730c7d5656062b55b04ef2c379e6f3ad6) feat: get plugin from context - [`eb4a5e7`](https://github.com/better-auth/better-auth/commit/eb4a5e788840e3fdc25d4fb97ca2a8db8c52c100) feat: get plugin from context ### 📊 Changes **6 files changed** (+571 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/two-factor/index.ts` (+77 -26) 📝 `packages/better-auth/src/plugins/two-factor/two-factor.test.ts` (+466 -3) 📝 `packages/better-auth/src/plugins/two-factor/types.ts` (+8 -0) 📝 `packages/better-auth/src/plugins/two-factor/verify-two-factor.ts` (+16 -5) 📝 `packages/better-auth/src/state.ts` (+2 -2) 📝 `packages/expo/src/routes.ts` (+2 -2) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Secure 2FA trusted devices with server-side records, rotation, and expiration, and add a configurable trustDeviceMaxAge. Also fix cookie max-age units and revoke trust when 2FA is disabled. - New Features - Server-side trust device record with HMAC token + identifier; validated on sign-in and rotated on success. - trustDeviceMaxAge option (default 30 days) applied to both cookie and DB expiry across TOTP/OTP/backup codes. - Preserve trusted device across sign-out. - Bug Fixes - Expire and clear invalid or expired trust cookies; prevent reuse after rotation. - Revoke and delete trust record when disabling 2FA. - Correct cookie maxAge units in OAuth state cookies (state.ts and Expo routes). <sup>Written for commit eb4a5e788840e3fdc25d4fb97ca2a8db8c52c100. 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-13 10:11:02 -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#15707