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 (claude): SSRF guard on URL ingest (block file:// + loopback/link-local), drop leaked browser tab per ingest
[._.]/ Adam Eivy8d1fb9c52c9a
diff --git a/server/lib/catalogValidation.js b/server/lib/catalogValidation.jsindex 47529e7ca8..ab86bde9b4 100644--- a/server/lib/catalogValidation.js+++ b/server/lib/catalogValidation.js@@ -78,8 +78,27 @@ export const catalogScrapPatchSchema = catalogScrapCreateSchema.partial();// client lands on the identical review phase. `providerOverride` mirrors// catalogExtractRequestSchema below.+// Block schemes and hosts that would turn "fetch this page" into local-file+// exfiltration or cloud-metadata SSRF. 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. We only reject the two genuinely dangerous classes:+// non-http(s) schemes (file:/chrome:/javascript:/ftp:) and loopback ++// link-local (127.x/::1/169.254.169.254 cloud-metadata).+export const isSafeIngestUrl = (raw) => {+ let u;+ try { u = new URL(raw); } catch { return false; }+ if (u.protocol !== 'http:' && u.protocol !== 'https:') return false;+ const host = u.hostname.toLowerCase().replace(/^\[|\]$/g, '');+ if (host === 'localhost' || host === '::1' || host.endsWith('.localhost')) return false;+ if (/^127\./.test(host)) return false; // loopback+ if (/^169\.254\./.test(host)) return false; // link-local incl. cloud metadata+ if (host === 'metadata.google.internal') return false;+ return true;+};+export const catalogUrlIngestSchema = z.object({- url: z.string().trim().url().max(4_000),+ url: z.string().trim().max(4_000).url()+ .refine(isSafeIngestUrl, 'only http(s) URLs to non-loopback/non-link-local hosts are allowed'),providerOverride: z.string().trim().min(1).max(120).optional(),}).strict();diff --git a/server/lib/catalogValidation.test.js b/server/lib/catalogValidation.test.jsindex 41385301f3..8469ba2bf9 100644--- a/server/lib/catalogValidation.test.js+++ b/server/lib/catalogValidation.test.js@@ -27,6 +27,7 @@ import {catalogMediaDetachSchema,catalogPortraitSetSchema,MEDIA_KINDS,+ catalogUrlIngestSchema,} from './catalogValidation.js';describe('catalogValidation — ingredient types & ref kinds', () => {@@ -455,3 +456,23 @@ describe('catalogValidation — catalogSyncEnvelopeSchema media block', () => {})).toThrow();});});++describe('catalogUrlIngestSchema — SSRF guard', () => {+ it('accepts a normal http(s) URL (incl. a LAN/Tailscale host — intentional)', () => {+ expect(catalogUrlIngestSchema.parse({ url: 'https://example.com/post' }).url).toBe('https://example.com/post');+ // Private/LAN hosts are allowed by design (ingest from a home wiki / peer).+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://192.168.1.50/wiki' })).not.toThrow();+ });++ it('rejects file:// and other non-http(s) schemes (local-file exfiltration)', () => {+ expect(() => catalogUrlIngestSchema.parse({ url: 'file:///etc/passwd' })).toThrow();+ expect(() => catalogUrlIngestSchema.parse({ url: 'ftp://host/x' })).toThrow();+ });++ it('rejects loopback and link-local / cloud-metadata hosts (SSRF)', () => {+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://169.254.169.254/latest/meta-data/' })).toThrow();+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://localhost:5555/api/secrets' })).toThrow();+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://127.0.0.1/x' })).toThrow();+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://metadata.google.internal/x' })).toThrow();+ });+});diff --git a/server/services/catalogIngestSources.js b/server/services/catalogIngestSources.jsindex 28babb869e..21c2b2a075 100644--- a/server/services/catalogIngestSources.js+++ b/server/services/catalogIngestSources.js@@ -25,7 +25,6 @@ import * as catalogDB from './catalogDB.js';import { extractIngredients } from './catalogExtraction.js';import { transcribe } from './voice/stt.js';import {- findOrOpenPage,navigateToUrl,listCdpPages,evaluateOnPage,@@ -71,10 +70,9 @@ 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 } = {}) {- // Open (or reuse a tab already on this host), then navigate to force the- // exact URL — findOrOpenPage matches by hostname so an existing tab on the- // same site would otherwise be reused at the wrong path.- await findOrOpenPage(url).catch(() => null);+ // `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.)const opened = await navigateToUrl(url);await sleep(settleMs);diff --git a/server/services/catalogIngestSources.test.js b/server/services/catalogIngestSources.test.jsindex 0ea00f1769..d5d41d59c4 100644--- a/server/services/catalogIngestSources.test.js+++ b/server/services/catalogIngestSources.test.js@@ -23,7 +23,6 @@ vi.mock('./voice/stt.js', () => ({transcribe: vi.fn(),}));vi.mock('./browserService.js', () => ({- findOrOpenPage: vi.fn(),navigateToUrl: vi.fn(),listCdpPages: vi.fn(),evaluateOnPage: vi.fn(),@@ -57,7 +56,6 @@ beforeEach(() => {describe('fetchUrlMainText', () => {it('navigates + reads main text, returning title + text + finalUrl', async () => {- browserService.findOrOpenPage.mockResolvedValue({ id: 'p1' });browserService.navigateToUrl.mockResolvedValue({ id: 'p1', url: 'https://ex.com/a' });browserService.listCdpPages.mockResolvedValue([{ id: 'p1', url: 'https://ex.com/a', title: 'A', webSocketDebuggerUrl: 'ws://x' },@@ -70,7 +68,6 @@ describe('fetchUrlMainText', () => {});it('throws when the page extracts no readable text', async () => {- browserService.findOrOpenPage.mockResolvedValue(null);browserService.navigateToUrl.mockResolvedValue({ id: 'p1', url: 'https://ex.com/a' });browserService.listCdpPages.mockResolvedValue([{ id: 'p1', url: 'https://ex.com/a', title: '', webSocketDebuggerUrl: 'ws://x' }]);browserService.evaluateOnPage.mockResolvedValue(JSON.stringify({ title: '', text: ' ' }));@@ -78,11 +75,19 @@ describe('fetchUrlMainText', () => {await expect(fetchUrlMainText('https://ex.com/a', { settleMs: 0 })).rejects.toThrow(/no readable text/);expect(catalogDB.createScrap).not.toHaveBeenCalled();});++ it('clamps an oversized page body to the raw-text cap (2M chars)', async () => {+ browserService.navigateToUrl.mockResolvedValue({ id: 'p1', url: 'https://ex.com/a' });+ browserService.listCdpPages.mockResolvedValue([{ id: 'p1', url: 'https://ex.com/a', title: 'Big', webSocketDebuggerUrl: 'ws://x' }]);+ const huge = 'x'.repeat(2_500_000);+ browserService.evaluateOnPage.mockResolvedValue(JSON.stringify({ title: 'Big', text: huge }));+ const out = await fetchUrlMainText('https://ex.com/a', { settleMs: 0 });+ expect(out.text.length).toBe(2_000_000);+ });});describe('ingestFromUrl', () => {it('creates a url scrap with url metadata and runs extraction', async () => {- browserService.findOrOpenPage.mockResolvedValue({ id: 'p1' });browserService.navigateToUrl.mockResolvedValue({ id: 'p1', url: 'https://ex.com/a' });browserService.listCdpPages.mockResolvedValue([{ id: 'p1', url: 'https://ex.com/a', title: 'A', webSocketDebuggerUrl: 'ws://x' }]);browserService.evaluateOnPage.mockResolvedValue(JSON.stringify({ title: 'Article A', text: 'Body.' }));