mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-28 17:56:02 +08:00 
			
		
		
		
	fix(auth): add missing TOTP verification for /login/token to align with /login
This commit is contained in:
		
							parent
							
								
									b4b5e86a14
								
							
						
					
					
						commit
						93c9383a92
					
				
					 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