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]): resolve A + AAAA in parallel for SSRF guard

[._.]/ Adam Eivy354529fd17d2
diff --git a/server/services/feeds.js b/server/services/feeds.js
index 4574cc8ce6..a246e6f507 100644
--- a/server/services/feeds.js
+++ b/server/services/feeds.js
@@ -428,7 +428,10 @@ function isPrivateIP(ip) {
return false;
}
-// Resolve hostname and verify it doesn't point to a private IP
+// 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
+// parallel AAAA lookup also lets AAAA-only feeds resolve.
async function isHostSafe(hostname) {
// URL.hostname preserves the [::1] bracketed form for IPv6 literals; strip
// brackets so net.isIP recognizes the address before falling through to DNS.
@@ -436,8 +439,11 @@ async function isHostSafe(hostname) {
? hostname.slice(1, -1)
: hostname;
if (net.isIP(stripped)) return !isPrivateIP(stripped);
- // DNS resolution: check all resolved addresses
- const addresses = await dns.resolve4(stripped).catch(() => []);
+ const [v4, v6] = await Promise.all([
+ dns.resolve4(stripped).catch(() => []),
+ dns.resolve6(stripped).catch(() => []),
+ ]);
+ const addresses = [...v4, ...v6];
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 38e0693f8d..81150d325e 100644
--- a/server/services/feeds.test.js
+++ b/server/services/feeds.test.js
@@ -17,9 +17,14 @@ vi.mock('../lib/fetchWithTimeout.js', () => ({
}));
const dnsResolveMock = vi.fn();
+const dnsResolve6Mock = vi.fn();
vi.mock('dns/promises', () => ({
- default: { resolve4: (...args) => dnsResolveMock(...args) },
+ default: {
+ resolve4: (...args) => dnsResolveMock(...args),
+ resolve6: (...args) => dnsResolve6Mock(...args),
+ },
resolve4: (...args) => dnsResolveMock(...args),
+ resolve6: (...args) => dnsResolve6Mock(...args),
}));
let feeds;
@@ -38,6 +43,7 @@ beforeEach(async () => {
vi.resetModules();
fetchMock.mockReset();
dnsResolveMock.mockReset().mockResolvedValue(['93.184.216.34']);
+ dnsResolve6Mock.mockReset().mockResolvedValue([]);
feeds = await import('./feeds.js');
});
@@ -198,13 +204,39 @@ describe('addFeed', () => {
expect(fetchMock).not.toHaveBeenCalled();
});
- it('rejects hostnames with no A records', async () => {
+ it('rejects hostnames with no A or AAAA records', async () => {
dnsResolveMock.mockResolvedValue([]);
+ dnsResolve6Mock.mockResolvedValue([]);
const result = await feeds.addFeed('https://no-records.example.com/rss');
expect(result).toEqual({ error: FETCH_ERROR });
expect(fetchMock).not.toHaveBeenCalled();
});
+ it('rejects when AAAA resolves to a private IPv6 even if A is public (happy-eyeballs SSRF)', async () => {
+ dnsResolveMock.mockResolvedValue(['93.184.216.34']);
+ dnsResolve6Mock.mockResolvedValue(['fc00::1']);
+ const result = await feeds.addFeed('https://dual-stack.example.com/rss');
+ expect(result).toEqual({ error: FETCH_ERROR });
+ expect(fetchMock).not.toHaveBeenCalled();
+ });
+
+ it('accepts AAAA-only hostnames (no A record, public IPv6)', async () => {
+ fetchMock.mockResolvedValue(makeResponse({ body: RSS_FIXTURE }));
+ dnsResolveMock.mockResolvedValue([]);
+ dnsResolve6Mock.mockResolvedValue(['2606:4700:4700::1111']);
+ const result = await feeds.addFeed('https://v6only.example.com/rss');
+ expect(result.error).toBeUndefined();
+ expect(fetchMock).toHaveBeenCalledTimes(1);
+ });
+
+ it('rejects AAAA-only hostnames that point to private IPv6', async () => {
+ dnsResolveMock.mockResolvedValue([]);
+ dnsResolve6Mock.mockResolvedValue(['fe80::1']);
+ const result = await feeds.addFeed('https://v6private.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' } }))