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
refactor(core): rename scripting settings to security
Elian Doran8cd9e81f28c2
diff --git a/apps/client/src/widgets/type_widgets/options/security.tsx b/apps/client/src/widgets/type_widgets/options/security.tsxindex d3b0fc09de..468c2c61b8 100644--- a/apps/client/src/widgets/type_widgets/options/security.tsx+++ b/apps/client/src/widgets/type_widgets/options/security.tsx@@ -25,7 +25,7 @@ function ServerConfigHint({ configKey, envVar }: { configKey: string; envVar: streturn (<Collapsible title={t("security.how_to_enable")}><p>{t("security.server_config_hint")}</p>- <pre><code>{`[Scripting]\n${configKey}=true`}</code></pre>+ <pre><code>{`[Security]\n${configKey}=true`}</code></pre><p>{t("security.server_env_hint")}</p><pre><code>{envVar}=true</code></pre></Collapsible>@@ -63,7 +63,7 @@ function BackendScriptingSettings() {/><ServerConfigHintconfigKey="backendScriptingEnabled"- envVar="TRILIUM_SCRIPTING_BACKEND_ENABLED"+ envVar="TRILIUM_SECURITY_BACKEND_SCRIPTING_ENABLED"/></OptionsSection>);@@ -100,7 +100,7 @@ function SqlConsoleSettings() {/><ServerConfigHintconfigKey="sqlConsoleEnabled"- envVar="TRILIUM_SCRIPTING_SQLCONSOLEENABLED"+ envVar="TRILIUM_SECURITY_SQL_CONSOLE_ENABLED"/></OptionsSection>);diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex 4d4cbe65be..500103c00f 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -142,10 +142,10 @@ async function main() {// Override scripting config from security.json (lives outside the DB for tamper resistance)const securitySettings = getSecuritySettings();if (securitySettings.backendScriptingEnabled !== undefined) {- config.Scripting.backendScriptingEnabled = securitySettings.backendScriptingEnabled;+ config.Security.backendScriptingEnabled = securitySettings.backendScriptingEnabled;}if (securitySettings.sqlConsoleEnabled !== undefined) {- config.Scripting.sqlConsoleEnabled = securitySettings.sqlConsoleEnabled;+ config.Security.sqlConsoleEnabled = securitySettings.sqlConsoleEnabled;}const dbProvider = new BetterSqlite3Provider();diff --git a/apps/server/src/assets/config-sample.ini b/apps/server/src/assets/config-sample.iniindex 5e19fd8687..bfc5da33f9 100644--- a/apps/server/src/assets/config-sample.ini+++ b/apps/server/src/assets/config-sample.ini@@ -68,7 +68,7 @@ oauthIssuerName=# This is the icon of the service that will be used to verify the user's identityoauthIssuerIcon=-[Scripting]+[Security]# Enable backend script execution. WARNING: Backend scripts have full server access including# filesystem, network, and OS commands via require('child_process'). Only enable if you trust# all users with admin-level access to the server.diff --git a/apps/server/src/services/config.ts b/apps/server/src/services/config.tsindex b6bf3e309a..1a9b877b8b 100644--- a/apps/server/src/services/config.ts+++ b/apps/server/src/services/config.ts@@ -138,8 +138,8 @@ export interface TriliumConfig {*/retentionDays: number;};- /** Scripting and code execution configuration */- Scripting: {+ /** Security and code execution configuration */+ Security: {/** Whether backend script execution is enabled (default: false for server, true for desktop) */backendScriptingEnabled: boolean;/** Whether the SQL console is accessible (default: false) */@@ -471,17 +471,17 @@ const configMapping = {transformer: (value: unknown) => utils.stringToInt(String(value)) ?? LOGGING_DEFAULT_RETENTION_DAYS}},- Scripting: {+ Security: {backendScriptingEnabled: {- standardEnvVar: 'TRILIUM_SCRIPTING_BACKEND_ENABLED',- iniGetter: () => getIniSection("Scripting")?.backendScriptingEnabled,+ standardEnvVar: 'TRILIUM_SECURITY_BACKEND_SCRIPTING_ENABLED',+ iniGetter: () => getIniSection("Security")?.backendScriptingEnabled,defaultValue: false,transformer: transformBoolean},sqlConsoleEnabled: {- standardEnvVar: 'TRILIUM_SCRIPTING_SQLCONSOLEENABLED',- aliasEnvVars: ['TRILIUM_SCRIPTING_SQL_CONSOLE_ENABLED'],- iniGetter: () => getIniSection("Scripting")?.sqlConsoleEnabled,+ standardEnvVar: 'TRILIUM_SECURITY_SQL_CONSOLE_ENABLED',+ aliasEnvVars: ['TRILIUM_SECURITY_SQLCONSOLEENABLED'],+ iniGetter: () => getIniSection("Security")?.sqlConsoleEnabled,defaultValue: false,transformer: transformBoolean}@@ -539,9 +539,9 @@ const config: TriliumConfig = {Logging: {retentionDays: getConfigValue(configMapping.Logging.retentionDays)},- Scripting: {- backendScriptingEnabled: getConfigValue(configMapping.Scripting.backendScriptingEnabled),- sqlConsoleEnabled: getConfigValue(configMapping.Scripting.sqlConsoleEnabled)+ Security: {+ backendScriptingEnabled: getConfigValue(configMapping.Security.backendScriptingEnabled),+ sqlConsoleEnabled: getConfigValue(configMapping.Security.sqlConsoleEnabled)}};diff --git a/apps/server/src/services/scripting_guard.spec.ts b/apps/server/src/services/scripting_guard.spec.tsindex 286928b485..c1d2e1dbd7 100644--- a/apps/server/src/services/scripting_guard.spec.ts+++ b/apps/server/src/services/scripting_guard.spec.ts@@ -6,10 +6,10 @@ const mockState = {sqlConsoleEnabled: false};-// Mock config module so Scripting section can be controlled per test+// Mock config module so Security section can be controlled per testvi.mock("./config.js", () => ({default: {- Scripting: {+ Security: {get backendScriptingEnabled() {return mockState.scriptingEnabled;},diff --git a/apps/server/src/services/scripting_guard.ts b/apps/server/src/services/scripting_guard.tsindex b2d94c4d98..9f307de1d4 100644--- a/apps/server/src/services/scripting_guard.ts+++ b/apps/server/src/services/scripting_guard.ts@@ -4,24 +4,24 @@ import config from "./config.js";* Throws if backend scripting is disabled.*/export function assertScriptingEnabled(): void {- if (config.Scripting.backendScriptingEnabled) {+ if (config.Security.backendScriptingEnabled) {return;}throw new Error(- "Backend script execution is disabled. Set [Scripting] backendScriptingEnabled=true in config.ini or " +- "TRILIUM_SCRIPTING_BACKEND_ENABLED=true to enable. WARNING: Backend scripts have full server access."+ "Backend script execution is disabled. Set [Security] backendScriptingEnabled=true in config.ini or " ++ "TRILIUM_SECURITY_BACKEND_SCRIPTING_ENABLED=true to enable. WARNING: Backend scripts have full server access.");}export function assertSqlConsoleEnabled(): void {- if (config.Scripting.sqlConsoleEnabled) {+ if (config.Security.sqlConsoleEnabled) {return;}throw new Error(- "SQL console is disabled. Set [Scripting] sqlConsoleEnabled=true in config.ini to enable."+ "SQL console is disabled. Set [Security] sqlConsoleEnabled=true in config.ini to enable.");}export function isScriptingEnabled(): boolean {- return config.Scripting.backendScriptingEnabled;+ return config.Security.backendScriptingEnabled;}diff --git a/apps/server/src/share/routes.spec.ts b/apps/server/src/share/routes.spec.tsindex 1fe0024409..f9a0e2f76f 100644--- a/apps/server/src/share/routes.spec.ts+++ b/apps/server/src/share/routes.spec.ts@@ -42,8 +42,8 @@ describe("Share API test", () => {it("renders custom share template", async () => {// Custom EJS templates require scripting to be enabled- const originalEnabled = config.Scripting.backendScriptingEnabled;- config.Scripting.backendScriptingEnabled = true;+ const originalEnabled = config.Security.backendScriptingEnabled;+ config.Security.backendScriptingEnabled = true;try {const response = await supertest(app).get("/share/pQvNLLoHcMwH")@@ -52,7 +52,7 @@ describe("Share API test", () => {expect(response.text).toContain("Content Start");expect(response.text).toContain("Content End");} finally {- config.Scripting.backendScriptingEnabled = originalEnabled;+ config.Security.backendScriptingEnabled = originalEnabled;}});diff --git a/apps/server/src/www.ts b/apps/server/src/www.tsindex 046c205415..1c3b3f80d8 100644--- a/apps/server/src/www.ts+++ b/apps/server/src/www.ts@@ -97,7 +97,7 @@ async function displayStartupMessage() {getLog().info("WARNING: Backend script execution is ENABLED. Backend scripts have full server access including " +"filesystem, network, and OS commands. Only enable in trusted environments.");} else {- getLog().info("Backend script execution is DISABLED. Set [Scripting] backendScriptingEnabled=true in config.ini to enable.");+ getLog().info("Backend script execution is DISABLED. Set [Security] backendScriptingEnabled=true in config.ini to enable.");}getLog().info("");diff --git a/packages/trilium-core/src/routes/api/options.ts b/packages/trilium-core/src/routes/api/options.tsindex 6d6cdcab9f..bb46661e9a 100644--- a/packages/trilium-core/src/routes/api/options.ts+++ b/packages/trilium-core/src/routes/api/options.ts@@ -154,8 +154,8 @@ function getOptions() {optionMap[secretOption] ? "true" : "false";}// Expose scripting config (read-only, from config.ini / env vars)- resultMap["backendScriptingEnabled"] = config.Scripting.backendScriptingEnabled ? "true" : "false";- resultMap["sqlConsoleEnabled"] = config.Scripting.sqlConsoleEnabled ? "true" : "false";+ resultMap["backendScriptingEnabled"] = config.Security.backendScriptingEnabled ? "true" : "false";+ resultMap["sqlConsoleEnabled"] = config.Security.sqlConsoleEnabled ? "true" : "false";// if database is read-only, disable editing in UI by setting 0 hereif (config.General.readOnly) {diff --git a/packages/trilium-core/src/services/config.ts b/packages/trilium-core/src/services/config.tsindex f9014d30cb..9b30a09352 100644--- a/packages/trilium-core/src/services/config.ts+++ b/packages/trilium-core/src/services/config.ts@@ -19,7 +19,7 @@ export interface CoreConfig {syncServerTimeout: string;syncProxy: string;};- Scripting: {+ Security: {backendScriptingEnabled: boolean;sqlConsoleEnabled: boolean;};@@ -35,7 +35,7 @@ const EMPTY_CONFIG: CoreConfig = {syncServerTimeout: "",syncProxy: ""},- Scripting: {+ Security: {backendScriptingEnabled: false,sqlConsoleEnabled: false}diff --git a/packages/trilium-core/src/services/script_context.ts b/packages/trilium-core/src/services/script_context.tsindex 6326466d7e..0076dd035d 100644--- a/packages/trilium-core/src/services/script_context.ts+++ b/packages/trilium-core/src/services/script_context.ts@@ -7,8 +7,8 @@ import { toObject } from "./utils/index.js";* IMPORTANT: This module allowlist/blocklist is a defense-in-depth measure only.* It is NOT a security sandbox. Scripts execute via eval() in the main Node.js* process and can bypass these restrictions through globalThis, process, etc.- * The actual security boundary is the [Scripting] enabled=false config toggle,- * which prevents script execution entirely.+ * The actual security boundary is the [Security] backendScriptingEnabled=false config toggle,+ * which prevents backend script execution entirely.** Modules that are safe for user scripts to require.* Note-based modules (resolved via note title matching) are handled separatelydiff --git a/packages/trilium-core/src/services/scripting_guard.ts b/packages/trilium-core/src/services/scripting_guard.tsindex b2d94c4d98..9f307de1d4 100644--- a/packages/trilium-core/src/services/scripting_guard.ts+++ b/packages/trilium-core/src/services/scripting_guard.ts@@ -4,24 +4,24 @@ import config from "./config.js";* Throws if backend scripting is disabled.*/export function assertScriptingEnabled(): void {- if (config.Scripting.backendScriptingEnabled) {+ if (config.Security.backendScriptingEnabled) {return;}throw new Error(- "Backend script execution is disabled. Set [Scripting] backendScriptingEnabled=true in config.ini or " +- "TRILIUM_SCRIPTING_BACKEND_ENABLED=true to enable. WARNING: Backend scripts have full server access."+ "Backend script execution is disabled. Set [Security] backendScriptingEnabled=true in config.ini or " ++ "TRILIUM_SECURITY_BACKEND_SCRIPTING_ENABLED=true to enable. WARNING: Backend scripts have full server access.");}export function assertSqlConsoleEnabled(): void {- if (config.Scripting.sqlConsoleEnabled) {+ if (config.Security.sqlConsoleEnabled) {return;}throw new Error(- "SQL console is disabled. Set [Scripting] sqlConsoleEnabled=true in config.ini to enable."+ "SQL console is disabled. Set [Security] sqlConsoleEnabled=true in config.ini to enable.");}export function isScriptingEnabled(): boolean {- return config.Scripting.backendScriptingEnabled;+ return config.Security.backendScriptingEnabled;}