Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): neutralise the script relations on a safe import

Elian Doranb975843472bd
diff --git a/packages/commons/src/lib/builtin_attributes.ts b/packages/commons/src/lib/builtin_attributes.ts
index 9cd5314145..b5e295ea69 100644
--- a/packages/commons/src/lib/builtin_attributes.ts
+++ b/packages/commons/src/lib/builtin_attributes.ts
@@ -179,7 +179,9 @@ const BUILTIN_ATTRIBUTES = [
// Launch bar, and the hidden subtree items that back it
{ type: "label", name: "launcherType", valueType: "string" },
{ type: "label", name: "builtinWidget", valueType: "string" },
- { type: "label", name: "scriptInLauncherContent", valueType: "boolean" },
+ // Dangerous together with `~script` below: it makes the launcher run its own content instead, so
+ // neutralising only the relation would leave this as a way around it.
+ { type: "label", name: "scriptInLauncherContent", valueType: "boolean", isDangerous: true },
{ type: "label", name: "baseSize", valueType: "number" },
{ type: "label", name: "growthFactor", valueType: "number" },
{ type: "label", name: "desktopOnly", valueType: "boolean" },
@@ -267,10 +269,12 @@ const BUILTIN_ATTRIBUTES = [
{ type: "relation", name: "yearTemplate" },
{ type: "relation", name: "widget", isDangerous: true },
{ type: "relation", name: "renderNote", isDangerous: true },
- { type: "relation", name: "searchScript" },
+ { type: "relation", name: "searchScript", isDangerous: true },
{ type: "relation", name: "ancestor" },
{ type: "relation", name: "target" },
- { type: "relation", name: "script" },
+ // Both execute a script, unlike the handlers above only once the user opens or clicks something.
+ // Flagged all the same, so a safe import cannot leave one primed behind a single keystroke.
+ { type: "relation", name: "script", isDangerous: true },
{ type: "relation", name: "hoistedNote" },
{ type: "relation", name: "shareCss" },
{ type: "relation", name: "shareLogo" },
diff --git a/packages/trilium-core/src/services/attributes.spec.ts b/packages/trilium-core/src/services/attributes.spec.ts
index 1227426c53..2a11dac646 100644
--- a/packages/trilium-core/src/services/attributes.spec.ts
+++ b/packages/trilium-core/src/services/attributes.spec.ts
@@ -59,6 +59,13 @@ describe("attributes service", () => {
expect(isAttributeDangerous("relation", "run")).toBe(false);
});
+ it("flags the script relations, which run only on user action but run all the same", () => {
+ expect(isAttributeDangerous("relation", "script")).toBe(true);
+ expect(isAttributeDangerous("relation", "searchScript")).toBe(true);
+ // Without this a launcher could run its content instead, sidestepping `~script`.
+ expect(isAttributeDangerous("label", "scriptInLauncherContent")).toBe(true);
+ });
+
it("matches case-insensitively and trims whitespace from the name", () => {
expect(isAttributeDangerous("label", "RUN")).toBe(true);
expect(isAttributeDangerous("label", " run ")).toBe(true);