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
review: harden SSRF host guard against IPv4-compatible-IPv6 + trailing-dot bypasses
[._.]/ Adam Eivyd7249a96d534
diff --git a/server/lib/catalogValidation.js b/server/lib/catalogValidation.jsindex 4addfc051a..8c996500cf 100644--- a/server/lib/catalogValidation.js+++ b/server/lib/catalogValidation.js@@ -80,23 +80,35 @@ export const catalogScrapPatchSchema = catalogScrapCreateSchema.partial();// 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.+// and the unspecified address — in plain IPv4, IPv6, IPv4-mapped-IPv6+// (`::ffff:127.0.0.1` → WHATWG-hex `::ffff:7f00:1`), AND the deprecated+// IPv4-compatible-IPv6 form (`::127.0.0.1` → `::7f00:1`), so the guard can't be+// bypassed by embedding a blocked v4 address inside an IPv6 literal. A trailing+// FQDN dot (`localhost.`, `127.0.0.1.`) is stripped first since resolvers treat+// it as equivalent. NOTE: decimal / hex / octal / shorthand IPv4 (`2130706433`,+// `0x7f000001`, `127.1`) need no special handling — `new URL()` already+// normalizes them to canonical dotted-quad in `.hostname` before this runs. We+// deliberately ALLOW other private/LAN hosts (incl. IPv6 ULA `fd00::/8`):+// reaching a Tailscale peer or home-network wiki is a legit use of this+// single-user tool. This is a host-literal guard, not a DNS-resolution or+// post-redirect check — a hostname that RESOLVES to loopback, or a redirect to+// a blocked host, is not caught here.export const isBlockedIngestHost = (host) => {- const h = host.toLowerCase().replace(/^\[|\]$/g, '');+ const h = host.toLowerCase().replace(/^\[|\]$/g, '').replace(/\.+$/, '');if (h === 'localhost' || h.endsWith('.localhost') || h === 'metadata.google.internal') return true;if (h === '::1' || h === '::' || h === '0.0.0.0') return true;// IPv6 link-local fe80::/10 (first hextet fe80–febf), e.g. [fe80::1].if (h.includes(':') && /^fe[89ab][0-9a-f]?:/i.test(h)) 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];+ // A blocked v4 address embedded in an IPv6 literal — either IPv4-mapped+ // (`::ffff:…`) or the deprecated IPv4-compatible (`::…`) form. WHATWG+ // normalizes the trailing v4 to a pair of hex hextets (`7f00:1`), or keeps it+ // dotted in older inputs; handle both. A `::ffff:`-less match also catches the+ // compatible form; the real `::1` / `::` cases were already returned above.+ const embedded = /^::(?:ffff:)?(.+)$/i.exec(h);+ if (embedded) {+ const tail = embedded[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))) {diff --git a/server/lib/catalogValidation.test.js b/server/lib/catalogValidation.test.jsindex 4911540f09..a38c1831d1 100644--- a/server/lib/catalogValidation.test.js+++ b/server/lib/catalogValidation.test.js@@ -488,4 +488,23 @@ describe('catalogUrlIngestSchema — SSRF guard', () => {expect(() => catalogUrlIngestSchema.parse({ url: 'http://[fe80::1]/x' })).toThrow();expect(() => catalogUrlIngestSchema.parse({ url: 'http://[febf::dead]/x' })).toThrow();});++ it('rejects deprecated IPv4-COMPATIBLE IPv6 literals embedding a blocked v4', () => {+ // [::127.0.0.1] → WHATWG-hex [::7f00:1] (NOT ::ffff:), and+ // [::169.254.169.254] → [::a9fe:a9fe]; both must reject like the mapped form.+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://[::127.0.0.1]/x' })).toThrow();+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://[::169.254.169.254]/x' })).toThrow();+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://[0:0:0:0:0:0:7f00:1]/x' })).toThrow();+ });++ it('rejects trailing-FQDN-dot loopback (resolvers treat it as equivalent)', () => {+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://localhost./x' })).toThrow();+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://127.0.0.1./x' })).toThrow();+ });++ it('still ACCEPTS a LAN host embedded as IPv4-compatible IPv6 (allow-LAN policy holds)', () => {+ // [::192.168.0.1] → [::c0a8:1] decodes to a private LAN v4 → allowed, same as+ // the bare 192.168.x case above. Confirms the new branch doesn't over-block.+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://[::192.168.0.1]/x' })).not.toThrow();+ });});diff --git a/server/routes/browser.js b/server/routes/browser.jsindex 7a62730cd0..a2e4338e7d 100644--- a/server/routes/browser.js+++ b/server/routes/browser.js@@ -10,11 +10,15 @@ const router = express.Router();// Validation schemas// SSRF guard (shared with catalog URL ingest): reject non-http(s) schemes-// (file:/chrome:/javascript:) and loopback / link-local / cloud-metadata hosts-// so a redirect or agent-driven navigate can't turn this into local-file-// exfiltration or a metadata-endpoint hit. Private/LAN + Tailscale hosts stay+// (file:/chrome:/javascript:) and loopback / link-local / cloud-metadata host+// LITERALS so an agent-driven navigate can't directly target local-file+// exfiltration or a metadata endpoint. Private/LAN + Tailscale hosts stay// allowed (a single-user tool legitimately drives its browser there);// `localhost`/`127.x` are blocked — navigate by LAN IP/hostname for a local app.+// This is a host-literal guard, not a DNS-resolution / post-redirect check: a+// hostname that RESOLVES to loopback, or a server-side redirect the CDP browser+// then follows to a blocked host, is out of scope here (the browser, not this+// route, performs the redirect fetch).const navigateSchema = z.object({url: z.string().url().refine(isSafeIngestUrl, 'only http(s) URLs to non-loopback/non-link-local hosts are allowed')diff --git a/server/routes/browser.test.js b/server/routes/browser.test.jsindex b248018bee..15f3451976 100644--- a/server/routes/browser.test.js+++ b/server/routes/browser.test.js@@ -85,6 +85,19 @@ describe('POST /api/browser/navigate — SSRF guard', () => {expect(navigateToUrl).not.toHaveBeenCalled();});+ it('rejects IPv4-compatible-IPv6 + trailing-dot bypasses', async () => {+ for (const url of [+ 'http://[::127.0.0.1]/', // → ::7f00:1 (compatible, not ::ffff:)+ 'http://[::169.254.169.254]/', // → ::a9fe:a9fe+ 'http://localhost./', // trailing FQDN dot+ 'http://127.0.0.1./',+ ]) {+ const r = await navigate(url);+ expect(r.status, url).toBe(400);+ }+ expect(navigateToUrl).not.toHaveBeenCalled();+ });+it('rejects a non-URL string', async () => {const r = await navigate('not a url');expect(r.status).toBe(400);