Skip to content

Personal AI, On Personal Devices

Python

fix(desktop): allow remote API connections

Haotian Zheng3c68a17ac553
diff --git a/frontend/src-tauri/tauri.conf.json b/frontend/src-tauri/tauri.conf.json
index e48d564d..3cf35457 100644
--- a/frontend/src-tauri/tauri.conf.json
+++ b/frontend/src-tauri/tauri.conf.json
@@ -24,7 +24,7 @@
}
],
"security": {
- "csp": "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; connect-src 'self' http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:*; img-src 'self' data: blob:"
+ "csp": "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; connect-src 'self' http: https: ws: wss:; img-src 'self' data: blob:"
}
},
"bundle": {
diff --git a/tests/deployment/test_desktop_network_policy.py b/tests/deployment/test_desktop_network_policy.py
new file mode 100644
index 00000000..4ded5e02
--- /dev/null
+++ b/tests/deployment/test_desktop_network_policy.py
@@ -0,0 +1,25 @@
+"""Regression guards for the desktop app's outbound network policy."""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent.parent
+TAURI_CONFIG = ROOT / "frontend" / "src-tauri" / "tauri.conf.json"
+
+
+def _csp_sources(directive: str) -> set[str]:
+ config = json.loads(TAURI_CONFIG.read_text(encoding="utf-8"))
+ csp = config["app"]["security"]["csp"]
+ directives = {
+ parts[0]: set(parts[1:]) for item in csp.split(";") if (parts := item.split())
+ }
+ return directives[directive]
+
+
+def test_desktop_csp_allows_remote_api_servers() -> None:
+ """The user-configured API URL may point beyond localhost (#649)."""
+ connect_sources = _csp_sources("connect-src")
+
+ assert {"http:", "https:", "ws:", "wss:"} <= connect_sources