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(desktop): keep notifications available to the renderer session
Elian Doran10895048532e
diff --git a/apps/desktop/src/services/web_contents_security.spec.ts b/apps/desktop/src/services/web_contents_security.spec.tsindex f73416b76c..61f919a320 100644--- a/apps/desktop/src/services/web_contents_security.spec.ts+++ b/apps/desktop/src/services/web_contents_security.spec.ts@@ -208,16 +208,20 @@ describe("setupWebContentsSecurity", () => {describe("isPermissionAllowed", () => {it("implements the per-session allowlist matrix", () => {- // App session: the renderer copies note content and toggles fullscreen.+ // App session: the renderer copies note content, toggles fullscreen+ // and shows notifications (user scripts rely on `new Notification()`).expect(isPermissionAllowed("app", "clipboard-sanitized-write")).toBe(true);expect(isPermissionAllowed("app", "fullscreen")).toBe(true);+ expect(isPermissionAllowed("app", "notifications")).toBe(true);- // Guest session: only fullscreen (embedded video players).+ // Guest session: only fullscreen (embedded video players). Remote+ // pages must not show OS notifications appearing to come from Trilium.expect(isPermissionAllowed("guest", "fullscreen")).toBe(true);expect(isPermissionAllowed("guest", "clipboard-sanitized-write")).toBe(false);+ expect(isPermissionAllowed("guest", "notifications")).toBe(false);// Everything else is denied everywhere.- for (const permission of ["media", "geolocation", "notifications", "midi", "hid", "serial", "usb", "pointerLock", "clipboard-read", "openExternal"]) {+ for (const permission of ["media", "geolocation", "midi", "hid", "serial", "usb", "pointerLock", "clipboard-read", "openExternal"]) {expect(isPermissionAllowed("app", permission)).toBe(false);expect(isPermissionAllowed("guest", permission)).toBe(false);}diff --git a/apps/desktop/src/services/web_contents_security.ts b/apps/desktop/src/services/web_contents_security.tsindex 369b5097fe..efb25a7eac 100644--- a/apps/desktop/src/services/web_contents_security.ts+++ b/apps/desktop/src/services/web_contents_security.ts@@ -113,13 +113,16 @@ export function hardenWebviewPreferences(webPreferences: Electron.WebPreferences* denied.** - `app`: the default session — the Trilium renderer itself. It legitimately- * writes to the clipboard (copy note content/links) and toggles fullscreen- * (e.g. presentations, zen mode), nothing else.+ * writes to the clipboard (copy note content/links), toggles fullscreen+ * (e.g. presentations, zen mode) and shows notifications (user scripts+ * commonly call `new Notification()` for reminders; the renderer only runs+ * trusted code, so this stays available to the scripting ecosystem).* - `guest`: the `<webview>` partition hosting arbitrary remote pages from- * Web View notes. Fullscreen only (embedded video players).+ * Web View notes. Fullscreen only (embedded video players) — a remote page+ * must not show OS notifications that appear to come from Trilium.*/const PERMISSION_ALLOWLIST = {- app: new Set(["clipboard-sanitized-write", "fullscreen"]),+ app: new Set(["clipboard-sanitized-write", "fullscreen", "notifications"]),guest: new Set(["fullscreen"])} as const;