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([feeds-ssrf-aaaa-record-blindness]): address codex review — fail closed on resolver errors

[._.]/ Adam Eivy3a6c338515de
diff --git a/server/services/feeds.js b/server/services/feeds.js
index a246e6f507..8d18025a54 100644
--- a/server/services/feeds.js
+++ b/server/services/feeds.js
@@ -428,6 +428,13 @@ function isPrivateIP(ip) {
return false;
}
+// DNS error codes that mean "this record type does not exist" — safe to treat
+// as an empty result. Anything else (SERVFAIL, TIMEOUT, CONNREFUSED, …) is a
+// resolver failure that can't prove the family is safe; we must fail closed
+// because Node's fetch performs its own lookup and may still happy-eyeballs to
+// a private address we never got to inspect.
+const BENIGN_DNS_MISS_CODES = new Set(['ENOTFOUND', 'ENODATA', 'NODATA', 'NOTFOUND']);
+
// Resolve hostname and verify it doesn't point to a private IP. Resolves A
// and AAAA in parallel so a hostname with a public A but a private AAAA
// (happy-eyeballs would prefer the AAAA in Node's fetch) is rejected; the
@@ -439,11 +446,16 @@ async function isHostSafe(hostname) {
? hostname.slice(1, -1)
: hostname;
if (net.isIP(stripped)) return !isPrivateIP(stripped);
+ const wrap = (p) => p.then(
+ addrs => ({ ok: true, addrs }),
+ err => BENIGN_DNS_MISS_CODES.has(err?.code) ? { ok: true, addrs: [] } : { ok: false, addrs: [] },
+ );
const [v4, v6] = await Promise.all([
- dns.resolve4(stripped).catch(() => []),
- dns.resolve6(stripped).catch(() => []),
+ wrap(dns.resolve4(stripped)),
+ wrap(dns.resolve6(stripped)),
]);
- const addresses = [...v4, ...v6];
+ if (!v4.ok || !v6.ok) return false;
+ const addresses = [...v4.addrs, ...v6.addrs];
if (addresses.length === 0) return false;
return addresses.every(addr => !isPrivateIP(addr));
}
diff --git a/server/services/feeds.test.js b/server/services/feeds.test.js
index 81150d325e..6446f4a5f9 100644
--- a/server/services/feeds.test.js
+++ b/server/services/feeds.test.js
@@ -237,6 +237,39 @@ describe('addFeed', () => {
expect(fetchMock).not.toHaveBeenCalled();
});
+ it('rejects when AAAA resolver fails (SERVFAIL) even if A is public (fail-closed)', async () => {
+ // Node's fetch may still happy-eyeballs to a private AAAA on its own
+ // lookup, so a resolver error on AAAA must reject — we cannot prove
+ // the family is safe to fall through to the A result alone.
+ const err = Object.assign(new Error('servfail'), { code: 'ESERVFAIL' });
+ dnsResolveMock.mockResolvedValue(['93.184.216.34']);
+ dnsResolve6Mock.mockRejectedValue(err);
+ const result = await feeds.addFeed('https://flaky-aaaa.example.com/rss');
+ expect(result).toEqual({ error: FETCH_ERROR });
+ expect(fetchMock).not.toHaveBeenCalled();
+ });
+
+ it('accepts when AAAA returns NODATA and A is public (benign no-records miss)', async () => {
+ // ENODATA means "name exists, no records of this type" — the other
+ // family covers the hostname and we should not fail closed on it.
+ const err = Object.assign(new Error('no data'), { code: 'ENODATA' });
+ fetchMock.mockResolvedValue(makeResponse({ body: RSS_FIXTURE }));
+ dnsResolveMock.mockResolvedValue(['93.184.216.34']);
+ dnsResolve6Mock.mockRejectedValue(err);
+ const result = await feeds.addFeed('https://a-only.example.com/rss');
+ expect(result.error).toBeUndefined();
+ expect(fetchMock).toHaveBeenCalledTimes(1);
+ });
+
+ it('rejects when A resolver fails (TIMEOUT) even if AAAA is public (fail-closed)', async () => {
+ const err = Object.assign(new Error('timeout'), { code: 'ETIMEOUT' });
+ dnsResolveMock.mockRejectedValue(err);
+ dnsResolve6Mock.mockResolvedValue(['2606:4700:4700::1111']);
+ const result = await feeds.addFeed('https://flaky-a.example.com/rss');
+ expect(result).toEqual({ error: FETCH_ERROR });
+ expect(fetchMock).not.toHaveBeenCalled();
+ });
+
it('follows a single safe redirect to the new URL', async () => {
fetchMock
.mockResolvedValueOnce(makeResponse({ status: 302, headers: { location: 'https://example.com/final.xml' } }))