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
address review (codex): DNS-resolution SSRF guard, fail instead of reading an arbitrary CDP tab, stop the mic when leaving the recording UI
[._.]/ Adam Eivyde3e89123f30
diff --git a/client/src/pages/CatalogIngest.jsx b/client/src/pages/CatalogIngest.jsxindex c89da0edae..76a0bfbb9a 100644--- a/client/src/pages/CatalogIngest.jsx+++ b/client/src/pages/CatalogIngest.jsx@@ -87,6 +87,10 @@ export default function CatalogIngest() {const recorderRef = useRef(null);const fileInputRef = useRef(null);+ // Stop the mic if the page unmounts mid-recording (navigating away), so the+ // MediaRecorder stream isn't left live with no UI to stop it.+ useEffect(() => () => { recorderRef.current?.cancel?.(); }, []);+// Track active runId so a stale frame from an earlier scrap can't mutate the// current stage list (server fans these to all sockets — single-user trust// model still applies, but tab refresh + a slow extract overlap is real).@@ -345,7 +349,9 @@ export default function CatalogIngest() {</button>{phase === 'paste' && (<button type="button" onClick={() => setBulkOpen((v) => !v)}- className="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg text-sm border border-port-border text-gray-300 hover:text-white"+ disabled={recording}+ title={recording ? 'Stop the voice recording first' : undefined}+ className="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg text-sm border border-port-border text-gray-300 hover:text-white disabled:opacity-40 disabled:cursor-not-allowed"aria-expanded={bulkOpen}><Upload size={14} aria-hidden="true" /> Bulk Import</button>diff --git a/server/lib/catalogValidation.js b/server/lib/catalogValidation.jsindex fc44736414..8022f7d992 100644--- a/server/lib/catalogValidation.js+++ b/server/lib/catalogValidation.js@@ -85,7 +85,7 @@ export const catalogScrapPatchSchema = catalogScrapCreateSchema.partial();// the guard can't be bypassed with a mapped literal. We deliberately ALLOW// other private/LAN hosts: ingesting from a Tailscale peer or a home-network// wiki is a legit use of this single-user tool.-const isBlockedIngestHost = (host) => {+export const isBlockedIngestHost = (host) => {const h = host.toLowerCase().replace(/^\[|\]$/g, '');if (h === 'localhost' || h.endsWith('.localhost') || h === 'metadata.google.internal') return true;if (h === '::1' || h === '::' || h === '0.0.0.0') return true;diff --git a/server/services/catalogIngestSources.js b/server/services/catalogIngestSources.jsindex 173844bc25..a3069d71f0 100644--- a/server/services/catalogIngestSources.js+++ b/server/services/catalogIngestSources.js@@ -29,8 +29,9 @@ import {listCdpPages,evaluateOnPage,} from './browserService.js';+import { lookup } from 'dns/promises';import { PATHS, ensureDir } from '../lib/fileUtils.js';-import { isSafeIngestUrl } from '../lib/catalogValidation.js';+import { isSafeIngestUrl, isBlockedIngestHost } from '../lib/catalogValidation.js';// Cap fetched/transcribed bodies at the scrap column boundary (the Zod// rawText max). A runaway page or a multi-hour memo can't blow past the DB.@@ -71,6 +72,21 @@ async function createScrapAndExtract({ title, rawText, sourceKind, metadata, pro* the page or extracts nothing usable, so the route surfaces a clean 4xx/5xx.*/export async function fetchUrlMainText(url, { settleMs = PAGE_SETTLE_MS } = {}) {+ // DNS guard: the schema rejects blocked IP LITERALS, but a hostname can+ // resolve to a blocked address (DNS record / rebinding pointing at+ // 169.254.169.254, loopback, …). Resolve it and reject before we navigate.+ // (Residual TOCTOU — Chrome re-resolves independently — is acceptable on a+ // single-user private network; this closes the realistic record-points-at-+ // metadata vector and is paired with the post-navigation re-check below.)+ const { hostname } = new URL(url);+ const isIpLiteral = /^[\d.]+$/.test(hostname) || hostname.includes(':');+ if (!isIpLiteral) {+ const resolved = await lookup(hostname).catch(() => null);+ if (resolved?.address && isBlockedIngestHost(resolved.address)) {+ throw new Error('refusing to ingest a host that resolves to a blocked (loopback/link-local) address');+ }+ }+// `navigateToUrl` opens a fresh tab at the exact URL and returns it; we drive// and read that tab below. (Don't call findOrOpenPage first — it would open a// SECOND, orphaned tab per ingest, since navigateToUrl never reuses one.)@@ -78,11 +94,13 @@ export async function fetchUrlMainText(url, { settleMs = PAGE_SETTLE_MS } = {})await sleep(settleMs);// Re-list to get the live webSocketDebuggerUrl for the tab we just drove.+ // Match strictly by the id (then the exact url) navigateToUrl returned —+ // never fall back to an arbitrary `pages[0]`, which could be an unrelated+ // open tab and would ingest the wrong (possibly sensitive) page.const pages = await listCdpPages();const page = pages.find((p) => p.id === opened.id)- || pages.find((p) => p.url === opened.url)- || pages[0];- if (!page) throw new Error('browser tab not found after navigation');+ || pages.find((p) => p.url === opened.url);+ if (!page) throw new Error('could not match the navigated tab after navigation (refusing to read an arbitrary tab)');// Re-validate the FINAL url before reading the DOM: the request-body URL// passed the SSRF guard, but a server-controlled redirect could have sentdiff --git a/server/services/catalogIngestSources.test.js b/server/services/catalogIngestSources.test.jsindex 39522e3e1e..94689abbc8 100644--- a/server/services/catalogIngestSources.test.js+++ b/server/services/catalogIngestSources.test.js@@ -30,6 +30,9 @@ vi.mock('./browserService.js', () => ({vi.mock('fs/promises', () => ({writeFile: vi.fn(),}));+vi.mock('dns/promises', () => ({+ lookup: vi.fn(),+}));vi.mock('../lib/fileUtils.js', () => ({PATHS: { audio: '/tmp/data/audio' },ensureDir: vi.fn(),@@ -39,6 +42,7 @@ const catalogDB = await import('./catalogDB.js');const catalogExtraction = await import('./catalogExtraction.js');const browserService = await import('./browserService.js');const fsp = await import('fs/promises');+const dnsp = await import('dns/promises');const {fetchUrlMainText,ingestFromUrl,@@ -52,6 +56,8 @@ beforeEach(() => {vi.clearAllMocks();catalogExtraction.extractIngredients.mockResolvedValue(DRAFT);catalogDB.createScrap.mockImplementation(async (args) => ({ id: 'cat-scrap-1', ...args }));+ // Hostnames resolve to a safe public address by default (the DNS SSRF guard).+ dnsp.lookup.mockResolvedValue({ address: '93.184.216.34', family: 4 });});describe('fetchUrlMainText', () => {@@ -76,6 +82,13 @@ describe('fetchUrlMainText', () => {expect(catalogDB.createScrap).not.toHaveBeenCalled();});+ it('refuses to ingest a hostname that resolves to a blocked address (DNS SSRF) before navigating', async () => {+ // Schema passes (it's a normal hostname), but DNS points it at cloud metadata.+ dnsp.lookup.mockResolvedValue({ address: '169.254.169.254', family: 4 });+ await expect(fetchUrlMainText('https://evil.example/x', { settleMs: 0 })).rejects.toThrow(/resolves to a blocked/);+ expect(browserService.navigateToUrl).not.toHaveBeenCalled();+ });+it('refuses to ingest a redirect that lands on a blocked (loopback) host', async () => {browserService.navigateToUrl.mockResolvedValue({ id: 'p1', url: 'https://ex.com/a' });// The first-hop URL passed the schema guard, but Chrome followed a redirect