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: catalog URL-ingest no longer over-refuses public pages embedding slow/cached iframes (#2083)
Adam Eivy57a387aa6b41
diff --git a/server/services/browserService.js b/server/services/browserService.jsindex a1f40d2b52..a582521822 100644--- a/server/services/browserService.js+++ b/server/services/browserService.js@@ -307,7 +307,21 @@ export async function navigateToUrl(url) {* 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) {+export function pickMainFrameHops(messages, topFrameId = null) {+ // CDP sets `requestId === loaderId` on the main resource of EVERY frame — the+ // top document AND cross-origin sub-frames (iframes). When the caller passes+ // the top frame's `frameId` (from the `Page.navigate` response) we classify a+ // top-level navigation by `frameId === topFrameId` instead, so a slow/cached+ // iframe document can't land in the pending/empty-IP gate and over-refuse a safe+ // public page. Defensive fallback: if NO document request in the stream carries+ // `topFrameId` (a frameId-format surprise), retain the `requestId === loaderId`+ // classification so the gate can never regress to refuse-all. Sub-frame /+ // sub-resource IPs are still fully verified by `collectConnectedIps`.+ const useFrameId = topFrameId != null && messages.some((m) => (+ m?.method === 'Network.requestWillBeSent' && m.params?.type === 'Document' && m.params?.frameId === topFrameId+ ));+ const isMainDocRequest = (p) => p.type === 'Document' && p.requestId+ && (useFrameId ? p.frameId === topFrameId : p.requestId === p.loaderId);const mainRequestIds = new Set();const respondedIds = new Set();const hops = [];@@ -316,9 +330,7 @@ export function pickMainFrameHops(messages) {const p = msg?.params;if (!p) continue;if (msg.method === 'Network.requestWillBeSent') {- // A Document request whose requestId equals its loaderId is a top-level- // navigation; ignore sub-resource / sub-frame requests.- if (p.type === 'Document' && p.requestId && p.requestId === p.loaderId) {+ if (isMainDocRequest(p)) {mainRequestIds.add(p.requestId);}if (mainRequestIds.has(p.requestId) && p.redirectResponse) {@@ -390,8 +402,8 @@ export function collectWebSocketHosts(messages) {// 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) {- const { hops, pendingMainRequestIds } = pickMainFrameHops(messages);+export function ssrfPinRefusalReason(messages, verifyRemoteIp, url, topFrameId = null) {+ const { hops, pendingMainRequestIds } = pickMainFrameHops(messages, topFrameId);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.@@ -485,6 +497,10 @@ export async function navigateToUrlPinned(url, {const ws = new WebSocket(target.webSocketDebuggerUrl);let settled = false;let phase = 'nav';+ // The top frame's id, reported by the `Page.navigate` response (id 2). Threaded+ // into the pin so ONLY the top document gates the pending/empty-IP checks —+ // slow/cached iframes (which also carry `requestId === loaderId`) don't.+ let topFrameId = null;let overallTimer;let settleTimer = null;let evalTimer = null;@@ -506,10 +522,10 @@ export async function navigateToUrlPinned(url, {// Settle expired: verify everything captured so far, then either read the DOM// on THIS same session (so no monitoring gap) or resolve for a separate read.const onSettleEnd = () => {- const bad = ssrfPinRefusalReason(messages, verifyRemoteIp, url);+ const bad = ssrfPinRefusalReason(messages, verifyRemoteIp, url, topFrameId);if (bad) return finish({ ok: false, reason: bad });if (!evaluateExpression) {- const { finalUrl } = pickMainFrameHops(messages);+ const { finalUrl } = pickMainFrameHops(messages, topFrameId);return finish({ ok: true, finalUrl, evalResult: null });}phase = 'read';@@ -528,16 +544,21 @@ export async function navigateToUrlPinned(url, {ws.on('message', (data) => {const msg = safeJSONParse(data.toString(), null, { context: 'cdp-pin' });if (!msg) return;- // A Page.navigate Chrome rejects outright (bad scheme, etc.) errors on id 2.- if (msg.id === 2 && msg.error) return finish({ ok: false, reason: msg.error.message || 'navigate rejected' });+ // A Page.navigate Chrome rejects outright (bad scheme, etc.) errors on id 2;+ // otherwise its result carries the top frame's `frameId` we pin against.+ if (msg.id === 2) {+ if (msg.error) return finish({ ok: false, reason: msg.error.message || 'navigate rejected' });+ if (msg.result?.frameId) topFrameId = msg.result.frameId;+ return;+ }if (msg.id === READ_ID) {// DOM read returned. RE-verify over ALL events captured up to now: any// top-level navigation that committed during the read is in `messages`,// so a late rebind that changed the page under us fails closed here.- const bad = ssrfPinRefusalReason(messages, verifyRemoteIp, url);+ const bad = ssrfPinRefusalReason(messages, verifyRemoteIp, url, topFrameId);if (bad) return finish({ ok: false, reason: bad });const evalResult = (msg.error || msg.result?.exceptionDetails) ? null : (msg.result?.result?.value ?? null);- const { finalUrl } = pickMainFrameHops(messages);+ const { finalUrl } = pickMainFrameHops(messages, topFrameId);return finish({ ok: true, finalUrl, evalResult });}if (!msg.method) return;diff --git a/server/services/browserService.test.js b/server/services/browserService.test.jsindex 84d8fd46f4..2a279bd219 100644--- a/server/services/browserService.test.js+++ b/server/services/browserService.test.js@@ -144,6 +144,37 @@ describe('pickMainFrameHops (SSRF pin — main-frame connection IPs)', () => {expect(hops).toEqual([]);expect(finalUrl).toBeNull();});++ it('with topFrameId, ignores a sub-frame (iframe) document that also has requestId===loaderId', () => {+ // CDP marks the main resource of EVERY frame with requestId===loaderId, so an+ // iframe document (F2, its own frameId) looks like a top-level nav. Passing the+ // top frame's frameId restricts main-frame classification to F1 only — the+ // slow/cached iframe (F2, no response yet) must NOT gate the pending check.+ const msgs = [+ { method: 'Network.requestWillBeSent', params: { requestId: 'R1', loaderId: 'R1', frameId: 'F1', type: 'Document', request: { url: 'https://ex.com/a' } } },+ { method: 'Network.responseReceived', params: { requestId: 'R1', frameId: 'F1', type: 'Document', response: { url: 'https://ex.com/a', remoteIPAddress: '93.184.216.34', status: 200 } } },+ // Sub-frame document: distinct frameId, still requestId===loaderId, no response.+ { method: 'Network.requestWillBeSent', params: { requestId: 'R2', loaderId: 'R2', frameId: 'F2', type: 'Document', request: { url: 'https://widget.example/iframe' } } },+ ];+ const { mainRequestIds, pendingMainRequestIds, hops } = pickMainFrameHops(msgs, 'F1');+ expect(mainRequestIds).toEqual(['R1']);+ expect(pendingMainRequestIds).toEqual([]);+ expect(hops.map((h) => h.remoteIPAddress)).toEqual(['93.184.216.34']);+ // Without the frameId hint, the old classifier over-refuses (F2 is pending).+ const legacy = pickMainFrameHops(msgs);+ expect(legacy.pendingMainRequestIds).toEqual(['R2']);+ });++ it('falls back to requestId===loaderId when no request matches topFrameId', () => {+ // A frameId-format surprise (topFrameId matches nothing in the stream) must not+ // regress to refuse-all — retain the legacy classification.+ const { mainRequestIds, hops } = pickMainFrameHops([+ docRequest('R1', 'https://ex.com/a', ''),+ docResponse('R1', 'https://ex.com/a', '93.184.216.34'),+ ], 'FRAME-THAT-DOES-NOT-EXIST');+ expect(mainRequestIds).toEqual(['R1']);+ expect(hops.map((h) => h.remoteIPAddress)).toEqual(['93.184.216.34']);+ });});describe('ssrfPinRefusalReason (SSRF pin gate)', () => {@@ -252,4 +283,18 @@ describe('ssrfPinRefusalReason (SSRF pin gate)', () => {], hostAllow, 'https://ex.com/a');expect(reason).toBeNull();});++ it('passes a public page that embeds a slow iframe when the top frameId is pinned', () => {+ // Top document loads clean from public; an embedded iframe (its own frameId,+ // requestId===loaderId) is still in flight at settle-end. Without the frameId+ // pin this over-refuses ("still in flight"); with it, only F1 gates the check.+ const msgs = [+ { method: 'Network.requestWillBeSent', params: { requestId: 'R1', loaderId: 'R1', frameId: 'F1', type: 'Document', request: { url: 'https://ex.com/article' } } },+ { method: 'Network.responseReceived', params: { requestId: 'R1', frameId: 'F1', type: 'Document', response: { url: 'https://ex.com/article', remoteIPAddress: '93.184.216.34', status: 200 } } },+ { method: 'Network.requestWillBeSent', params: { requestId: 'R2', loaderId: 'R2', frameId: 'F2', type: 'Document', request: { url: 'https://widget.example/embed' } } },+ ];+ expect(ssrfPinRefusalReason(msgs, allow, 'https://ex.com/article', 'F1')).toBeNull();+ // Sanity: the legacy classifier (no frameId) over-refuses the same stream.+ expect(ssrfPinRefusalReason(msgs, allow, 'https://ex.com/article')).toMatch(/still in flight/);+ });});