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: re-query live tab url after settle so client-side nav to a blocked host is re-vetted (#2068)
Adam Eivy5ac2d944c36d
diff --git a/server/services/catalogIngestSources.js b/server/services/catalogIngestSources.jsindex b0c6223821..234158f1fd 100644--- a/server/services/catalogIngestSources.js+++ b/server/services/catalogIngestSources.js@@ -32,6 +32,7 @@ import { extractIngredientsForScrap } from './catalogExtraction.js';import { transcribe } from './voice/stt.js';import {navigateToUrlPinned,+ listCdpPages,evaluateOnPage,} from './browserService.js';import { lookup } from 'dns/promises';@@ -121,13 +122,19 @@ export async function fetchUrlMainText(url, { settleMs = PAGE_SETTLE_MS } = {})});await sleep(settleMs);- // Defense in depth: re-run the scheme+DNS gate against the FINAL landed url.- // The remoteIP pin above already proved Chrome dialed an allowed address for- // every hop; this additionally rejects a landed hostname that is itself a- // blocked literal (e.g. an in-page/JS redirect after load that the network-hop- // pin didn't cover).- const landedUrl = page.url || url;+ // Defense in depth: re-query the tab's LIVE url AFTER the settle window and+ // re-vet it (scheme + DNS blocklist) before reading the DOM. The network-hop+ // pin above covers HTTP-level hops, but the page can client-side navigate+ // (meta refresh / location.replace) during the settle to a blocked host — so+ // read the CURRENT url from CDP, not the pre-settle url the pin captured, or+ // that redirect goes unchecked. Match strictly by the target id navigate+ // returned (never an arbitrary tab). Fall back to the pinned page's own+ // webSocketDebuggerUrl for the read if the re-list misses.+ const pages = await listCdpPages();+ const live = pages.find((p) => p.id === page.id);+ const landedUrl = live?.url || page.url || url;await assertIngestUrlSafe(landedUrl);+ const readTarget = live?.webSocketDebuggerUrl ? live : page;// Prefer the page's own <article>/<main> if present (skips nav/footer// chrome), falling back to document body text. Runs in the page; returns a@@ -138,11 +145,11 @@ export async function fetchUrlMainText(url, { settleMs = PAGE_SETTLE_MS } = {})const text = (pick && pick.innerText ? pick.innerText : '').trim();return JSON.stringify({ title, text });})()`;- const raw = await evaluateOnPage(page, expression);+ const raw = await evaluateOnPage(readTarget, expression);const parsed = raw ? safeJSONParse(raw, null) : null;const text = clampText(parsed?.text || '');if (!text.trim()) throw new Error('no readable text extracted from page');- return { text, title: parsed?.title || page.title || '', finalUrl: page.url || url };+ return { text, title: parsed?.title || live?.title || page.title || '', finalUrl: landedUrl };}/**diff --git a/server/services/catalogIngestSources.test.js b/server/services/catalogIngestSources.test.jsindex 2bdc0c612c..bfbcedaeea 100644--- a/server/services/catalogIngestSources.test.js+++ b/server/services/catalogIngestSources.test.js@@ -33,6 +33,7 @@ vi.mock('./voice/stt.js', () => ({}));vi.mock('./browserService.js', () => ({navigateToUrlPinned: vi.fn(),+ listCdpPages: vi.fn(),evaluateOnPage: vi.fn(),}));vi.mock('fs/promises', () => ({@@ -79,6 +80,8 @@ beforeEach(() => {dnsp.lookup.mockResolvedValue({ address: '93.184.216.34', family: 4 });// Default: Chrome dials a single public IP for the document (no rebind).browserService.navigateToUrlPinned.mockImplementation(pinnedNav({ finalUrl: 'https://ex.com/a', hops: ['93.184.216.34'] }));+ // Default: the live tab (re-queried after settle) is the same safe url.+ browserService.listCdpPages.mockResolvedValue([{ id: 'p1', url: 'https://ex.com/a', title: 'A', webSocketDebuggerUrl: 'ws://x' }]);});/**@@ -145,17 +148,26 @@ describe('fetchUrlMainText', () => {});it('refuses a landed HOSTNAME that resolves to a blocked address (defense-in-depth re-check)', async () => {- // All network hops dialed public IPs (pin passes), but the FINAL landed url- // is a hostname that itself resolves to metadata — the landed-url re-vet- // still catches an in-page/JS redirect the network-hop pin didn't cover.+ // All network hops dialed public IPs (pin passes), but the LIVE tab url after+ // settle is a hostname that itself resolves to metadata — the landed-url+ // re-vet still catches an in-page/JS redirect the network-hop pin didn't cover.dnsp.lookup.mockResolvedValueOnce({ address: '93.184.216.34', family: 4 }).mockResolvedValueOnce({ address: '169.254.169.254', family: 4 });- browserService.navigateToUrlPinned.mockImplementation(pinnedNav({ finalUrl: 'https://evil.example/x', hops: ['93.184.216.34'] }));+ browserService.listCdpPages.mockResolvedValue([{ id: 'p1', url: 'https://evil.example/x', title: 'x', webSocketDebuggerUrl: 'ws://x' }]);await expect(fetchUrlMainText('https://ex.com/a', { settleMs: 0 })).rejects.toThrow(/resolves to a blocked/);expect(browserService.evaluateOnPage).not.toHaveBeenCalled();});+ it('re-checks the LIVE tab url after the settle window (client-side nav to loopback)', async () => {+ // Pin passes (public hops), but the page client-side navigates (meta refresh /+ // location.replace) during the settle to a loopback address. We must re-read+ // the CURRENT tab url — not the pre-settle url the pin captured — and refuse.+ browserService.listCdpPages.mockResolvedValue([{ id: 'p1', url: 'http://127.0.0.1:5555/secret', title: 'x', webSocketDebuggerUrl: 'ws://x' }]);+ await expect(fetchUrlMainText('https://ex.com/a', { settleMs: 0 })).rejects.toThrow(/loopback|link-local/);+ expect(browserService.evaluateOnPage).not.toHaveBeenCalled();+ });+it('clamps an oversized page body to the raw-text cap (2M chars)', async () => {const huge = 'x'.repeat(2_500_000);browserService.evaluateOnPage.mockResolvedValue(JSON.stringify({ title: 'Big', text: huge }));