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
feat(options/security): allow suppressing the dialog
Elian Doran4eef505abe36
diff --git a/apps/desktop/src/services/security_settings.ts b/apps/desktop/src/services/security_settings.tsindex 0160ce78b6..13bb316132 100644--- a/apps/desktop/src/services/security_settings.ts+++ b/apps/desktop/src/services/security_settings.ts@@ -1,10 +1,9 @@+import dataDirs from "@triliumnext/server/src/services/data_dir.js";import electron from "electron";import fs from "fs";import { t } from "i18next";import path from "path";-import dataDirs from "@triliumnext/server/src/services/data_dir.js";-const SECURITY_JSON_PATH = path.join(dataDirs.TRILIUM_DATA_DIR, "security.json");interface SecuritySettings {@@ -35,39 +34,58 @@ export function getSecuritySettings(): SecuritySettings {return readSettings();}-async function confirmEnable(settingLabel: string, warning: string): Promise<boolean> {+interface ConfirmResult {+ confirmed: boolean;+ suppressFurtherDialogs: boolean;+}++async function confirmEnable(settingLabel: string, warning: string): Promise<ConfirmResult> {const result = await electron.dialog.showMessageBox({type: "warning",buttons: [t("security-dialog.cancel"), t("security-dialog.enable")],defaultId: 0,cancelId: 0,+ checkboxLabel: t("security-dialog.dont-ask-again"),title: t("security-dialog.enable-title", { settingLabel }),message: t("security-dialog.enable-message", { settingLabel }),detail: t("security-dialog.enable-detail", { warning })});- return result.response === 1;+ return { confirmed: result.response === 1, suppressFurtherDialogs: result.checkboxChecked };}-async function confirmDisable(settingLabel: string): Promise<boolean> {+async function confirmDisable(settingLabel: string): Promise<ConfirmResult> {const result = await electron.dialog.showMessageBox({type: "info",buttons: [t("security-dialog.cancel"), t("security-dialog.disable")],defaultId: 1,cancelId: 0,+ checkboxLabel: t("security-dialog.dont-ask-again"),title: t("security-dialog.disable-title", { settingLabel }),message: t("security-dialog.disable-message", { settingLabel }),detail: t("security-dialog.disable-detail")});- return result.response === 1;+ return { confirmed: result.response === 1, suppressFurtherDialogs: result.checkboxChecked };}+// Prevents malicious frontend scripts from spamming the confirmation dialog to+// fatigue the user into clicking "Enable". The user can tick "Don't ask again"+// to suppress all security dialogs for the rest of the session. Resets on restart.+let suppressedForSession = false;+export function registerSecurityIpcHandlers(): void {electron.ipcMain.handle("security-set-backend-scripting", async (_event, enabled: boolean) => {- const confirmed = enabled+ if (suppressedForSession) {+ return false;+ }++ const { confirmed, suppressFurtherDialogs } = enabled? await confirmEnable(t("security-dialog.backend-scripting"), t("security-dialog.backend-scripting-warning")): await confirmDisable(t("security-dialog.backend-scripting"));+ if (suppressFurtherDialogs) {+ suppressedForSession = true;+ }if (!confirmed) {return false;}@@ -79,9 +97,16 @@ export function registerSecurityIpcHandlers(): void {});electron.ipcMain.handle("security-set-sql-console", async (_event, enabled: boolean) => {- const confirmed = enabled+ if (suppressedForSession) {+ return false;+ }++ const { confirmed, suppressFurtherDialogs } = enabled? await confirmEnable(t("security-dialog.sql-console"), t("security-dialog.sql-console-warning")): await confirmDisable(t("security-dialog.sql-console"));+ if (suppressFurtherDialogs) {+ suppressedForSession = true;+ }if (!confirmed) {return false;}diff --git a/apps/server/src/assets/translations/en/server.json b/apps/server/src/assets/translations/en/server.jsonindex c17e722d1c..b5209b4495 100644--- a/apps/server/src/assets/translations/en/server.json+++ b/apps/server/src/assets/translations/en/server.json@@ -449,6 +449,7 @@"cancel": "Cancel","enable": "Enable","disable": "Disable",+ "dont-ask-again": "Don't ask again until restart","backend-scripting": "Backend script execution","backend-scripting-warning": "Backend scripts have full access to the server, including the file system and network.","sql-console": "SQL console",