Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(server): TOTP broken after standalone refactoring
Elian Doran2823795e6a4e
diff --git a/apps/server/src/services/encryption/totp_encryption.spec.ts b/apps/server/src/services/encryption/totp_encryption.spec.tsindex 3ed346f40e..5eb3e63cb3 100644--- a/apps/server/src/services/encryption/totp_encryption.spec.ts+++ b/apps/server/src/services/encryption/totp_encryption.spec.ts@@ -24,11 +24,8 @@ describe("totp_encryption", () => {});expect(totpEncryption.isTotpSecretSet()).toBe(true);- // getTotpSecret returns a non-null decrypted value whose bytes are the secret- const stored = totpEncryption.getTotpSecret();- expect(stored).not.toBeNull();- const bytes = Uint8Array.from((stored as string).split(",").map(Number));- expect(Buffer.from(bytes).toString("utf-8")).toBe(SECRET);+ // the decrypted secret must round-trip exactly, otherwise TOTP validation breaks+ expect(totpEncryption.getTotpSecret()).toBe(SECRET);// verification re-hashes the original secret with the password saltexpect(totpEncryption.verifyTotpSecret(SECRET)).toBe(true);expect(totpEncryption.verifyTotpSecret("wrong-secret")).toBe(false);diff --git a/apps/server/src/services/encryption/totp_encryption.ts b/apps/server/src/services/encryption/totp_encryption.tsindex a40074b4e8..f6f00c9a2f 100644--- a/apps/server/src/services/encryption/totp_encryption.ts+++ b/apps/server/src/services/encryption/totp_encryption.ts@@ -10,7 +10,7 @@* Verification uses scrypt-based hashing with constant-time comparison.*/import type { OptionNames } from "@triliumnext/commons";-import { data_encryption, options as optionService } from "@triliumnext/core";+import { binary_utils, data_encryption, options as optionService } from "@triliumnext/core";import crypto from "crypto";import { constantTimeCompare, randomSecureToken, toBase64 } from "../utils.js";@@ -79,7 +79,7 @@ function getTotpSecret(): string | null {return null;}- return decryptedSecret.toString();+ return binary_utils.decodeUtf8(decryptedSecret);} catch (e) {console.error("Failed to decrypt TOTP secret:", e);return null;