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(security): SSRF guard on POST /api/browser/navigate

[._.]/ Adam Eivy27f3242d5d8f
diff --git a/server/routes/browser.js b/server/routes/browser.js
index 1fa3947a9a..7a62730cd0 100644
--- a/server/routes/browser.js
+++ b/server/routes/browser.js
@@ -1,14 +1,23 @@
import express from 'express';
import { z } from 'zod';
import { asyncHandler } from '../lib/errorHandler.js';
+import { validateRequest } from '../lib/validation.js';
import { validateChromePath, validateMacAppBundle } from '../lib/browserConfig.js';
+import { isSafeIngestUrl } from '../lib/catalogValidation.js';
import * as browserService from '../services/browserService.js';
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
+// allowed (a single-user tool legitimately drives its browser there);
+// `localhost`/`127.x` are blocked — navigate by LAN IP/hostname for a local app.
const navigateSchema = z.object({
url: z.string().url()
+ .refine(isSafeIngestUrl, 'only http(s) URLs to non-loopback/non-link-local hosts are allowed')
});
// Empty string from a "clear" UI action → unset (undefined), so the launcher
@@ -95,7 +104,7 @@ router.post('/restart', asyncHandler(async (req, res) => {
// POST /api/browser/navigate - Open a URL in the CDP browser
router.post('/navigate', asyncHandler(async (req, res) => {
- const { url } = navigateSchema.parse(req.body);
+ const { url } = validateRequest(navigateSchema, req.body);
console.log(`🌐 Navigate requested: ${url}`);
const page = await browserService.navigateToUrl(url);
res.json(page);
diff --git a/server/routes/browser.test.js b/server/routes/browser.test.js
new file mode 100644
index 0000000000..b248018bee
--- /dev/null
+++ b/server/routes/browser.test.js
@@ -0,0 +1,93 @@
+/**
+ * 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.
+ */
+
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+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 }));
+vi.mock('../services/browserService.js', () => ({
+ navigateToUrl: (...a) => navigateToUrl(...a),
+ // other exports are referenced by sibling routes but not by these tests
+ restartBrowser: vi.fn(),
+ getHealthStatus: vi.fn(),
+ getBrowserStatus: vi.fn(),
+ getBrowserLogs: vi.fn(),
+}));
+
+const router = (await import('./browser.js')).default;
+
+function makeApp() {
+ const app = express();
+ app.use(express.json());
+ app.use('/api/browser', router);
+ app.use(errorMiddleware);
+ return app;
+}
+
+const navigate = (url) => request(makeApp()).post('/api/browser/navigate').send({ url });
+
+beforeEach(() => vi.clearAllMocks());
+
+describe('POST /api/browser/navigate — SSRF guard', () => {
+ it('accepts a normal https URL and forwards it to the browser service', async () => {
+ const r = await navigate('https://example.com/');
+ expect(r.status).toBe(200);
+ expect(navigateToUrl).toHaveBeenCalledWith('https://example.com/');
+ });
+
+ it('accepts private / LAN hosts (intentionally allowed)', async () => {
+ for (const url of ['http://192.168.1.10/', 'http://10.0.0.5:8080/', 'http://my-nas.local/']) {
+ const r = await navigate(url);
+ expect(r.status, url).toBe(200);
+ }
+ expect(navigateToUrl).toHaveBeenCalledTimes(3);
+ });
+
+ it('rejects non-http(s) schemes (file:/chrome:/javascript:)', async () => {
+ for (const url of ['file:///etc/passwd', 'chrome://settings', 'javascript:alert(1)', 'ftp://host/x']) {
+ const r = await navigate(url);
+ expect(r.status, url).toBe(400);
+ }
+ expect(navigateToUrl).not.toHaveBeenCalled();
+ });
+
+ it('rejects loopback hosts', async () => {
+ for (const url of ['http://localhost:3000/', 'http://127.0.0.1/', 'http://[::1]/', 'http://0.0.0.0/']) {
+ const r = await navigate(url);
+ expect(r.status, url).toBe(400);
+ }
+ expect(navigateToUrl).not.toHaveBeenCalled();
+ });
+
+ it('rejects link-local and cloud-metadata hosts', async () => {
+ for (const url of ['http://169.254.169.254/latest/meta-data/', 'http://[fe80::1]/', 'http://metadata.google.internal/']) {
+ const r = await navigate(url);
+ expect(r.status, url).toBe(400);
+ }
+ expect(navigateToUrl).not.toHaveBeenCalled();
+ });
+
+ it('rejects IPv4-mapped-IPv6 loopback/link-local bypasses', async () => {
+ for (const url of ['http://[::ffff:127.0.0.1]/', 'http://[::ffff:169.254.169.254]/']) {
+ 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);
+ expect(navigateToUrl).not.toHaveBeenCalled();
+ });
+});