🔒 fix: 2FA Encrypt TOTP Secrets & Improve Docs #5933
Merged
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.
This pull request introduces changes to improve the security and functionality of the two-factor authentication (2FA) system. The main updates include encrypting TOTP secrets, adding a function to retrieve and decrypt these secrets, and enhancing the documentation for various functions.
Security Improvements:
api/server/controllers/TwoFactorController.js
: Updated theenable2FAController
to encrypt TOTP secrets before storing them and modifiedverify2FAController
andconfirm2FAController
to retrieve and decrypt TOTP secrets using the newgetTOTPSecret
function. [1] [2] [3]api/server/controllers/auth/TwoFactorAuthController.js
: Enhanced theverify2FA
function to use thegetTOTPSecret
function for retrieving and decrypting TOTP secrets.api/server/services/twoFactorService.js
: Added thegetTOTPSecret
function to retrieve and decrypt stored TOTP secrets, and included thedecryptV2
utility function.Code Enhancements:
api/server/services/twoFactorService.js
: Improved documentation for various functions, includingencodeBase32
,decodeBase32
,generate2FATempToken
,generateTOTPSecret
,generateTOTP
,verifyTOTP
,generateBackupCodes
, andverifyBackupCode
. [1] [2] [3] [4] [5] [6] [7] [8]Additional Imports:
api/server/controllers/TwoFactorController.js
: Added theencryptV2
utility function for encrypting TOTP secrets.api/server/controllers/auth/TwoFactorAuthController.js
: Imported thegetTOTPSecret
function fromtwoFactorService
.Change Type
Please delete any irrelevant options.
Testing
Test Configuration:
Checklist