mirror of
https://github.com/zadam/trilium.git
synced 2025-10-24 14:56:14 +08:00
fix(auth): add missing TOTP verification for /login/token (#6823)
This commit is contained in:
commit
f7e77cd6cb
1 changed files with 18 additions and 1 deletions
|
|
@ -13,6 +13,8 @@ import sql from "../../services/sql.js";
|
|||
import ws from "../../services/ws.js";
|
||||
import etapiTokenService from "../../services/etapi_tokens.js";
|
||||
import type { Request } from "express";
|
||||
import totp from "../../services/totp";
|
||||
import recoveryCodeService from "../../services/encryption/recovery_codes";
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
|
|
@ -161,9 +163,16 @@ function touchProtectedSession() {
|
|||
|
||||
function token(req: Request) {
|
||||
const password = req.body.password;
|
||||
const submittedTotpToken = req.body.totpToken;
|
||||
|
||||
if (totp.isTotpEnabled()) {
|
||||
if (!verifyTOTP(submittedTotpToken)) {
|
||||
return [401, "Incorrect credential"];
|
||||
}
|
||||
}
|
||||
|
||||
if (!passwordEncryptionService.verifyPassword(password)) {
|
||||
return [401, "Incorrect password"];
|
||||
return [401, "Incorrect credential"];
|
||||
}
|
||||
|
||||
// for backwards compatibility with Sender which does not send the name
|
||||
|
|
@ -174,6 +183,14 @@ function token(req: Request) {
|
|||
return { token: authToken };
|
||||
}
|
||||
|
||||
function verifyTOTP(submittedTotpToken: string) {
|
||||
if (totp.validateTOTP(submittedTotpToken)) return true;
|
||||
|
||||
const recoveryCodeValidates = recoveryCodeService.verifyRecoveryCode(submittedTotpToken);
|
||||
|
||||
return recoveryCodeValidates;
|
||||
}
|
||||
|
||||
export default {
|
||||
loginSync,
|
||||
loginToProtectedSession,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue