Skip to content

Build your personal knowledge base with Trilium Notes

feat(settings): expose desktop LAN access toggle in the Security tab

Elian Doran6de06f143ad5
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 65704400ce..22722447a3 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1659,6 +1659,10 @@
"sql_console_section_description": "The SQL console allows running raw SQL queries against the database. This can be used to read sensitive data (e.g. sync secrets, API keys) and alter or delete any data. A malicious frontend script could also access the SQL console API programmatically.",
"sql_console_label": "SQL console",
"sql_console_description": "Allow execution of queries in the SQL console.",
+ "lan_access_title": "Network access",
+ "lan_access_section_description": "By default the desktop app only accepts connections from this computer. Allow access from your local network so other devices can connect to it — for example to sync from another device. Only enable this on networks you trust.",
+ "lan_access_label": "Allow connections from other devices",
+ "lan_access_description": "Bind the server to all network interfaces instead of localhost only.",
"how_to_enable": "How to enable",
"server_config_hint": "Add the following to your config.ini file:",
"server_env_hint": "Or set the following environment variable:",
diff --git a/apps/client/src/widgets/type_widgets/options/security.tsx b/apps/client/src/widgets/type_widgets/options/security.tsx
index 3ce9579776..ae123fd3f3 100644
--- a/apps/client/src/widgets/type_widgets/options/security.tsx
+++ b/apps/client/src/widgets/type_widgets/options/security.tsx
@@ -14,13 +14,16 @@ export default function SecuritySettings() {
// null = no change made yet, use the live config value.
const [pendingBackendScripting, setPendingBackendScripting] = useState<boolean | null>(null);
const [pendingSqlConsole, setPendingSqlConsole] = useState<boolean | null>(null);
+ const [pendingLanAccess, setPendingLanAccess] = useState<boolean | null>(null);
const [liveBackendScripting] = useTriliumOptionBool("backendScriptingEnabled");
const [liveSqlConsole] = useTriliumOptionBool("sqlConsoleEnabled");
+ const [liveLanAccess] = useTriliumOptionBool("allowLanAccess");
const hasPendingChanges =
(pendingBackendScripting !== null && pendingBackendScripting !== liveBackendScripting) ||
- (pendingSqlConsole !== null && pendingSqlConsole !== liveSqlConsole);
+ (pendingSqlConsole !== null && pendingSqlConsole !== liveSqlConsole) ||
+ (pendingLanAccess !== null && pendingLanAccess !== liveLanAccess);
return (
<>
@@ -35,6 +38,13 @@ export default function SecuritySettings() {
pendingValue={pendingSqlConsole}
setPendingValue={setPendingSqlConsole}
/>
+ {isElectron() && (
+ <LanAccessSettings
+ liveValue={liveLanAccess}
+ pendingValue={pendingLanAccess}
+ setPendingValue={setPendingLanAccess}
+ />
+ )}
{hasPendingChanges && isElectron() && (
<OptionsSection noCard>
<OptionsRow name="restart" centered>
@@ -145,3 +155,35 @@ function SqlConsoleSettings({ liveValue, pendingValue, setPendingValue }: Toggle
</OptionsSection>
);
}
+
+// Desktop only: a server build is already reachable on its bound interface
+// (configured via [Network] host), so this toggle is gated behind isElectron()
+// by the caller.
+function LanAccessSettings({ liveValue, pendingValue, setPendingValue }: ToggleSectionProps) {
+ const displayValue = pendingValue ?? liveValue;
+ const hasPendingChange = pendingValue !== null && pendingValue !== liveValue;
+
+ async function handleToggle(enabled: boolean) {
+ const confirmed = await window.electronApi!.security.setLanAccessEnabled(enabled);
+ if (confirmed) {
+ setPendingValue(enabled === liveValue ? null : enabled);
+ }
+ }
+
+ return (
+ <OptionsSection
+ title={t("security.lan_access_title")}
+ description={t("security.lan_access_section_description")}
+ >
+ <OptionsRowWithToggle
+ name="lan-access-enabled"
+ label={t("security.lan_access_label")}
+ description={hasPendingChange
+ ? t("security.restart_required")
+ : t("security.lan_access_description")}
+ currentValue={displayValue}
+ onChange={handleToggle}
+ />
+ </OptionsSection>
+ );
+}
diff --git a/apps/desktop/src/services/security_settings.spec.ts b/apps/desktop/src/services/security_settings.spec.ts
index 98ef0df2df..406ccfc365 100644
--- a/apps/desktop/src/services/security_settings.spec.ts
+++ b/apps/desktop/src/services/security_settings.spec.ts
@@ -98,6 +98,15 @@ describe("security_settings", () => {
expect(result).toBe(false);
expect(h.fileStore.has(SETTINGS_PATH)).toBe(false);
});
+
+ it("registers and persists the LAN access toggle", async () => {
+ h.showMessageBox.mockResolvedValue({ response: 1, checkboxChecked: false });
+
+ const result = await invoke("security-set-lan-access", true);
+
+ expect(result).toBe(true);
+ expect(JSON.parse(h.fileStore.get(SETTINGS_PATH) ?? "{}")).toEqual({ allowLanAccess: true });
+ });
});
describe("registerSecurityIpcHandlers — disabling", () => {
diff --git a/packages/commons/src/lib/options_interface.ts b/packages/commons/src/lib/options_interface.ts
index 6a1e7e92ca..c84a3d4852 100644
--- a/packages/commons/src/lib/options_interface.ts
+++ b/packages/commons/src/lib/options_interface.ts
@@ -146,6 +146,7 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
databaseReadonly: boolean;
backendScriptingEnabled: boolean;
sqlConsoleEnabled: boolean;
+ allowLanAccess: boolean;
hasUserBackendScripts: boolean;
isPasswordSet: boolean;
overrideThemeFonts: boolean;
diff --git a/packages/trilium-core/src/routes/api/options.ts b/packages/trilium-core/src/routes/api/options.ts
index 1c96e88e1c..0c0b1c59f8 100644
--- a/packages/trilium-core/src/routes/api/options.ts
+++ b/packages/trilium-core/src/routes/api/options.ts
@@ -160,6 +160,8 @@ function getOptions() {
// Expose scripting config (read-only, from config.ini / env vars)
resultMap["backendScriptingEnabled"] = config.Security.backendScriptingEnabled ? "true" : "false";
resultMap["sqlConsoleEnabled"] = config.Security.sqlConsoleEnabled ? "true" : "false";
+ // Desktop LAN-access override (read-only; toggled via the Electron security bridge)
+ resultMap["allowLanAccess"] = config.Security.allowLanAccess ? "true" : "false";
// Detect if the user has any backend scripts with #run labels (backendStartup, hourly, daily).
// Filter by MIME type since #run can also appear on frontend scripts.
diff --git a/packages/trilium-core/src/services/config.ts b/packages/trilium-core/src/services/config.ts
index 9b30a09352..8fb128d18b 100644
--- a/packages/trilium-core/src/services/config.ts
+++ b/packages/trilium-core/src/services/config.ts
@@ -22,6 +22,7 @@ export interface CoreConfig {
Security: {
backendScriptingEnabled: boolean;
sqlConsoleEnabled: boolean;
+ allowLanAccess: boolean;
};
}
@@ -37,7 +38,8 @@ const EMPTY_CONFIG: CoreConfig = {
},
Security: {
backendScriptingEnabled: false,
- sqlConsoleEnabled: false
+ sqlConsoleEnabled: false,
+ allowLanAccess: false
}
};