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: fail closed on a top-level navigation still in flight at settle-end (#2068)
Adam Eivye5151629255b
diff --git a/server/services/browserService.js b/server/services/browserService.jsindex c63ff5ec23..0552e7c6ea 100644--- a/server/services/browserService.js+++ b/server/services/browserService.js@@ -300,10 +300,16 @@ export async function navigateToUrl(url) {** Pure + exported so the SSRF-pin decision is unit-testable without a live* browser. Returns `{ hops: [{ url, remoteIPAddress, status }], finalUrl,- * mainRequestIds: string[] }`.+ * mainRequestIds: string[], pendingMainRequestIds: string[] }`.+ * `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+ * non-empty pending set: Chrome could complete that navigation (to a private /+ * metadata target) right after we stop capturing, leaving it unpinned.*/export function pickMainFrameHops(messages) {const mainRequestIds = new Set();+ const respondedIds = new Set();const hops = [];let finalUrl = null;for (const msg of messages) {@@ -324,6 +330,7 @@ export function pickMainFrameHops(messages) {}} else if (msg.method === 'Network.responseReceived') {if (mainRequestIds.has(p.requestId) && p.response) {+ respondedIds.add(p.requestId);hops.push({url: p.response.url || null,remoteIPAddress: p.response.remoteIPAddress || '',@@ -333,7 +340,8 @@ export function pickMainFrameHops(messages) {}}}- return { hops, finalUrl, mainRequestIds: [...mainRequestIds] };+ const pendingMainRequestIds = [...mainRequestIds].filter((id) => !respondedIds.has(id));+ return { hops, finalUrl, mainRequestIds: [...mainRequestIds], pendingMainRequestIds };}// Close a CDP tab by target id (best-effort). Used to fail closed after an@@ -430,7 +438,7 @@ export async function navigateToUrlPinned(url, { verifyRemoteIp, settleMs = 0, nws.on('error', () => finish({ ok: false, reason: 'CDP websocket error during navigation' }));});- const { hops, finalUrl } = pickMainFrameHops(messages);+ const { hops, finalUrl, pendingMainRequestIds } = pickMainFrameHops(messages);const fail = async (reason) => {await closeCdpPage(target.id);@@ -444,6 +452,12 @@ export async function navigateToUrlPinned(url, { verifyRemoteIp, settleMs = 0, nawait fail(`refusing to ingest: Chrome connected to a disallowed address ${hop.remoteIPAddress || '(unknown)'} for ${hop.url || url}`);}}+ // Fail closed if a top-level navigation was still in flight when the settle+ // window ended: its final connection IP was never observed, so Chrome could be+ // mid-connect to a private/metadata target the DOM reader would then see.+ if (pendingMainRequestIds.length) {+ await fail('refusing to ingest: a top-level navigation was still in flight at read time (unpinned)');+ }return { id: target.id, url: finalUrl || url, title: '', webSocketDebuggerUrl: target.webSocketDebuggerUrl };}diff --git a/server/services/browserService.test.js b/server/services/browserService.test.jsindex 6d50aca3e1..80b5d36a7a 100644--- a/server/services/browserService.test.js+++ b/server/services/browserService.test.js@@ -121,6 +121,21 @@ describe('pickMainFrameHops (SSRF pin — main-frame connection IPs)', () => {expect(hops.map((h) => h.remoteIPAddress)).toEqual(['93.184.216.34']);});+ it('flags a top-level navigation that started but has no response yet (in-flight → pending)', () => {+ // R1 completed clean; R2 (a client-side nav) STARTED during settle but the+ // socket closed before its responseReceived — its final IP is unverified, so+ // the caller must fail closed rather than read a possibly-private page.+ const { hops, mainRequestIds, pendingMainRequestIds } = pickMainFrameHops([+ docRequest('R1', 'https://ex.com/a', ''),+ docResponse('R1', 'https://ex.com/a', '93.184.216.34'),+ docRequest('R2', 'https://evil.example/x', ''),+ ]);+ expect(mainRequestIds).toEqual(['R1', 'R2']);+ expect(pendingMainRequestIds).toEqual(['R2']);+ // R2 contributed no hop (no response captured), so its IP was never checked.+ expect(hops.map((h) => h.remoteIPAddress)).toEqual(['93.184.216.34']);+ });+it('returns no hops when no main-frame document load is present', () => {const { hops, mainRequestIds, finalUrl } = pickMainFrameHops([{ method: 'Network.requestWillBeSent', params: { requestId: 'R2', loaderId: 'R1', type: 'Image', request: { url: 'https://cdn/x.png' } } },