Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: gate WebSockets opened to a blocked host during ingest (#2068)
Adam Eivyc45efb32b770
diff --git a/server/services/browserService.js b/server/services/browserService.jsindex 90d191327c..a1f40d2b52 100644--- a/server/services/browserService.js+++ b/server/services/browserService.js@@ -371,6 +371,23 @@ export function collectConnectedIps(messages) {return out;}+// Hosts of every WebSocket the page opened during the capture window. CDP routes+// WS through dedicated `Network.webSocket*` events whose payloads carry NO+// `remoteIPAddress`, so we can only gate the WS by its URL host, not by Chrome's+// actual connect IP (the resolver-level pin HTTP gets). Pure; exported for tests.+export function collectWebSocketHosts(messages) {+ const out = [];+ for (const msg of messages) {+ if (msg?.method !== 'Network.webSocketCreated') continue;+ const raw = msg.params?.url;+ if (typeof raw !== 'string') continue;+ let host = null;+ try { host = new URL(raw).hostname; } catch { host = null; }+ out.push({ url: raw, host });+ }+ return out;+}+// Pure gate over a captured CDP message stream: returns a refusal reason string,// or null when the navigation is safe to read. Exported for unit testing.export function ssrfPinRefusalReason(messages, verifyRemoteIp, url) {@@ -395,6 +412,18 @@ export function ssrfPinRefusalReason(messages, verifyRemoteIp, url) {return `Chrome connected to a disallowed address ${conn.remoteIPAddress} for ${conn.url || url}`;}}+ // WebSockets: CDP exposes no remoteIPAddress for WS, so we can only refuse a WS+ // opened to a blocked HOST (a direct ws://127.0.0.1 / ws://localhost / metadata+ // literal). A WS to a hostname that DNS-rebinds to a private IP is a residual+ // this interception approach can't see — closing it fully needs Chrome-launch+ // `--host-resolver-rules` (a per-navigation relaunch of the shared browser,+ // out of scope here). Bounded by the single-user trust model; cloud metadata,+ // the primary target, is HTTP-only and fully covered above.+ for (const ws of collectWebSocketHosts(messages)) {+ if (!ws.host || !verifyRemoteIp(ws.host)) {+ return `page opened a WebSocket to a disallowed host ${ws.host || '(unparseable)'} (${ws.url})`;+ }+ }return null;}diff --git a/server/services/browserService.test.js b/server/services/browserService.test.jsindex 361bc3902c..84d8fd46f4 100644--- a/server/services/browserService.test.js+++ b/server/services/browserService.test.js@@ -230,4 +230,26 @@ describe('ssrfPinRefusalReason (SSRF pin gate)', () => {], lanAllow, 'https://wiki.lan/a');expect(reason).toBeNull();});++ it('refuses a WebSocket opened to a blocked host literal (ws:// to loopback/localhost)', () => {+ // CDP gives WS no remoteIPAddress, so we gate on the WS host — this catches a+ // direct ws://localhost / ws://127.0.0.1 (host-level, not IP-level, check).+ const hostAllow = (h) => h !== 'localhost' && !h.startsWith('127.') && h !== '::1';+ const reason = ssrfPinRefusalReason([+ docRequest('R1', 'https://ex.com/a'),+ docResponse('R1', 'https://ex.com/a', '93.184.216.34'),+ { method: 'Network.webSocketCreated', params: { requestId: 'W1', url: 'ws://localhost:9222/devtools' } },+ ], hostAllow, 'https://ex.com/a');+ expect(reason).toMatch(/WebSocket to a disallowed host localhost/);+ });++ it('allows a WebSocket to a normal public host', () => {+ const hostAllow = (h) => h !== 'localhost' && !h.startsWith('127.');+ const reason = ssrfPinRefusalReason([+ docRequest('R1', 'https://ex.com/a'),+ docResponse('R1', 'https://ex.com/a', '93.184.216.34'),+ { method: 'Network.webSocketCreated', params: { requestId: 'W1', url: 'wss://realtime.example.com/socket' } },+ ], hostAllow, 'https://ex.com/a');+ expect(reason).toBeNull();+ });});