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

fix: revalidate browser navigate by resolved IP + Chrome connect address (#2517)

Adam Eivy3d4eeff337d0
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 00e8a76a66..11ae3bd239 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -3,6 +3,7 @@
## Security
- **[issue-2514] Harden AI provider custom endpoints against SSRF / API-key exfiltration.** A provider's `endpoint` is a free-form URL, and model-refresh / API-run paths attached the paid `Authorization: Bearer <apiKey>` and fetched that host with no host checks — a hostile or mistyped endpoint could receive the user's paid LLM key and prompts, or be pointed at a cloud-metadata service (`169.254.169.254`). A new `endpointGuard` now gates every secret-bearing request: loopback/LAN (Tailscale) and known paid-provider hosts are allowed, cloud-metadata hosts are always blocked, and any other host requires the new per-provider **Allow custom endpoint** opt-in. Keyless local-LLM calls (Ollama/LM Studio) are unaffected.
+- **[issue-2517] Revalidate the browser navigate URL by resolved IP and by Chrome's actual per-hop connect address.** `POST /api/browser/navigate` only checked the host LITERAL with `isSafeIngestUrl`, so a hostname whose A record rebinds to loopback/link-local/cloud-metadata, or a post-navigate redirect the CDP browser silently follows to a blocked host, slipped past. The route now adds a DNS-resolve pre-check (`assertPublicHttpUrl`) that refuses a hostname resolving to a blocked address before any tab is opened, and drives the navigation through `navigateToUrlPinned` — the same connect-time pin the catalog URL ingest uses — which verifies Chrome's own reported `remoteIPAddress` for the initial nav, every HTTP redirect, and any client-side navigation in the settle window, tearing the tab down and failing closed on a blocked hop. LAN/Tailscale hosts stay intentionally allowed. Residual: a WebSocket to a hostname that DNS-rebinds to a private IP can't be pinned via CDP interception (no `remoteIPAddress` on WS events) — bounded by the single-user trust model and documented in `browserService.ssrfPinRefusalReason`.
## Fixed
diff --git a/server/routes/browser.js b/server/routes/browser.js
index 8f70ccb472..d838960afa 100644
--- a/server/routes/browser.js
+++ b/server/routes/browser.js
@@ -3,11 +3,18 @@ import { z } from 'zod';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { validateRequest } from '../lib/validation.js';
import { validateChromePath, validateMacAppBundle } from '../lib/browserConfig.js';
-import { isSafeIngestUrl } from '../lib/catalogValidation.js';
+import { isSafeIngestUrl, isBlockedIngestHost } from '../lib/catalogValidation.js';
+import { assertPublicHttpUrl } from '../lib/safeUrlFetch.js';
import * as browserService from '../services/browserService.js';
const router = express.Router();
+// Settle window the pinned navigate holds open after the first document response
+// so a client-side redirect (meta-refresh / location.replace) that fires just
+// after load is captured and IP-verified too, not just the initial nav + HTTP
+// redirect chain. Small so an interactive "open this URL" stays responsive.
+const NAVIGATE_SETTLE_MS = 1000;
+
// Validation schemas
// SSRF guard (shared with catalog URL ingest): reject non-http(s) schemes
// (file:/chrome:/javascript:) and loopback / link-local / cloud-metadata host
@@ -15,10 +22,12 @@ const router = express.Router();
// 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).
+// This is the FIRST of three layers — a host-literal guard. The hostname→blocked
+// (DNS-rebinding) and post-navigate-redirect gaps it can't see are closed in the
+// handler: a DNS-resolve pre-check (`assertPublicHttpUrl`) rejects a hostname
+// whose A record points at a blocked address, and the CDP pin
+// (`navigateToUrlPinned`) verifies Chrome's ACTUAL per-hop connect IP for the
+// initial nav, every redirect, and any settle-window navigation.
const navigateSchema = z.object({
url: z.string().url()
.refine(isSafeIngestUrl, 'only http(s) URLs to non-loopback/non-link-local hosts are allowed')
@@ -111,7 +120,21 @@ router.post('/navigate', asyncHandler(async (req, res) => {
const caller = req.headers['referer'] || req.headers['origin'] || 'unknown';
console.log(`🌐 Navigate: ${req.body?.url} (from ${caller})`);
const { url } = validateRequest(navigateSchema, req.body);
- const page = await browserService.navigateToUrl(url);
+ // Layer 2 — DNS-resolve pre-check: reject a hostname whose A record points at a
+ // blocked (loopback / link-local / cloud-metadata) address BEFORE opening a
+ // tab. Throws a clean 400 (UNSAFE_URL) via the shared safeUrlFetch gate; an
+ // IP-literal target skips the lookup (isSafeIngestUrl already classified it).
+ await assertPublicHttpUrl(url);
+ // Layer 3 — connect-time pin: Chrome resolves DNS itself, so a rebinding answer
+ // (or a server-side redirect) could still steer it to a blocked address after
+ // the pre-check. navigateToUrlPinned verifies, against Chrome's OWN reported
+ // remoteIPAddress, that the initial nav, EVERY HTTP redirect hop, and any
+ // client-side navigation during the settle window connected to an allowed
+ // address — tearing the tab down and failing closed (throws) otherwise.
+ const page = await browserService.navigateToUrlPinned(url, {
+ verifyRemoteIp: (ip) => !isBlockedIngestHost(ip),
+ settleMs: NAVIGATE_SETTLE_MS,
+ });
res.json(page);
}));
diff --git a/server/routes/browser.test.js b/server/routes/browser.test.js
index 15f3451976..424a5534e1 100644
--- a/server/routes/browser.test.js
+++ b/server/routes/browser.test.js
@@ -1,12 +1,23 @@
/**
* SSRF-guard boundary tests for POST /api/browser/navigate.
*
- * The navigate route reuses the catalog ingest guard (isSafeIngestUrl): http(s)
- * only, and loopback / link-local / cloud-metadata hosts blocked — including
- * IPv4-mapped-IPv6 bypass forms. Private/LAN hosts stay allowed (a single-user
- * tool legitimately drives its browser to a Tailscale peer or home-network app).
- * browserService is mocked so a rejected URL never reaches CDP and an accepted
- * one doesn't launch a real browser.
+ * The navigate route defends in three layers:
+ * 1. Host-literal Zod refine (isSafeIngestUrl): http(s) only, and loopback /
+ * link-local / cloud-metadata host LITERALS blocked — including
+ * IPv4-mapped-IPv6 bypass forms. Private/LAN hosts stay allowed (a
+ * single-user tool legitimately drives its browser to a Tailscale peer or
+ * home-network app).
+ * 2. DNS-resolve pre-check (assertPublicHttpUrl): a HOSTNAME whose A record
+ * points at a blocked address is rejected before a tab is opened — closing
+ * the DNS-rebinding gap the literal guard can't see.
+ * 3. CDP connect-time pin (navigateToUrlPinned): Chrome's ACTUAL per-hop
+ * connect IP (initial nav + every redirect + settle-window navigation) is
+ * verified against isBlockedIngestHost, so a rebind/redirect to a blocked
+ * host after the pre-check still fails closed.
+ *
+ * dns/promises is mocked so the resolve pre-check is hermetic (no real network),
+ * and browserService is mocked so a rejected URL never reaches CDP and an
+ * accepted one doesn't launch a real browser.
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
@@ -14,9 +25,14 @@ import express from 'express';
import { request } from '../lib/testHelper.js';
import { errorMiddleware } from '../lib/errorHandler.js';
-const navigateToUrl = vi.fn(async (url) => ({ ok: true, url }));
+// Default: every hostname resolves to a public address (allowed). Individual
+// tests override this to simulate a hostname that rebinds to a blocked IP.
+const lookup = vi.fn(async () => ({ address: '93.184.216.34', family: 4 }));
+vi.mock('dns/promises', () => ({ default: { lookup }, lookup }));
+
+const navigateToUrlPinned = vi.fn(async (url) => ({ id: 'tab-1', url }));
vi.mock('../services/browserService.js', () => ({
- navigateToUrl: (...a) => navigateToUrl(...a),
+ navigateToUrlPinned: (...a) => navigateToUrlPinned(...a),
// other exports are referenced by sibling routes but not by these tests
restartBrowser: vi.fn(),
getHealthStatus: vi.fn(),
@@ -36,13 +52,31 @@ function makeApp() {
const navigate = (url) => request(makeApp()).post('/api/browser/navigate').send({ url });
-beforeEach(() => vi.clearAllMocks());
+beforeEach(() => {
+ vi.clearAllMocks();
+ lookup.mockResolvedValue({ address: '93.184.216.34', family: 4 });
+});
describe('POST /api/browser/navigate — SSRF guard', () => {
- it('accepts a normal https URL and forwards it to the browser service', async () => {
+ it('accepts a normal https URL and pins it through the browser service', async () => {
const r = await navigate('https://example.com/');
expect(r.status).toBe(200);
- expect(navigateToUrl).toHaveBeenCalledWith('https://example.com/');
+ expect(navigateToUrlPinned).toHaveBeenCalledWith('https://example.com/', expect.objectContaining({
+ verifyRemoteIp: expect.any(Function),
+ settleMs: expect.any(Number),
+ }));
+ });
+
+ it('pins with a predicate that rejects blocked connect IPs and allows public/LAN ones', async () => {
+ await navigate('https://example.com/');
+ const { verifyRemoteIp } = navigateToUrlPinned.mock.calls[0][1];
+ // Blocked: loopback, link-local, cloud-metadata
+ expect(verifyRemoteIp('127.0.0.1')).toBe(false);
+ expect(verifyRemoteIp('169.254.169.254')).toBe(false);
+ expect(verifyRemoteIp('::1')).toBe(false);
+ // Allowed: public + private/LAN (Tailscale/home-network navigation stays usable)
+ expect(verifyRemoteIp('93.184.216.34')).toBe(true);
+ expect(verifyRemoteIp('192.168.1.10')).toBe(true);
});
it('accepts private / LAN hosts (intentionally allowed)', async () => {
@@ -50,7 +84,7 @@ describe('POST /api/browser/navigate — SSRF guard', () => {
const r = await navigate(url);
expect(r.status, url).toBe(200);
}
- expect(navigateToUrl).toHaveBeenCalledTimes(3);
+ expect(navigateToUrlPinned).toHaveBeenCalledTimes(3);
});
it('rejects non-http(s) schemes (file:/chrome:/javascript:)', async () => {
@@ -58,7 +92,7 @@ describe('POST /api/browser/navigate — SSRF guard', () => {
const r = await navigate(url);
expect(r.status, url).toBe(400);
}
- expect(navigateToUrl).not.toHaveBeenCalled();
+ expect(navigateToUrlPinned).not.toHaveBeenCalled();
});
it('rejects loopback hosts', async () => {
@@ -66,7 +100,7 @@ describe('POST /api/browser/navigate — SSRF guard', () => {
const r = await navigate(url);
expect(r.status, url).toBe(400);
}
- expect(navigateToUrl).not.toHaveBeenCalled();
+ expect(navigateToUrlPinned).not.toHaveBeenCalled();
});
it('rejects link-local and cloud-metadata hosts', async () => {
@@ -74,7 +108,7 @@ describe('POST /api/browser/navigate — SSRF guard', () => {
const r = await navigate(url);
expect(r.status, url).toBe(400);
}
- expect(navigateToUrl).not.toHaveBeenCalled();
+ expect(navigateToUrlPinned).not.toHaveBeenCalled();
});
it('rejects IPv4-mapped-IPv6 loopback/link-local bypasses', async () => {
@@ -82,7 +116,7 @@ describe('POST /api/browser/navigate — SSRF guard', () => {
const r = await navigate(url);
expect(r.status, url).toBe(400);
}
- expect(navigateToUrl).not.toHaveBeenCalled();
+ expect(navigateToUrlPinned).not.toHaveBeenCalled();
});
it('rejects IPv4-compatible-IPv6 + trailing-dot bypasses', async () => {
@@ -95,12 +129,33 @@ describe('POST /api/browser/navigate — SSRF guard', () => {
const r = await navigate(url);
expect(r.status, url).toBe(400);
}
- expect(navigateToUrl).not.toHaveBeenCalled();
+ expect(navigateToUrlPinned).not.toHaveBeenCalled();
+ });
+
+ it('rejects a hostname that DNS-rebinds to a blocked address (never opens a tab)', async () => {
+ // Passes the host-literal guard (rebind.example is not a blocked literal) but
+ // its A record resolves to loopback / cloud-metadata — the DNS-resolve
+ // pre-check must catch it before navigateToUrlPinned is ever called.
+ for (const address of ['127.0.0.1', '169.254.169.254']) {
+ lookup.mockResolvedValueOnce({ address, family: 4 });
+ const r = await navigate('http://rebind.example/');
+ expect(r.status, address).toBe(400);
+ }
+ expect(navigateToUrlPinned).not.toHaveBeenCalled();
+ });
+
+ it('fails closed when a hostname cannot be resolved', async () => {
+ // An unresolvable name can't be vetted → can't be safely pinned → refuse
+ // rather than fall through to an unpinned navigate that re-resolves.
+ lookup.mockRejectedValueOnce(new Error('ENOTFOUND'));
+ const r = await navigate('http://does-not-resolve.example/');
+ expect(r.status).toBe(400);
+ expect(navigateToUrlPinned).not.toHaveBeenCalled();
});
it('rejects a non-URL string', async () => {
const r = await navigate('not a url');
expect(r.status).toBe(400);
- expect(navigateToUrl).not.toHaveBeenCalled();
+ expect(navigateToUrlPinned).not.toHaveBeenCalled();
});
});