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): DNS re-check on redirected URL, block IPv6 link-local fe80::/10, release mic when starting another ingest flow

[._.]/ Adam Eivy0d8df82b4508
diff --git a/client/src/pages/CatalogIngest.jsx b/client/src/pages/CatalogIngest.jsx
index 76a0bfbb9a..59cf67caad 100644
--- a/client/src/pages/CatalogIngest.jsx
+++ b/client/src/pages/CatalogIngest.jsx
@@ -91,6 +91,18 @@ export default function CatalogIngest() {
// MediaRecorder stream isn't left live with no UI to stop it.
useEffect(() => () => { recorderRef.current?.cancel?.(); }, []);
+ // Any transition OUT of the paste phase that isn't the voice flow's own
+ // stop-and-transcribe (which nulls recorderRef before switching) must release
+ // the mic — otherwise starting File/URL/Paste ingest mid-recording hides the
+ // stop control while the stream stays live.
+ useEffect(() => {
+ if (phase !== 'paste' && recorderRef.current) {
+ recorderRef.current.cancel?.();
+ recorderRef.current = null;
+ setRecording(false);
+ }
+ }, [phase]);
+
// Track active runId so a stale frame from an earlier scrap can't mutate the
// current stage list (server fans these to all sockets — single-user trust
// model still applies, but tab refresh + a slow extract overlap is real).
diff --git a/server/lib/catalogValidation.js b/server/lib/catalogValidation.js
index 8022f7d992..4addfc051a 100644
--- a/server/lib/catalogValidation.js
+++ b/server/lib/catalogValidation.js
@@ -89,6 +89,8 @@ export 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;
+ // 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`.
diff --git a/server/lib/catalogValidation.test.js b/server/lib/catalogValidation.test.js
index 66563d4a8b..4911540f09 100644
--- a/server/lib/catalogValidation.test.js
+++ b/server/lib/catalogValidation.test.js
@@ -483,4 +483,9 @@ describe('catalogUrlIngestSchema — SSRF guard', () => {
expect(() => catalogUrlIngestSchema.parse({ url: 'http://[::]/x' })).toThrow();
expect(() => catalogUrlIngestSchema.parse({ url: 'http://0.0.0.0/x' })).toThrow();
});
+
+ it('rejects native IPv6 link-local (fe80::/10) literals', () => {
+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://[fe80::1]/x' })).toThrow();
+ expect(() => catalogUrlIngestSchema.parse({ url: 'http://[febf::dead]/x' })).toThrow();
+ });
});
diff --git a/server/services/catalogIngestSources.js b/server/services/catalogIngestSources.js
index a3069d71f0..79c712c49e 100644
--- a/server/services/catalogIngestSources.js
+++ b/server/services/catalogIngestSources.js
@@ -61,6 +61,29 @@ async function createScrapAndExtract({ title, rawText, sourceKind, metadata, pro
return { scrap, draft };
}
+/**
+ * Full SSRF gate for an ingest URL: scheme + blocked-literal check (sync), AND
+ * a DNS resolve so a hostname whose A record points at a blocked address
+ * (cloud metadata / loopback / link-local) is rejected too. Applied to BOTH the
+ * request-body URL and the post-redirect landed URL — a redirect to such a
+ * hostname must be caught the same way as the first hop. (Residual TOCTOU —
+ * Chrome re-resolves independently — is acceptable on a single-user private
+ * network; this closes the realistic record-points-at-metadata vector.)
+ */
+async function assertIngestUrlSafe(target) {
+ if (!isSafeIngestUrl(target)) {
+ throw new Error('refusing to ingest a non-http(s) or loopback/link-local URL');
+ }
+ const { hostname } = new URL(target);
+ const isIpLiteral = /^[\d.]+$/.test(hostname) || hostname.includes(':');
+ if (!isIpLiteral) {
+ const resolved = await lookup(hostname).catch(() => null);
+ if (resolved?.address && isBlockedIngestHost(resolved.address)) {
+ throw new Error('refusing to ingest a host that resolves to a blocked (loopback/link-local) address');
+ }
+ }
+}
+
/**
* Fetch a URL through the browser service and return its main text + title.
* Uses CDP (the same headed/headless Chrome the rest of PortOS drives) so
@@ -72,20 +95,7 @@ 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 } = {}) {
- // DNS guard: the schema rejects blocked IP LITERALS, but a hostname can
- // resolve to a blocked address (DNS record / rebinding pointing at
- // 169.254.169.254, loopback, …). Resolve it and reject before we navigate.
- // (Residual TOCTOU — Chrome re-resolves independently — is acceptable on a
- // single-user private network; this closes the realistic record-points-at-
- // metadata vector and is paired with the post-navigation re-check below.)
- const { hostname } = new URL(url);
- const isIpLiteral = /^[\d.]+$/.test(hostname) || hostname.includes(':');
- if (!isIpLiteral) {
- const resolved = await lookup(hostname).catch(() => null);
- if (resolved?.address && isBlockedIngestHost(resolved.address)) {
- throw new Error('refusing to ingest a host that resolves to a blocked (loopback/link-local) address');
- }
- }
+ await assertIngestUrlSafe(url);
// `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
@@ -102,14 +112,12 @@ export async function fetchUrlMainText(url, { settleMs = PAGE_SETTLE_MS } = {})
|| pages.find((p) => p.url === opened.url);
if (!page) throw new Error('could not match the navigated tab after navigation (refusing to read an arbitrary tab)');
- // 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.
+ // Re-run the FULL gate (scheme + DNS) against the FINAL url before reading the
+ // DOM: a server-controlled redirect could have sent Chrome to a blocked
+ // target, or to a hostname that itself resolves to one. The first-hop gate
+ // doesn't cover the landed page.
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');
- }
+ await assertIngestUrlSafe(landedUrl);
// 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
diff --git a/server/services/catalogIngestSources.test.js b/server/services/catalogIngestSources.test.js
index 94689abbc8..93146a505d 100644
--- a/server/services/catalogIngestSources.test.js
+++ b/server/services/catalogIngestSources.test.js
@@ -94,7 +94,18 @@ describe('fetchUrlMainText', () => {
// 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/);
+ await expect(fetchUrlMainText('https://ex.com/a', { settleMs: 0 })).rejects.toThrow(/loopback|link-local/);
+ expect(browserService.evaluateOnPage).not.toHaveBeenCalled();
+ });
+
+ it('refuses a redirect to a HOSTNAME that resolves to a blocked address (DNS re-check on landed url)', async () => {
+ // First hop resolves safe; the landed redirect host resolves to metadata.
+ dnsp.lookup
+ .mockResolvedValueOnce({ address: '93.184.216.34', family: 4 })
+ .mockResolvedValueOnce({ address: '169.254.169.254', family: 4 });
+ browserService.navigateToUrl.mockResolvedValue({ id: 'p1', url: 'https://ex.com/a' });
+ browserService.listCdpPages.mockResolvedValue([{ id: 'p1', url: 'https://evil.example/x', title: 'x', webSocketDebuggerUrl: 'ws://x' }]);
+ await expect(fetchUrlMainText('https://ex.com/a', { settleMs: 0 })).rejects.toThrow(/resolves to a blocked/);
expect(browserService.evaluateOnPage).not.toHaveBeenCalled();
});