Skip to content

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

fix: pin ALL Chrome connections (subresources/XHR), not just main-frame doc (#2068)

Adam Eivyb15ff72e3f7f
diff --git a/server/services/browserService.js b/server/services/browserService.js
index f0f91257b2..90d191327c 100644
--- a/server/services/browserService.js
+++ b/server/services/browserService.js
@@ -352,20 +352,49 @@ async function closeCdpPage(id) {
await cdpRequest(`/json/close/${id}`, { timeout: HEALTH_TIMEOUT_MS }).catch(() => {});
}
+// Every address Chrome ACTUALLY dialed across the capture window — the main
+// document, its redirects, AND every sub-resource / XHR / fetch the page issued
+// (any request type), each with a non-empty `remoteIPAddress`. Empty IPs
+// (data:/blob:/cache/service-worker responses — no network connection) are
+// omitted so legit pages aren't false-refused. Pure; exported for testing.
+export function collectConnectedIps(messages) {
+ const out = [];
+ for (const msg of messages) {
+ const p = msg?.params;
+ if (!p) continue;
+ if (msg.method === 'Network.requestWillBeSent' && p.redirectResponse?.remoteIPAddress) {
+ out.push({ url: p.redirectResponse.url || null, remoteIPAddress: p.redirectResponse.remoteIPAddress });
+ } else if (msg.method === 'Network.responseReceived' && p.response?.remoteIPAddress) {
+ out.push({ url: p.response.url || null, remoteIPAddress: p.response.remoteIPAddress });
+ }
+ }
+ return out;
+}
+
// Pure gate over a captured CDP message stream: returns a refusal reason string,
-// or null when every main-frame hop connected to an allowed address and no
-// top-level navigation is still in flight. Exported for unit testing.
+// or null when the navigation is safe to read. Exported for unit testing.
export function ssrfPinRefusalReason(messages, verifyRemoteIp, url) {
const { hops, pendingMainRequestIds } = pickMainFrameHops(messages);
if (!hops.length) return 'no main-frame document response was observed';
+ // The main document must have a verifiable (present) connection IP — an empty
+ // one can't be checked, so fail closed.
for (const hop of hops) {
- if (!hop.remoteIPAddress || !verifyRemoteIp(hop.remoteIPAddress)) {
- return `Chrome connected to a disallowed address ${hop.remoteIPAddress || '(unknown)'} for ${hop.url || url}`;
- }
+ if (!hop.remoteIPAddress) return `Chrome connected to an unverifiable address for ${hop.url || url}`;
}
// A top-level navigation that STARTED but produced no response was never
// pinned — Chrome could be mid-connect to a private/metadata target.
if (pendingMainRequestIds.length) return 'a top-level navigation was still in flight (unpinned)';
+ // EVERY connection Chrome made must dial an allowed address — not just the
+ // main document. A rebinding page can load public, then `fetch()` its
+ // now-private-resolving hostname; the browser treats it as same-origin, JS
+ // injects that private response into the DOM we ingest, and the sub-resource's
+ // real `remoteIPAddress` surfaces it here. (`isBlockedIngestHost` blocks only
+ // loopback/link-local/metadata, not RFC1918 LAN, so LAN pages aren't refused.)
+ for (const conn of collectConnectedIps(messages)) {
+ if (!verifyRemoteIp(conn.remoteIPAddress)) {
+ return `Chrome connected to a disallowed address ${conn.remoteIPAddress} for ${conn.url || url}`;
+ }
+ }
return null;
}
diff --git a/server/services/browserService.test.js b/server/services/browserService.test.js
index 1e8890b916..361bc3902c 100644
--- a/server/services/browserService.test.js
+++ b/server/services/browserService.test.js
@@ -192,11 +192,42 @@ describe('ssrfPinRefusalReason (SSRF pin gate)', () => {
expect(ssrfPinRefusalReason([], allow, 'https://ex.com/a')).toMatch(/no main-frame document response/);
});
- it('refuses a hop with a missing/empty remote IP (unverifiable)', () => {
+ it('refuses a main document with a missing/empty remote IP (unverifiable)', () => {
const reason = ssrfPinRefusalReason([
docRequest('R1', 'https://ex.com/a'),
docResponse('R1', 'https://ex.com/a', ''),
], allow, 'https://ex.com/a');
- expect(reason).toMatch(/disallowed address \(unknown\)/);
+ expect(reason).toMatch(/unverifiable address/);
+ });
+
+ it('refuses a SUB-RESOURCE / fetch that dialed a blocked IP (rebind after page load)', () => {
+ // Main doc loads clean from public, then the page fetch()es its now-private-
+ // resolving hostname (a subresource, type XHR). Its real IP must be checked.
+ const reason = ssrfPinRefusalReason([
+ docRequest('R1', 'https://ex.com/a'),
+ docResponse('R1', 'https://ex.com/a', '93.184.216.34'),
+ { method: 'Network.responseReceived', params: { requestId: 'R2', type: 'XHR', response: { url: 'https://ex.com/latest/meta-data', remoteIPAddress: '169.254.169.254', status: 200 } } },
+ ], allow, 'https://ex.com/a');
+ expect(reason).toMatch(/disallowed address 169\.254\.169\.254/);
+ });
+
+ it('ignores sub-resources with an empty remote IP (data:/blob:/cache — no connection)', () => {
+ const reason = ssrfPinRefusalReason([
+ docRequest('R1', 'https://ex.com/a'),
+ docResponse('R1', 'https://ex.com/a', '93.184.216.34'),
+ { method: 'Network.responseReceived', params: { requestId: 'R2', type: 'Image', response: { url: 'data:image/png;base64,AAAA', remoteIPAddress: '', status: 200 } } },
+ ], allow, 'https://ex.com/a');
+ expect(reason).toBeNull();
+ });
+
+ it('allows an RFC1918 LAN sub-resource (only loopback/link-local/metadata are blocked)', () => {
+ // isBlockedIngestHost does NOT block 192.168/10/172.16 — LAN pages stay ingestible.
+ const lanAllow = (ip) => !ip.startsWith('127.') && !ip.startsWith('169.254.');
+ const reason = ssrfPinRefusalReason([
+ docRequest('R1', 'https://wiki.lan/a'),
+ docResponse('R1', 'https://wiki.lan/a', '192.168.1.10'),
+ { method: 'Network.responseReceived', params: { requestId: 'R2', type: 'Script', response: { url: 'https://wiki.lan/app.js', remoteIPAddress: '192.168.1.10', status: 200 } } },
+ ], lanAllow, 'https://wiki.lan/a');
+ expect(reason).toBeNull();
});
});