Skip to content

Build your personal knowledge base with Trilium Notes

chore(core): remove Electron bypass for backend scripting

Elian Doran1b55902a02bb
diff --git a/apps/server/src/services/config.ts b/apps/server/src/services/config.ts
index cf5454fb55..b6bf3e309a 100644
--- a/apps/server/src/services/config.ts
+++ b/apps/server/src/services/config.ts
@@ -545,11 +545,6 @@ const config: TriliumConfig = {
}
};
-// Desktop builds always have scripting enabled (single-user trusted environment)
-if (process.versions["electron"]) {
- config.Scripting.backendScriptingEnabled = true;
- config.Scripting.sqlConsoleEnabled = true;
-}
/**
* =====================================================================
diff --git a/apps/server/src/services/scripting_guard.spec.ts b/apps/server/src/services/scripting_guard.spec.ts
index 7adf607b73..286928b485 100644
--- a/apps/server/src/services/scripting_guard.spec.ts
+++ b/apps/server/src/services/scripting_guard.spec.ts
@@ -2,24 +2,15 @@ import { vi, describe, it, expect, beforeEach } from "vitest";
// Mutable mock state that can be changed between tests
const mockState = {
- isElectron: false,
scriptingEnabled: false,
sqlConsoleEnabled: false
};
-// Mock utils module so isElectron can be controlled per test
-vi.mock("./utils.js", () => ({
- isElectron: false,
- default: {
- isElectron: false
- }
-}));
-
// Mock config module so Scripting section can be controlled per test
vi.mock("./config.js", () => ({
default: {
Scripting: {
- get enabled() {
+ get backendScriptingEnabled() {
return mockState.scriptingEnabled;
},
get sqlConsoleEnabled() {
@@ -31,26 +22,17 @@ vi.mock("./config.js", () => ({
describe("scripting_guard", () => {
beforeEach(() => {
- // Reset to defaults
- mockState.isElectron = false;
mockState.scriptingEnabled = false;
mockState.sqlConsoleEnabled = false;
vi.resetModules();
});
describe("assertScriptingEnabled", () => {
- it("should throw when scripting is disabled and not Electron", async () => {
- mockState.isElectron = false;
+ it("should throw when scripting is disabled", async () => {
mockState.scriptingEnabled = false;
- // Re-mock utils with isElectron = false
- vi.doMock("./utils.js", () => ({
- isElectron: false,
- default: { isElectron: false }
- }));
-
const { assertScriptingEnabled } = await import("./scripting_guard.js");
- expect(() => assertScriptingEnabled()).toThrowError(
+ expect(() => assertScriptingEnabled()).toThrow(
/Backend script execution is disabled/
);
});
@@ -58,39 +40,17 @@ describe("scripting_guard", () => {
it("should not throw when scripting is enabled", async () => {
mockState.scriptingEnabled = true;
- vi.doMock("./utils.js", () => ({
- isElectron: false,
- default: { isElectron: false }
- }));
-
- const { assertScriptingEnabled } = await import("./scripting_guard.js");
- expect(() => assertScriptingEnabled()).not.toThrow();
- });
-
- it("should not throw when isElectron is true even if config is false", async () => {
- mockState.scriptingEnabled = false;
-
- vi.doMock("./utils.js", () => ({
- isElectron: true,
- default: { isElectron: true }
- }));
-
const { assertScriptingEnabled } = await import("./scripting_guard.js");
expect(() => assertScriptingEnabled()).not.toThrow();
});
});
describe("assertSqlConsoleEnabled", () => {
- it("should throw when SQL console is disabled and not Electron", async () => {
+ it("should throw when SQL console is disabled", async () => {
mockState.sqlConsoleEnabled = false;
- vi.doMock("./utils.js", () => ({
- isElectron: false,
- default: { isElectron: false }
- }));
-
const { assertSqlConsoleEnabled } = await import("./scripting_guard.js");
- expect(() => assertSqlConsoleEnabled()).toThrowError(
+ expect(() => assertSqlConsoleEnabled()).toThrow(
/SQL console is disabled/
);
});
@@ -98,25 +58,15 @@ describe("scripting_guard", () => {
it("should not throw when SQL console is enabled", async () => {
mockState.sqlConsoleEnabled = true;
- vi.doMock("./utils.js", () => ({
- isElectron: false,
- default: { isElectron: false }
- }));
-
const { assertSqlConsoleEnabled } = await import("./scripting_guard.js");
expect(() => assertSqlConsoleEnabled()).not.toThrow();
});
});
describe("isScriptingEnabled", () => {
- it("should return false when disabled and not Electron", async () => {
+ it("should return false when disabled", async () => {
mockState.scriptingEnabled = false;
- vi.doMock("./utils.js", () => ({
- isElectron: false,
- default: { isElectron: false }
- }));
-
const { isScriptingEnabled } = await import("./scripting_guard.js");
expect(isScriptingEnabled()).toBe(false);
});
@@ -124,23 +74,6 @@ describe("scripting_guard", () => {
it("should return true when enabled", async () => {
mockState.scriptingEnabled = true;
- vi.doMock("./utils.js", () => ({
- isElectron: false,
- default: { isElectron: false }
- }));
-
- const { isScriptingEnabled } = await import("./scripting_guard.js");
- expect(isScriptingEnabled()).toBe(true);
- });
-
- it("should return true when isElectron is true", async () => {
- mockState.scriptingEnabled = false;
-
- vi.doMock("./utils.js", () => ({
- isElectron: true,
- default: { isElectron: true }
- }));
-
const { isScriptingEnabled } = await import("./scripting_guard.js");
expect(isScriptingEnabled()).toBe(true);
});
diff --git a/apps/server/src/services/scripting_guard.ts b/apps/server/src/services/scripting_guard.ts
index 7d0c3655b1..b2d94c4d98 100644
--- a/apps/server/src/services/scripting_guard.ts
+++ b/apps/server/src/services/scripting_guard.ts
@@ -1,11 +1,10 @@
import config from "./config.js";
-import { isElectron } from "./utils.js";
/**
- * Throws if backend scripting is disabled. Desktop (Electron) always allows scripting.
+ * Throws if backend scripting is disabled.
*/
export function assertScriptingEnabled(): void {
- if (isElectron || config.Scripting.backendScriptingEnabled) {
+ if (config.Scripting.backendScriptingEnabled) {
return;
}
throw new Error(
@@ -15,7 +14,7 @@ export function assertScriptingEnabled(): void {
}
export function assertSqlConsoleEnabled(): void {
- if (isElectron || config.Scripting.sqlConsoleEnabled) {
+ if (config.Scripting.sqlConsoleEnabled) {
return;
}
throw new Error(
@@ -24,5 +23,5 @@ export function assertSqlConsoleEnabled(): void {
}
export function isScriptingEnabled(): boolean {
- return isElectron || config.Scripting.backendScriptingEnabled;
+ return config.Scripting.backendScriptingEnabled;
}
diff --git a/packages/trilium-core/src/services/scripting_guard.ts b/packages/trilium-core/src/services/scripting_guard.ts
index ba9efcc9bb..b2d94c4d98 100644
--- a/packages/trilium-core/src/services/scripting_guard.ts
+++ b/packages/trilium-core/src/services/scripting_guard.ts
@@ -1,11 +1,10 @@
import config from "./config.js";
-import { isElectron } from "./utils/index.js";
/**
- * Throws if backend scripting is disabled. Desktop (Electron) always allows scripting.
+ * Throws if backend scripting is disabled.
*/
export function assertScriptingEnabled(): void {
- if (isElectron() || config.Scripting.backendScriptingEnabled) {
+ if (config.Scripting.backendScriptingEnabled) {
return;
}
throw new Error(
@@ -15,7 +14,7 @@ export function assertScriptingEnabled(): void {
}
export function assertSqlConsoleEnabled(): void {
- if (isElectron() || config.Scripting.sqlConsoleEnabled) {
+ if (config.Scripting.sqlConsoleEnabled) {
return;
}
throw new Error(
@@ -24,5 +23,5 @@ export function assertSqlConsoleEnabled(): void {
}
export function isScriptingEnabled(): boolean {
- return isElectron() || config.Scripting.backendScriptingEnabled;
+ return config.Scripting.backendScriptingEnabled;
}