[PR #6176] [MERGED] fix(two-factor): use constant time equal for otp comparison #14749

Closed
opened 2026-04-13 09:37:07 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6176
Author: @Bekacru
Created: 11/21/2025
Status: Merged
Merged: 11/21/2025
Merged by: @Bekacru

Base: canaryHead: fix/2fa


📝 Commits (2)

  • accfc40 fix(two-factor): use constant time equal for otp comparison
  • 35ae0e8 Merge branch 'canary' into fix/2fa

📊 Changes

2 files changed (+16 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/plugins/two-factor/backup-codes/index.ts (+10 -1)
📝 packages/better-auth/src/plugins/two-factor/otp/index.ts (+6 -1)

📄 Description

Summary by cubic

Strengthens 2FA security by using constant-time OTP comparison and making backup code redemption atomic. Prevents timing attacks and avoids double-use of backup codes under concurrent requests.

  • Bug Fixes
    • Use constantTimeEqual for OTP verification instead of direct string comparison.
    • Make backup code updates conditional on the current backupCodes and throw CONFLICT if no rows update, preventing race conditions.

Written for commit 35ae0e8dcd. Summary will update automatically 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/6176 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 11/21/2025 **Status:** ✅ Merged **Merged:** 11/21/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/2fa` --- ### 📝 Commits (2) - [`accfc40`](https://github.com/better-auth/better-auth/commit/accfc40440bebabea3071a7443442aff4915664b) fix(two-factor): use constant time equal for otp comparison - [`35ae0e8`](https://github.com/better-auth/better-auth/commit/35ae0e8dcd84c1b242eee28b5f3caa942817337c) Merge branch 'canary' into fix/2fa ### 📊 Changes **2 files changed** (+16 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/two-factor/backup-codes/index.ts` (+10 -1) 📝 `packages/better-auth/src/plugins/two-factor/otp/index.ts` (+6 -1) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Strengthens 2FA security by using constant-time OTP comparison and making backup code redemption atomic. Prevents timing attacks and avoids double-use of backup codes under concurrent requests. - **Bug Fixes** - Use constantTimeEqual for OTP verification instead of direct string comparison. - Make backup code updates conditional on the current backupCodes and throw CONFLICT if no rows update, preventing race conditions. <sup>Written for commit 35ae0e8dcd84c1b242eee28b5f3caa942817337c. Summary will update automatically 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 09:37:07 -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#14749