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.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
Audit all Lens source URLs with scoped fixture exceptions
Martin Vogel1a073040ef62
diff --git a/.github/workflows/_security.yml b/.github/workflows/_security.ymlindex 2e52b6d10..f1cf88bd5 100644--- a/.github/workflows/_security.yml+++ b/.github/workflows/_security.yml@@ -25,7 +25,9 @@ jobs:bash tests/test_security_audit_subprocess_calls.shscripts/security-audit.sh- name: "Layer 6: UI security audit"- run: scripts/security-ui.sh+ run: |+ bash tests/test_security_ui_urls.sh+ scripts/security-ui.sh- name: "Layer 8: Vendored dependency integrity"run: scripts/security-vendored.shdiff --git a/graph-ui/src/app/atlas-api.test.ts b/graph-ui/src/app/atlas-api.test.tsindex 82f746b0e..5d1c18a9e 100644--- a/graph-ui/src/app/atlas-api.test.ts+++ b/graph-ui/src/app/atlas-api.test.ts@@ -7,6 +7,7 @@import { describe, expect, it } from 'vitest';import { AtlasApi, AtlasApiError } from './atlas-api';+import { observeErrors, type ErrorReport } from '../provider/error-observer';interface FetchCall {url: string;@@ -34,6 +35,37 @@ function api(reply: { ok?: boolean; status?: number; body: string }): { api: Atl}describe('AtlasApi, the projects routes', () => {+ it.each(['', 'http://127.0.0.1:9749'])('attributes failed requests to their decoded project with base %s', async (base) => {+ const reports: ErrorReport[] = [];+ const stopObserving = observeErrors((report) => reports.push(report));+ const calls: FetchCall[] = [];+ const client = new AtlasApi({+ base,+ fetch: recordingFetch({ ok: false, status: 503, body: '{"error":"unavailable"}' }, calls),+ });+ try {+ await expect(client.logs(20, 'warn', 'a repo&revision=2')).rejects.toBeInstanceOf(AtlasApiError);+ expect(calls[0]?.url).toBe(`${base}/api/logs?lines=20&min_level=warn&project=a+repo%26revision%3D2`);+ expect(reports).toEqual([expect.objectContaining({+ source: 'api', level: 'error', project: 'a repo&revision=2',+ })]);+ } finally {+ stopObserving();+ }+ });++ it('does not invent a project for failed requests without one', async () => {+ const reports: ErrorReport[] = [];+ const stopObserving = observeErrors((report) => reports.push(report));+ const { api: client } = api({ ok: false, status: 503, body: '{"error":"unavailable"}' });+ try {+ await expect(client.logs(20)).rejects.toBeInstanceOf(AtlasApiError);+ expect(reports).toEqual([expect.objectContaining({ project: '' })]);+ } finally {+ stopObserving();+ }+ });+it('encodes history filters without interpreting search as URL parameters', async () => {const { api: client, calls } = api({ body: '{"lines":[],"total":0,"query":"path&level=info"}' });const result = await client.logs(200, 'error', undefined, { scope: 'unattributed', query: 'path&level=info' });diff --git a/graph-ui/src/app/atlas-api.ts b/graph-ui/src/app/atlas-api.tsindex add605fa4..316303e8f 100644--- a/graph-ui/src/app/atlas-api.ts+++ b/graph-ui/src/app/atlas-api.ts@@ -87,7 +87,7 @@ function announce(error: AtlasApiError, detail?: string): AtlasApiError {const refused = error.status >= 400 && error.status < 500;reportError({source: 'api',- project: new URL(error.route, 'http://daemon.invalid').searchParams.get('project') ?? '',+ project: new URL(error.route, 'http://127.0.0.1').searchParams.get('project') ?? '',level: refused ? 'warn' : 'error',message: error.message,detail,diff --git a/scripts/security-ui.sh b/scripts/security-ui.shindex 3d990a6f8..7fabbec67 100755--- a/scripts/security-ui.sh+++ b/scripts/security-ui.sh@@ -15,7 +15,7 @@ ROOT="$(cd "$(dirname "$0")/.." && pwd)"FAIL=0# Only the pinned opt-in model policy may declare these external locations.-# Negative URL fixtures are confined to the four named boundary tests.+# Inert URL fixtures are confined to the individually reviewed tests below.browser_model_source_url_allowed() {local relfile="$1" url="$2"case "$relfile" in@@ -34,7 +34,18 @@ browser_model_source_url_allowed() {graph-ui/src/browser-ai/model-policy.test.ts|\graph-ui/src/browser-ai/security-download-origins.test.ts|\graph-ui/src/browser-ai/security-ui-model-policy.test.ts|\- graph-ui/src/browser-ai/ChatMarkdown.test.tsx) return 0 ;;+ graph-ui/src/browser-ai/ChatMarkdown.test.tsx|\+ graph-ui/src/adr/AdrWorkspace.test.tsx|\+ graph-ui/src/architecture/SourceEvidenceDrawer.test.tsx|\+ graph-ui/src/architecture/container-topology.test.ts|\+ graph-ui/src/architecture/repository-guide.test.ts|\+ graph-ui/src/browser-ai/BrowserChatDock.ask-model.test.tsx|\+ graph-ui/src/browser-ai/BrowserChatDock.test.tsx|\+ graph-ui/src/browser-ai/explanation-response.test.ts|\+ graph-ui/src/browser-ai/file-facts.test.ts|\+ graph-ui/src/browser-ai/file-outline.ini.test.ts|\+ graph-ui/src/browser-ai/file-outline.test.ts|\+ graph-ui/src/settings/model-catalog.test.ts) return 0 ;;esacreturn 1}@@ -73,7 +84,7 @@ elseif ! $is_dist; thenecho " Checking for external domains (source)..."- 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+ if find "$UI_DIR" -type f \( -name '*.js' -o -name '*.ts' -o -name '*.tsx' -o -name '*.css' \) -exec grep -lE 'https?://' {} \; 2>/dev/null > "$SEC_TMPDIR/urls"; thenwhile IFS= read -r file; dorelfile="${file#"$ROOT/"}"grep -onE 'https?://[^[:space:]"'"'"')]+' "$file" 2>/dev/null | while IFS=: read -r lineno url; dodiff --git a/tests/test_security_ui_urls.sh b/tests/test_security_ui_urls.shnew file mode 100644index 000000000..b844b4490--- /dev/null+++ b/tests/test_security_ui_urls.sh@@ -0,0 +1,107 @@+#!/usr/bin/env bash+set -euo pipefail++# Run the actual UI audit against isolated source trees. No fixture makes a+# network request, and no exception is granted to arbitrary test filenames.+ROOT="$(cd "$(dirname "$0")/.." && pwd)"+TEST_TMPDIR=$(mktemp -d)+trap 'rm -rf "$TEST_TMPDIR"' EXIT+CASES=0+FAILED=0+FIXTURE=''++new_fixture() {+ CASES=$((CASES + 1))+ FIXTURE="$TEST_TMPDIR/case-$CASES"+ mkdir -p "$FIXTURE/scripts" "$FIXTURE/graph-ui/src" "$FIXTURE/src/ui"+ cp "$ROOT/scripts/security-ui.sh" "$FIXTURE/scripts/security-ui.sh"+ printf 'static const char *bind_address = "127.0.0.1";\n' > "$FIXTURE/src/ui/httpd.c"+ printf '// Local request handlers.\n' > "$FIXTURE/src/ui/http_server.c"+}++source_url() {+ local relative_path="$1" url="$2"+ mkdir -p "$(dirname "$FIXTURE/graph-ui/src/$relative_path")"+ printf 'export const fixtureUrl = "%s";\n' "$url" > "$FIXTURE/graph-ui/src/$relative_path"+}++expect_allowed() {+ local label="$1"+ if bash "$FIXTURE/scripts/security-ui.sh" > "$FIXTURE/result.log" 2>&1; then+ printf 'PASS: %s\n' "$label"+ else+ printf 'FAIL: %s should pass\n' "$label"+ cat "$FIXTURE/result.log"+ FAILED=$((FAILED + 1))+ fi+}++expect_blocked() {+ local label="$1" relative_path="$2"+ if bash "$FIXTURE/scripts/security-ui.sh" > "$FIXTURE/result.log" 2>&1; then+ printf 'FAIL: %s should fail\n' "$label"+ FAILED=$((FAILED + 1))+ elif grep -F "BLOCKED: graph-ui/src/$relative_path:" "$FIXTURE/result.log" | grep -q 'External URL:'; then+ printf 'PASS: %s\n' "$label"+ else+ printf 'FAIL: %s failed for another reason\n' "$label"+ cat "$FIXTURE/result.log"+ FAILED=$((FAILED + 1))+ fi+}++while IFS= read -r reviewed_fixture; do+ new_fixture+ source_url "$reviewed_fixture" 'https://example.invalid/fixture'+ expect_allowed "reviewed URL fixture $reviewed_fixture"+done <<'FIXTURES'+adr/AdrWorkspace.test.tsx+architecture/SourceEvidenceDrawer.test.tsx+architecture/container-topology.test.ts+architecture/repository-guide.test.ts+browser-ai/BrowserChatDock.ask-model.test.tsx+browser-ai/BrowserChatDock.test.tsx+browser-ai/explanation-response.test.ts+browser-ai/file-facts.test.ts+browser-ai/file-outline.ini.test.ts+browser-ai/file-outline.test.ts+settings/model-catalog.test.ts+FIXTURES++new_fixture+source_url 'browser-ai/other.test.ts' 'https://example.invalid/fixture'+expect_blocked 'an arbitrary test is not exempt' 'browser-ai/other.test.ts'++new_fixture+source_url 'browser-ai/BrowserChatDock.tsx' 'https://example.invalid/runtime'+expect_blocked 'the runtime counterpart is not exempt' 'browser-ai/BrowserChatDock.tsx'++new_fixture+source_url 'counterfeit/browser-ai/BrowserChatDock.test.tsx' 'https://example.invalid/fixture'+expect_blocked 'a matching basename in another directory is not exempt' 'counterfeit/browser-ai/BrowserChatDock.test.tsx'++new_fixture+source_url 'browser-ai/model-policy.ts' 'https://huggingface.co/onnx-community/Qwen2.5-Coder-0.5B-Instruct'+expect_allowed 'the pinned model location remains allowed'++new_fixture+source_url 'browser-ai/model-policy.ts' 'https://huggingface.co/unreviewed/model'+expect_blocked 'an unpinned model location remains blocked' 'browser-ai/model-policy.ts'++new_fixture+source_url 'browser-ai/other.ts' 'https://huggingface.co/onnx-community/Qwen2.5-Coder-0.5B-Instruct'+expect_blocked 'the model location is not allowed outside its policy file' 'browser-ai/other.ts'++new_fixture+for index in $(seq 1 25); do+ source_url "runtime/file-$index.ts" 'http://127.0.0.1/fixture'+done+# Choose the last file in the same traversal used by the scanner, so this+# catches a truncated scan independently of filesystem directory ordering.+last_file=$(find "$FIXTURE/graph-ui/src" -type f -name '*.ts' -exec grep -lE 'https?://' {} \; | tail -n 1)+last_relative="${last_file#"$FIXTURE/graph-ui/src/"}"+source_url "$last_relative" 'https://example.invalid/after-twenty'+expect_blocked 'a forbidden runtime URL after the twentieth file is inspected' "$last_relative"++printf '%s cases, %s failed\n' "$CASES" "$FAILED"+[[ "$FAILED" -eq 0 ]]