Skip to content

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

address review (codex): close SSRF bypasses — reject IPv4-mapped IPv6 loopback/link-local literals and re-validate the post-redirect URL

[._.]/ Adam Eivy20dc6ed0839c
diff --git a/server/lib/catalogValidation.js b/server/lib/catalogValidation.js
index ab86bde9b4..fc44736414 100644
--- a/server/lib/catalogValidation.js
+++ b/server/lib/catalogValidation.js
@@ -78,22 +78,41 @@ export const catalogScrapPatchSchema = catalogScrapCreateSchema.partial();
// client lands on the identical review phase. `providerOverride` mirrors
// catalogExtractRequestSchema below.
+// A host (bracket-stripped, lowercased) that the URL ingest must refuse:
+// loopback, link-local (incl. the 169.254.169.254 cloud-metadata endpoint),
+// and the unspecified address — in plain IPv4, IPv6, AND IPv4-mapped-IPv6 form
+// (`::ffff:127.0.0.1`, which WHATWG normalizes to the hex `::ffff:7f00:1`), so
+// 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) => {
+ 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;
+ const v4Blocked = (ip) => /^127\./.test(ip) || /^169\.254\./.test(ip) || ip === '0.0.0.0';
+ if (/^\d{1,3}(\.\d{1,3}){3}$/.test(h)) return v4Blocked(h);
+ // IPv4-mapped IPv6: `::ffff:a.b.c.d` or the compressed hex `::ffff:HHHH:HHHH`.
+ const mapped = /^::ffff:(.+)$/i.exec(h);
+ if (mapped) {
+ const tail = mapped[1];
+ if (/^\d{1,3}(\.\d{1,3}){3}$/.test(tail)) return v4Blocked(tail);
+ const parts = tail.split(':');
+ if (parts.length === 2 && parts.every((p) => /^[0-9a-f]{1,4}$/.test(p))) {
+ const hi = parseInt(parts[0], 16), lo = parseInt(parts[1], 16);
+ return v4Blocked(`${(hi >> 8) & 255}.${hi & 255}.${(lo >> 8) & 255}.${lo & 255}`);
+ }
+ }
+ return false;
+};
+
// 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).
+// exfiltration or cloud-metadata SSRF: non-http(s) schemes (file:/chrome:/
+// javascript:/ftp:) and the blocked hosts above.
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;
+ return !isBlockedIngestHost(u.hostname);
};
export const catalogUrlIngestSchema = z.object({
diff --git a/server/lib/catalogValidation.test.js b/server/lib/catalogValidation.test.js
index 8469ba2bf9..66563d4a8b 100644
--- a/server/lib/catalogValidation.test.js
+++ b/server/lib/catalogValidation.test.js
@@ -475,4 +475,12 @@ describe('catalogUrlIngestSchema — SSRF guard', () => {
expect(() => catalogUrlIngestSchema.parse({ url: 'http://127.0.0.1/x' })).toThrow();
expect(() => catalogUrlIngestSchema.parse({ url: 'http://metadata.google.internal/x' })).toThrow();
});
+
+ it('rejects IPv4-mapped IPv6 loopback/link-local + unspecified literals (no bypass)', () => {
+ // WHATWG normalizes [::ffff:127.0.0.1] → [::ffff:7f00:1]; both must reject.
+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://[::ffff:127.0.0.1]/x' })).toThrow();
+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://[::ffff:169.254.169.254]/x' })).toThrow();
+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://[::]/x' })).toThrow();
+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://0.0.0.0/x' })).toThrow();
+ });
});
diff --git a/server/services/catalogIngestSources.js b/server/services/catalogIngestSources.js
index 21c2b2a075..173844bc25 100644
--- a/server/services/catalogIngestSources.js
+++ b/server/services/catalogIngestSources.js
@@ -30,6 +30,7 @@ import {
evaluateOnPage,
} from './browserService.js';
import { PATHS, ensureDir } from '../lib/fileUtils.js';
+import { isSafeIngestUrl } 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.
@@ -83,6 +84,15 @@ export async function fetchUrlMainText(url, { settleMs = PAGE_SETTLE_MS } = {})
|| pages[0];
if (!page) throw new Error('browser tab not found after navigation');
+ // Re-validate the FINAL url before reading the DOM: the request-body URL
+ // passed the SSRF guard, but a server-controlled redirect could have sent
+ // Chrome to a blocked target (127.0.0.1, 169.254.169.254, …). The schema
+ // guard only covers the first hop, so re-check here against the landed URL.
+ const landedUrl = page.url || opened.url || url;
+ if (!isSafeIngestUrl(landedUrl)) {
+ throw new Error('refusing to ingest a redirect to a blocked (loopback/link-local) host');
+ }
+
// 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
// plain string so evaluateOnPage's returnByValue marshals it cleanly.
diff --git a/server/services/catalogIngestSources.test.js b/server/services/catalogIngestSources.test.js
index d5d41d59c4..39522e3e1e 100644
--- a/server/services/catalogIngestSources.test.js
+++ b/server/services/catalogIngestSources.test.js
@@ -76,6 +76,15 @@ describe('fetchUrlMainText', () => {
expect(catalogDB.createScrap).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
+ // to a loopback target — the landed page.url is what we must re-check.
+ 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(/redirect to a blocked/);
+ expect(browserService.evaluateOnPage).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' }]);