[PR #5202] [MERGED] fix(two-factor): backup codes shouldn't be encrypted twice #5846

Closed
opened 2026-03-13 12:38:50 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5202
Author: @Bekacru
Created: 10/10/2025
Status: Merged
Merged: 10/10/2025
Merged by: @himself65

Base: canaryHead: fix/two-factor


📝 Commits (4)

📊 Changes

3 files changed (+66 additions, -85 deletions)

View changed files

📝 packages/better-auth/src/plugins/two-factor/backup-codes/index.ts (+55 -78)
📝 packages/better-auth/src/plugins/two-factor/index.ts (+11 -3)
📝 packages/better-auth/src/plugins/two-factor/two-factor.test.ts (+0 -4)

📄 Description

Summary by cubic

Fixes double encryption of two-factor backup codes and ensures verification and viewing return parsed arrays instead of encrypted strings. Encrypted storage is now the default to prevent misconfiguration.

  • Bug Fixes
    • Centralized encryption/decryption in generateBackupCodes/getBackupCodes with safeJSONParse.
    • Defaulted backupCodeOptions to storeBackupCodes: "encrypted" and removed redundant helpers.
    • verifyBackupCode and viewBackupCodes now pass options correctly and return string[].
    • Updated tests to validate array output and use the verifyBackupCode response.

🔄 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/5202 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 10/10/2025 **Status:** ✅ Merged **Merged:** 10/10/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/two-factor` --- ### 📝 Commits (4) - [`5fd6d6f`](https://github.com/better-auth/better-auth/commit/5fd6d6f0ccf20ec73e8278e4239c6264d53590ba) fix(two-factor): double backup code encryption - [`de3fb51`](https://github.com/better-auth/better-auth/commit/de3fb511dbf05ea9ac4d16b06a4de0fdfabdf094) chore: fix minor - [`7ceda7e`](https://github.com/better-auth/better-auth/commit/7ceda7e6bfc233c3595c528eedd1c99d9c668424) fix: nitpick - [`b56502c`](https://github.com/better-auth/better-auth/commit/b56502c4649476548911d6c03f3aab6aae97ee85) fix: nitpick ### 📊 Changes **3 files changed** (+66 additions, -85 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/two-factor/backup-codes/index.ts` (+55 -78) 📝 `packages/better-auth/src/plugins/two-factor/index.ts` (+11 -3) 📝 `packages/better-auth/src/plugins/two-factor/two-factor.test.ts` (+0 -4) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Fixes double encryption of two-factor backup codes and ensures verification and viewing return parsed arrays instead of encrypted strings. Encrypted storage is now the default to prevent misconfiguration. - **Bug Fixes** - Centralized encryption/decryption in generateBackupCodes/getBackupCodes with safeJSONParse. - Defaulted backupCodeOptions to storeBackupCodes: "encrypted" and removed redundant helpers. - verifyBackupCode and viewBackupCodes now pass options correctly and return string[]. - Updated tests to validate array output and use the verifyBackupCode response. <!-- 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-03-13 12:38:50 -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#5846