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(core): add security boundary at bundle execution level
Elian Doran40de97282228
diff --git a/packages/trilium-core/src/services/script.ts b/packages/trilium-core/src/services/script.tsindex 5e0392446b..ceb97cb59e 100644--- a/packages/trilium-core/src/services/script.ts+++ b/packages/trilium-core/src/services/script.ts@@ -7,6 +7,7 @@ import type BNote from "../becca/entities/bnote.js";import type { ApiParams } from "./backend_script_api_interface.js";import { getLog } from "./log.js";import ScriptContext from "./script_context.js";+import { assertScriptingEnabled } from "./scripting_guard.js";import { getContext } from "./context.js";import { unwrapStringOrBuffer } from "./utils/binary.js";import ws from "./ws.js";@@ -60,6 +61,13 @@ function executeNoteNoException(note: BNote, apiParams: ApiParams) {}export function executeBundle(bundle: Bundle, apiParams: ApiParams = {}) {+ // Security boundary: all backend script execution funnels through here, so this is the+ // single point that enforces the backendScriptingEnabled toggle. Call sites may also check+ // beforehand to fail gracefully (skip, return [], 403), but this guarantees no script runs+ // when scripting is disabled, regardless of how executeBundle is reached (e.g. via the+ // script-facing BNote.executeScript()).+ assertScriptingEnabled();+if (!apiParams.startNote) {// this is the default case, the only exception is when we want to preserve frontend startNoteapiParams.startNote = bundle.note;