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
docs: update security architecture references after nodeIntegration removal
Elian Dorana5e7de5d56c0
diff --git a/CLAUDE.md b/CLAUDE.mdindex c5d09af3ef..f63eed48ee 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -168,7 +168,7 @@ Fluent builder pattern: `.child()`, `.class()`, `.css()` chaining with position-- **No Node.js built-in modules in core** — core runs in both Node.js and the browser (standalone). Use platform-agnostic alternatives or platform providers- **Platform detection via functions** — `isElectron()`, `isMac()`, `isWindows()` from `utils/index.ts` are functions (not constants) that call `getPlatform()`. They can only be called after `initializeCore()`, not at module top-level. If used in static definitions, wrap in a closure: `value: () => isWindows() ? "0.9" : "1.0"`- **Barrel import caution** — `import { x } from "@triliumnext/core"` loads ALL core exports. Early-loading modules like `config.ts` should import specific subpaths (e.g. `@triliumnext/core/src/services/utils/index`) to avoid circular dependencies or initialization ordering issues-- **Electron IPC** — In desktop mode, client API calls use Electron IPC (not HTTP). The IPC handler in `apps/server/src/routes/electron.ts` must be registered via `utils.isElectron` from the **server's** utils (which correctly checks `process.versions["electron"]`), not from core's utils+- **Electron custom protocol** — In desktop mode, the renderer loads the UI and makes API calls via the `trilium-app://` custom protocol (not HTTP). `apps/desktop/src/protocol.ts` dispatches these requests into the Express app running in the main process; the dispatcher tags them via `apps/server/src/services/electron_request.ts` so auth/CSRF middleware can distinguish them from external TCP traffic### Binary Utilities@@ -212,16 +212,16 @@ SQLite via `better-sqlite3`. SQL abstraction in `packages/trilium-core/src/servi- **Interpolation**: Use `{{variable}}` for normal interpolation; use `{{- variable}}` (with hyphen) for **unescaped** interpolation when the value contains special characters like quotes that shouldn't be HTML-escaped### Electron Desktop App-- Desktop entry point: `apps/desktop/src/main.ts`, window management: `apps/server/src/services/window.ts`+- Desktop entry point: `apps/desktop/src/main.ts`, window management: `apps/desktop/src/services/window.ts`- **Security**: `nodeIntegration` is **disabled** and `contextIsolation` is **enabled**. The renderer has no access to Node.js APIs or Electron internals.- **Preload script** (`apps/desktop/src/preload.ts`): Uses `contextBridge.exposeInMainWorld("electronApi", ...)` to expose a whitelisted API to the renderer. Compiled to CJS via esbuild (dev: `scripts/electron-start.mts`, prod: `apps/desktop/scripts/build.ts`).- **ElectronApi interface** (`packages/commons/src/lib/electron_api_interface.ts`): Shared type definition used by both the preload script (`satisfies ElectronApi`) and the client (`window.electronApi`). Grouped into sub-objects: `window`, `clipboard`, `shell`, `contextMenu`, `spellcheck`, `tray`, `printing`, `navigation`.- **Client-side access**: Use `window.electronApi?.group.method()` — never use `require("electron")` or `dynamicRequire()` in client code.-- **Adding new Electron APIs**: Add the method to the interface in commons, implement it in `preload.ts`, add the IPC handler in `apps/server/src/services/window.ts`, and add a test in `apps/desktop/spec/preload.spec.ts`.+- **Adding new Electron APIs**: Add the method to the interface in commons, implement it in `preload.ts`, add the IPC handler in `apps/desktop/src/services/window.ts`, and add a test in `apps/desktop/spec/preload.spec.ts`.- **IPC handlers**: Use `electron.ipcMain.on(channel, handler)` for fire-and-forget, `electron.ipcMain.handle(channel, handler)` for async request/response, `ipcMain.on` + `event.returnValue` for synchronous queries.- Electron-only features should check `isElectron()` from `apps/client/src/services/utils.ts` (client) or `utils.isElectron` (server)- **`@electron/remote` is removed** — do not use it. All renderer↔main communication goes through the preload bridge.-- **Spurious `electron.app is undefined` error** — when running Electron-based apps (`pnpm desktop:start`, `pnpm edit-docs:edit-docs`, etc.), the console may print `TypeError: Cannot read properties of undefined (reading 'commandLine')` from `apps/server/src/services/window.ts` (the `electron.app.commandLine.appendSwitch("disable-http-cache")` line). This is **not a real failure** — the app runs correctly. Do not try to fix it, guard it, or investigate electron initialization order unless the user explicitly raises it as a bug.+- **Spurious `electron.app is undefined` error** — when running Electron-based apps (`pnpm desktop:start`, `pnpm edit-docs:edit-docs`, etc.), the console may print `TypeError: Cannot read properties of undefined (reading 'commandLine')` from `apps/desktop/src/main.ts` (the `app.commandLine.appendSwitch("disable-http-cache")` line). This is **not a real failure** — the app runs correctly. Do not try to fix it, guard it, or investigate electron initialization order unless the user explicitly raises it as a bug.Three inheritance mechanisms:1. **Standard**: `note.getInheritableAttributes()` walks parent treediff --git a/SECURITY.md b/SECURITY.mdindex befd061a74..ee7880594c 100644--- a/SECURITY.md+++ b/SECURITY.md@@ -54,11 +54,10 @@ Trilium is a personal knowledge base where users have full control over their owVulnerabilities that require a user to inject malicious content into their own notes and then view it themselves are not considered security issues.-#### Electron Architecture (nodeIntegration)-Trilium's desktop application runs with `nodeIntegration: true` to enable its powerful scripting features. This is an intentional design decision, similar to VS Code extensions having full system access. We mitigate risks by:-- Sanitizing content at input boundaries-- Fixing specific XSS vectors as they're discovered-- Using Electron fuses to prevent external abuse+#### Electron Architecture+The desktop application follows the Electron security checklist: `nodeIntegration` is disabled, `contextIsolation` is enabled, and the renderer can only reach the main process through a whitelisted `contextBridge` API (`window.electronApi`). Embedded web content (Web View notes) is isolated in a dedicated session partition with deny-by-default permission handlers, `<webview>` attach requests are vetted in the main process, and window-open/navigation requests are checked against a scheme allowlist. Electron fuses additionally prevent external abuse.++User scripting (see Self-XSS above) still intentionally allows arbitrary JavaScript in the renderer, so reports that reduce to "a user script can call the frontend API" remain out of scope. Renderer-to-main escapes, however, **are in scope**: gaining Node.js access from the renderer, bypassing the preload bridge whitelist, or escaping the webview isolation.#### Authenticated User ActionsActions that require valid authentication and only affect the authenticated user's own data are generally not vulnerabilities.diff --git a/apps/server/src/services/electron_request.ts b/apps/server/src/services/electron_request.tsindex ddd4692ab0..8d0f4c8879 100644--- a/apps/server/src/services/electron_request.ts+++ b/apps/server/src/services/electron_request.ts@@ -3,7 +3,7 @@** The desktop build runs the full Express stack inside the Electron main* process. The renderer makes API calls via the custom protocol (see- * `apps/server/src/routes/electron.ts`), which dispatches a synthesised+ * `apps/desktop/src/protocol.ts`), which dispatches a synthesised* request through the same Express app instance as the public HTTP listener.** Auth and CSRF middleware historically bypassed on the process-wide