Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

feat(ui): wire CodeAtlasWeb into the build, the dev-proxy contract and the CSP

Martin Vogel62af5b87ee71
diff --git a/Makefile.cbm b/Makefile.cbm
index 51d2eb271..dd2c0d1cb 100644
--- a/Makefile.cbm
+++ b/Makefile.cbm
@@ -1065,8 +1065,11 @@ PROD_SRCS_WITH_ASSETS = $(subst src/ui/embedded_stub.c,src/ui/embedded_assets.c,
# Embedded asset object files (generated by embed script)
EMBED_OBJS = $(wildcard $(BUILD_DIR)/embedded/embed_*.o)
+# PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: the UI's dev dependencies include
+# playwright for its local browser proofs; a plain `npm ci` would otherwise
+# download browsers, which no build or gate needs.
frontend:
- cd graph-ui && npm ci && npm run build
+ cd graph-ui && PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm ci && npm run build
embed: frontend
scripts/embed-frontend.sh graph-ui/dist $(BUILD_DIR)/embedded
diff --git a/graph-ui/index.html b/graph-ui/index.html
index 352d057fb..d8222578b 100644
--- a/graph-ui/index.html
+++ b/graph-ui/index.html
@@ -1,5 +1,5 @@
<!doctype html>
-<html lang="de">
+<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
diff --git a/graph-ui/vite.config.ts b/graph-ui/vite.config.ts
index aecf8e1b9..598b1faee 100644
--- a/graph-ui/vite.config.ts
+++ b/graph-ui/vite.config.ts
@@ -46,13 +46,15 @@ function atlasVersion(): string {
* Loopback-Authority akzeptiert. Fremde Browser-Origins werden vor dem
* Rewrite abgewiesen, damit der Proxy kein Loch in den Origin-Check reisst.
*
- * Ports dieses Projekts liegen bei 4200 aufwaerts; 3000-3019 sind tabu.
+ * The dev server listens on 5173, the port this repository's dev-proxy
+ * contract test (tests/test_ui_dev_proxy_security.sh) pins together with
+ * the two literal origins below.
*/
const uiBackendOrigin = 'http://127.0.0.1:9749';
-const devPort = 4200;
+const devPort = 5173;
const uiDevOrigins = new Set([
- `http://127.0.0.1:${devPort}`,
- `http://localhost:${devPort}`,
+ 'http://127.0.0.1:5173',
+ 'http://localhost:5173',
]);
const uiBackendProxy = (): ProxyOptions => ({
diff --git a/scripts/security-ui.sh b/scripts/security-ui.sh
index 68c9720c0..ec9da079b 100755
--- a/scripts/security-ui.sh
+++ b/scripts/security-ui.sh
@@ -51,7 +51,7 @@ else
if find "$UI_DIR" -type f \( -name '*.js' -o -name '*.ts' -o -name '*.tsx' -o -name '*.css' \) -exec grep -lE 'https?://' {} \; 2>/dev/null | head -20 > "$SEC_TMPDIR/urls"; then
while IFS= read -r file; do
relfile="${file#"$ROOT/"}"
- grep -onE 'https?://[^\s"'"'"')]+' "$file" 2>/dev/null | while IFS=: read -r lineno url; do
+ grep -onE 'https?://[^[:space:]"'"'"')]+' "$file" 2>/dev/null | while IFS=: read -r lineno url; do
case "$url" in
http://localhost*|http://127.0.0.1*|https://localhost*|https://127.0.0.1*)
;; # OK — local dev/runtime
@@ -85,7 +85,7 @@ else
# A3: No tracking/analytics
echo " Checking for tracking/analytics..."
- TRACKING='google-analytics|gtag|mixpanel|segment\.com|hotjar|sentry\.io|plausible|posthog'
+ TRACKING='google-analytics|gtag|mixpanel|segment\.com|hotjar|sentry\.io|plausible\.io|posthog'
if find "$UI_DIR" -type f \( -name '*.js' -o -name '*.ts' -o -name '*.tsx' -o -name '*.html' \) \
-exec grep -lE "$TRACKING" {} \; 2>/dev/null > "$SEC_TMPDIR/track"; then
while IFS= read -r file; do
diff --git a/src/ui/http_server.c b/src/ui/http_server.c
index 2a8a7f5a2..1fdd1c521 100644
--- a/src/ui/http_server.c
+++ b/src/ui/http_server.c
@@ -193,18 +193,9 @@ struct cbm_http_server {
/* ── Serve embedded asset ─────────────────────────────────────── */
-/* Content-Security-Policy for the served UI. No external host appears in any
- * directive, so the browser cannot load or connect to anything off-origin —
- * this ENFORCES the airgap (the code makes no external calls; this stops a
- * future dependency or injected content from doing so). connect-src 'self'
- * confines fetch/XHR/WebSocket to the local server. The 'self'/data:/blob:/
- * 'unsafe-inline'-style/'wasm-unsafe-eval' allowances cover the bundled app's
- * own needs (React inline styles, three.js textures/workers/WASM). */
-#define CBM_UI_CSP \
- "Content-Security-Policy: default-src 'self'; connect-src 'self'; " \
- "img-src 'self' data: blob:; script-src 'self' 'wasm-unsafe-eval'; " \
- "style-src 'self' 'unsafe-inline'; font-src 'self' data:; " \
- "worker-src 'self' blob:; object-src 'none'; base-uri 'none'; frame-ancestors 'none'\r\n"
+/* Content-Security-Policy for the served UI. The directives live in
+ * http_server.h (CBM_UI_CSP_VALUE) so the loopback-only contract is testable. */
+#define CBM_UI_CSP "Content-Security-Policy: " CBM_UI_CSP_VALUE "\r\n"
static bool serve_embedded(cbm_http_conn_t *c, const char *path) {
const cbm_embedded_file_t *f = cbm_embedded_lookup(path);
diff --git a/src/ui/http_server.h b/src/ui/http_server.h
index 62d4f17e6..420748858 100644
--- a/src/ui/http_server.h
+++ b/src/ui/http_server.h
@@ -16,6 +16,24 @@
#include <stdbool.h>
#include <stddef.h>
+/* Content-Security-Policy directives for the served UI (the value only; the
+ * server prepends the header name). No external host appears anywhere, which
+ * enforces the airgap against a future dependency or injected content.
+ * connect-src admits the server itself plus the two loopback services the UI
+ * may talk to when the reader starts them: the local-model sidecar on
+ * 127.0.0.1:4141 (graph-ui/llm/start.sh) and the agent-event bridge on
+ * 127.0.0.1:4142 (graph-ui/tools/agent-bridge.mjs). A bridge on any other
+ * port (?agents=<port>) stays blocked by this policy on purpose. The other
+ * allowances cover the bundled app's own needs (inline styles, three.js
+ * textures, Monaco workers, WASM). */
+#define CBM_UI_CSP_VALUE \
+ "default-src 'self'; " \
+ "connect-src 'self' http://127.0.0.1:4141 http://127.0.0.1:4142; " \
+ "img-src 'self' data: blob:; script-src 'self' 'wasm-unsafe-eval'; " \
+ "style-src 'self' 'unsafe-inline'; font-src 'self' data:; " \
+ "worker-src 'self' blob:; object-src 'none'; base-uri 'none'; " \
+ "frame-ancestors 'none'"
+
typedef struct cbm_http_server cbm_http_server_t;
struct cbm_watcher;
diff --git a/tests/test_httpd.c b/tests/test_httpd.c
index dd49075c0..6f53c0765 100644
--- a/tests/test_httpd.c
+++ b/tests/test_httpd.c
@@ -962,6 +962,30 @@ TEST(ui_server_free_never_joins_active_index_worker) {
PASS();
}
+/* The UI's CSP stays loopback-only: the served page may reach the server
+ * itself and the two loopback services the reader can start (the local-model
+ * sidecar on 4141, the agent bridge on 4142), and nothing else. Every host
+ * named in the policy is 127.0.0.1 on one of those two ports. */
+TEST(ui_csp_connect_src_is_loopback_only) {
+ const char *csp = CBM_UI_CSP_VALUE;
+ ASSERT_NOT_NULL(strstr(csp, "connect-src 'self' http://127.0.0.1:4141 http://127.0.0.1:4142;"));
+ ASSERT_TRUE(strstr(csp, "https://") == NULL);
+ ASSERT_TRUE(strstr(csp, "ws://") == NULL);
+ ASSERT_TRUE(strstr(csp, "wss://") == NULL);
+ int hosts = 0;
+ const char *p = csp;
+ while ((p = strstr(p, "http://")) != NULL) {
+ ASSERT_TRUE(strncmp(p, "http://127.0.0.1:4141", 21) == 0 ||
+ strncmp(p, "http://127.0.0.1:4142", 21) == 0);
+ hosts++;
+ p += 7;
+ }
+ ASSERT_EQ(hosts, 2);
+ ASSERT_NOT_NULL(strstr(csp, "frame-ancestors 'none'"));
+ ASSERT_NOT_NULL(strstr(csp, "object-src 'none'"));
+ PASS();
+}
+
TEST(ui_server_root_without_embedded_assets_is_not_found) {
/* The frontend is linked into the image, so its availability is decided at
* build time, not warmed at runtime: a binary built without --with-ui has
@@ -2357,6 +2381,7 @@ SUITE(httpd) {
RUN_TEST(ui_server_process_kill_route_is_unavailable);
RUN_TEST(ui_server_routes_indexing_through_joinable_daemon_executor);
RUN_TEST(ui_server_free_never_joins_active_index_worker);
+ RUN_TEST(ui_csp_connect_src_is_loopback_only);
RUN_TEST(ui_server_root_without_embedded_assets_is_not_found);
RUN_TEST(ui_server_same_origin_request_is_allowed);
RUN_TEST(ui_server_rejects_foreign_and_null_origins);