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: scope the connectionless-hop exemption to its own navigation and URL host (#3317)
[._.]/ Adam Eivye61d935f15ea
diff --git a/server/services/browserService.js b/server/services/browserService.jsindex adefdadfd7..ad1713bf5d 100644--- a/server/services/browserService.js+++ b/server/services/browserService.js@@ -288,9 +288,18 @@ export async function navigateToUrl(url) {// connection, it just isn't annotated with the peer address.const NO_NETWORK_SW_SOURCES = new Set(['cache-storage', 'http-cache', 'fallback-code']);+// Hostname of a URL, or null when it isn't parseable. Used wherever the only+// address signal available is the URL itself (WebSockets and connectionless+// hops), never as a substitute for a verified peer IP.+const hostOf = (raw) => {+ if (typeof raw !== 'string') return null;+ try { return new URL(raw).hostname; } catch { return null; }+};+// One main-frame hop from a CDP `Network.Response` (a `responseReceived`// payload or the `redirectResponse` riding on the next request).-const toHop = (r) => ({+const toHop = (r, requestId) => ({+ requestId,url: r.url || null,remoteIPAddress: r.remoteIPAddress || '',status: r.status ?? null,@@ -337,11 +346,13 @@ const describeHopDelivery = (hop) => `no remoteIPAddress; fromServiceWorker=${ho* know, because Chrome resolves DNS itself (the rebinding TOCTOU).** Pure + exported so the SSRF-pin decision is unit-testable without a live- * browser. Returns `{ hops: [{ url, remoteIPAddress, status, fromServiceWorker,- * fromDiskCache, fromPrefetchCache, serviceWorkerResponseSource }], finalUrl,- * mainRequestIds: string[], pendingMainRequestIds: string[] }`. The delivery- * flags ride along so the gate can tell "Chrome dialed somewhere we can't see"- * apart from "Chrome made no connection at all" (see `hopMadeNoConnection`).+ * browser. Returns `{ hops: [{ requestId, url, remoteIPAddress, status,+ * fromServiceWorker, fromDiskCache, fromPrefetchCache,+ * serviceWorkerResponseSource }], finalUrl, mainRequestIds: string[],+ * pendingMainRequestIds: string[] }`. The delivery flags ride along so the gate+ * can tell "Chrome dialed somewhere we can't see" apart from "Chrome made no+ * connection at all" (see `hopMadeNoConnection`), and `requestId` keeps the hops+ * of ONE top-level navigation distinguishable from another's.* `pendingMainRequestIds` are top-level navigations that STARTED but produced no* `responseReceived` in the captured window — i.e. a navigation still in flight* whose final connection IP was never observed. The caller must fail closed on a@@ -375,12 +386,12 @@ export function pickMainFrameHops(messages, topFrameId = null) {mainRequestIds.add(p.requestId);}if (mainRequestIds.has(p.requestId) && p.redirectResponse) {- hops.push(toHop(p.redirectResponse));+ hops.push(toHop(p.redirectResponse, p.requestId));}} else if (msg.method === 'Network.responseReceived') {if (mainRequestIds.has(p.requestId) && p.response) {respondedIds.add(p.requestId);- hops.push(toHop(p.response));+ hops.push(toHop(p.response, p.requestId));finalUrl = p.response.url || finalUrl;}}@@ -426,9 +437,7 @@ export function collectWebSocketHosts(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 });+ out.push({ url: raw, host: hostOf(raw) });}return out;}@@ -442,17 +451,25 @@ export function ssrfPinRefusalReason(messages, verifyRemoteIp, url, topFrameId =// one can't be checked, so fail closed. The ONE exception is a hop Chrome// explicitly flagged as served without a connection (disk/prefetch cache, or a// service worker answering from its own store): there is no peer to pin, and- // refusing it false-positives every PWA. That exception only applies when- // another main-frame hop in the SAME navigation did verify a real IP — a- // navigation where nothing was ever verified is still a refusal, so a- // cache-flagged response can never stand in for a network check.- const anyHopVerified = hops.some((hop) => hop.remoteIPAddress);+ // refusing it false-positives every PWA. Two conditions bound that exception so+ // it can never stand in for a network check:+ // 1. Another hop of the SAME top-level navigation (same requestId — i.e. an+ // earlier link in this redirect chain) must have verified a real IP. A+ // verified IP from a DIFFERENT navigation proves nothing about this one:+ // a page that loads clean from public and then client-side-navigates to a+ // cached `http://127.0.0.1/…` document would otherwise be admitted.+ // 2. The hop's own URL host must still pass `verifyRemoteIp` — that catches a+ // cached document whose URL is a blocked literal (loopback/metadata),+ // which is the only address signal a connectionless hop carries. (Same+ // host-level fallback the WebSocket gate uses.)+ const verifiedRequestIds = new Set(hops.filter((h) => h.remoteIPAddress).map((h) => h.requestId));for (const hop of hops) {if (hop.remoteIPAddress) continue;const noConnection = hopMadeNoConnection(hop);- if (noConnection && anyHopVerified) continue;+ const host = hostOf(hop.url);+ if (noConnection && verifiedRequestIds.has(hop.requestId) && host && verifyRemoteIp(host)) continue;const detail = noConnection- ? `${describeHopDelivery(hop)}; no other main-frame hop verified a network address`+ ? `${describeHopDelivery(hop)}; no verified network address for this navigation`: describeHopDelivery(hop);return `Chrome connected to an unverifiable address for ${hop.url || url} (${detail})`;}diff --git a/server/services/browserService.test.js b/server/services/browserService.test.jsindex cdc741d78c..a0a657d2ed 100644--- a/server/services/browserService.test.js+++ b/server/services/browserService.test.js@@ -82,6 +82,7 @@ describe('pickMainFrameHops (SSRF pin — main-frame connection IPs)', () => {expect(mainRequestIds).toEqual(['R1']);expect(finalUrl).toBe('https://ex.com/a');expect(hops).toEqual([{+ requestId: 'R1',url: 'https://ex.com/a',remoteIPAddress: '93.184.216.34',status: 200,@@ -306,30 +307,54 @@ describe('ssrfPinRefusalReason (SSRF pin gate)', () => {expect(reason).toMatch(/serviceWorkerResponseSource=network/);});- it('allows a cache-served main-frame hop when another hop verified a real IP', () => {- // R1 loaded from the network and pinned a real address; a client-side nav- // (R2) was then answered from the disk cache — no connection was made, so- // there is nothing to pin and refusing would be a false positive.+ it('allows a cache-served hop when an EARLIER hop of the SAME navigation verified a real IP', () => {+ // R1 redirected through a network hop that pinned a real address; the final+ // hop of that same chain was answered from the disk cache — no connection was+ // made, so there is nothing to pin and refusing would be a false positive.const reason = ssrfPinRefusalReason([docRequest('R1', 'https://ex.com/a'),- docResponse('R1', 'https://ex.com/a', '93.184.216.34'),- docRequest('R2', 'https://ex.com/b'),- docResponse('R2', 'https://ex.com/b', '', { fromDiskCache: true }),+ docRequest('R1', 'https://ex.com/b', { url: 'https://ex.com/a', remoteIPAddress: '93.184.216.34', status: 302 }),+ docResponse('R1', 'https://ex.com/b', '', { fromDiskCache: true }),], allow, 'https://ex.com/a');expect(reason).toBeNull();});- it('allows a service-worker hop served from cache-storage when another hop verified a real IP', () => {+ it('allows a service-worker hop served from cache-storage on a chain that verified a real IP', () => {const reason = ssrfPinRefusalReason([docRequest('R1', 'https://pwa.example/'),- docResponse('R1', 'https://pwa.example/', '93.184.216.34'),- docRequest('R2', 'https://pwa.example/offline'),- docResponse('R2', 'https://pwa.example/offline', '', { fromServiceWorker: true, serviceWorkerResponseSource: 'cache-storage' }),+ docRequest('R1', 'https://pwa.example/offline', { url: 'https://pwa.example/', remoteIPAddress: '93.184.216.34', status: 302 }),+ docResponse('R1', 'https://pwa.example/offline', '', { fromServiceWorker: true, serviceWorkerResponseSource: 'cache-storage' }),], allow, 'https://pwa.example/');expect(reason).toBeNull();});- it('refuses a cache-served main document when NO main-frame hop verified an IP', () => {+ it('refuses a cache-served navigation that a DIFFERENT navigation verified (cross-nav borrow)', () => {+ // R1 loaded clean from public, then the page client-side-navigated to a+ // cached document. R1's verified IP says nothing about R2's origin — a+ // previously cached loopback/private document would otherwise be admitted+ // unpinned, so the exemption must not cross navigations.+ const reason = ssrfPinRefusalReason([+ docRequest('R1', 'https://ex.com/a'),+ docResponse('R1', 'https://ex.com/a', '93.184.216.34'),+ docRequest('R2', 'http://127.0.0.1/secret'),+ docResponse('R2', 'http://127.0.0.1/secret', '', { fromDiskCache: true }),+ ], allow, 'https://ex.com/a');+ expect(reason).toMatch(/unverifiable address/);+ expect(reason).toMatch(/no verified network address for this navigation/);+ });++ it('refuses a cache-served hop whose URL host is blocked, even on a verified chain', () => {+ // A connectionless hop carries one address signal — its own URL. A redirect+ // from a verified public hop into a cached loopback document must still fail.+ const reason = ssrfPinRefusalReason([+ docRequest('R1', 'https://ex.com/a'),+ docRequest('R1', 'http://127.0.0.1/secret', { url: 'https://ex.com/a', remoteIPAddress: '93.184.216.34', status: 302 }),+ docResponse('R1', 'http://127.0.0.1/secret', '', { fromDiskCache: true }),+ ], allow, 'https://ex.com/a');+ expect(reason).toMatch(/unverifiable address/);+ });++ it('refuses a cache-served main document when NO hop of that navigation verified an IP', () => {// A fully cache-served navigation pinned nothing at all — a cache flag can// never stand in for a network check, so this still fails closed.const reason = ssrfPinRefusalReason([@@ -337,7 +362,7 @@ describe('ssrfPinRefusalReason (SSRF pin gate)', () => {docResponse('R1', 'https://pwa.example/', '', { fromServiceWorker: true, serviceWorkerResponseSource: 'cache-storage' }),], allow, 'https://pwa.example/');expect(reason).toMatch(/unverifiable address/);- expect(reason).toMatch(/no other main-frame hop verified a network address/);+ expect(reason).toMatch(/no verified network address for this navigation/);});it('still refuses a disallowed sub-resource on a page whose main doc was cache-served', () => {@@ -345,9 +370,8 @@ describe('ssrfPinRefusalReason (SSRF pin gate)', () => {// every real connection the page made is still verified by collectConnectedIps.const reason = ssrfPinRefusalReason([docRequest('R1', 'https://pwa.example/'),- docResponse('R1', 'https://pwa.example/', '93.184.216.34'),- docRequest('R2', 'https://pwa.example/app'),- docResponse('R2', 'https://pwa.example/app', '', { fromDiskCache: true }),+ docRequest('R1', 'https://pwa.example/app', { url: 'https://pwa.example/', remoteIPAddress: '93.184.216.34', status: 302 }),+ docResponse('R1', 'https://pwa.example/app', '', { fromDiskCache: true }),{ method: 'Network.responseReceived', params: { requestId: 'R3', type: 'XHR', response: { url: 'https://pwa.example/latest/meta-data', remoteIPAddress: '169.254.169.254', status: 200 } } },], allow, 'https://pwa.example/');expect(reason).toMatch(/disallowed address 169\.254\.169\.254/);