Skip to content

Commit

Permalink
fix(2FA): handle malformed TOTP tokens gracefully (#10595)
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree authored Dec 31, 2024
1 parent 6cfee23 commit 0744f7f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions server/lib/two-factor-authentication/totp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ export default {
* twoFactorAuthenticatorCode = 6-digit TOTP
*/
function validateTOTPToken(encryptedSecret: string, token: string): boolean {
const decryptedTwoFactorAuthToken = crypto.decrypt(encryptedSecret);
return speakeasy.totp.verify({
secret: decryptedTwoFactorAuthToken,
encoding: 'base32',
token: token,
window: 2,
});
try {
const decryptedTwoFactorAuthToken = crypto.decrypt(encryptedSecret);
return speakeasy.totp.verify({
secret: decryptedTwoFactorAuthToken,
encoding: 'base32',
token: token,
window: 2,
});
} catch {
// An error can be thrown if the token is malformed. We simply return false in this case.
return false;
}
}

0 comments on commit 0744f7f

Please sign in to comment.