Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(ssrf): honor autoSelectFamily all:true in pinned-fetch lookup

nirholas06632d91335d
diff --git a/api/_lib/ssrf-guard.js b/api/_lib/ssrf-guard.js
index 5f01049bb..618957188 100644
--- a/api/_lib/ssrf-guard.js
+++ b/api/_lib/ssrf-guard.js
@@ -118,6 +118,26 @@ export async function assertSafePublicUrl(input, { allowHttp = false } = {}) {
return url;
}
+// Build the custom `lookup` an IP-pinned Agent installs so every socket connects
+// to exactly the pre-validated address (closing the DNS-rebinding window). It
+// MUST serve both lookup contracts: Node enables autoSelectFamily (Happy
+// Eyeballs) by default and, for a dual-stack host, calls the custom lookup with
+// `{ all: true }`, expecting the array form `cb(null, [{ address, family }])`.
+// Returning the legacy positional form under `all:true` makes Node read
+// `undefined` as the address and throw `Invalid IP address: undefined` before
+// any socket opens — which silently broke every pinned fetch to a dual-stack
+// host (e.g. storage.googleapis.com) on Node 24. Exported for direct testing.
+export function makePinnedLookup(pinnedIp) {
+ const family = net.isIPv6(pinnedIp) ? 6 : 4;
+ return function lookup(_hostname, options, cb) {
+ if (options && options.all) {
+ cb(null, [{ address: pinnedIp, family }]);
+ } else {
+ cb(null, pinnedIp, family);
+ }
+ };
+}
+
const MAX_REDIRECTS = 5;
// Convenience: assert + fetch. Uses the global fetch. Same options as fetch,
@@ -165,13 +185,10 @@ export async function fetchSafePublicUrlPinned(input, init = {}, opts = {}) {
// Build a one-shot Agent whose `lookup` always returns the pre-validated IP.
// This closes the TOCTOU window: the TCP socket connects to exactly the address
- // we checked, regardless of any subsequent DNS change.
+ // we checked, regardless of any subsequent DNS change. makePinnedLookup honors
+ // both the legacy and autoSelectFamily (`all:true`) lookup contracts.
const AgentClass = url.protocol === 'https:' ? https.Agent : http.Agent;
- const agent = new AgentClass({
- lookup(_hostname, _options, cb) {
- cb(null, pinnedIp, net.isIPv6(pinnedIp) ? 6 : 4);
- },
- });
+ const agent = new AgentClass({ lookup: makePinnedLookup(pinnedIp) });
const res = await new Promise((resolve, reject) => {
const mod = url.protocol === 'https:' ? https : http;
diff --git a/tests/ssrf-pinned-lookup.test.js b/tests/ssrf-pinned-lookup.test.js
new file mode 100644
index 000000000..fe580ffa5
--- /dev/null
+++ b/tests/ssrf-pinned-lookup.test.js
@@ -0,0 +1,61 @@
+// Regression guard for the IP-pinned Agent's custom DNS lookup.
+//
+// Node enables autoSelectFamily (Happy Eyeballs) by default, and for a
+// dual-stack host it calls a custom `lookup` with `{ all: true }`, expecting the
+// array form `cb(null, [{ address, family }])`. The pinned-fetch helper used to
+// return only the legacy positional form, so under `all:true` Node read
+// `undefined` as the address and threw `Invalid IP address: undefined` before
+// any socket opened — silently breaking every pinned fetch to a dual-stack host
+// (storage.googleapis.com, the GCP avatar-reconstruction result bucket). These
+// tests pin both lookup contracts so the array shape can never regress.
+
+import { describe, it, expect } from 'vitest';
+import { makePinnedLookup } from '../api/_lib/ssrf-guard.js';
+
+describe('makePinnedLookup', () => {
+ it('returns the array form when options.all is true (autoSelectFamily path)', () => {
+ const lookup = makePinnedLookup('142.250.73.123');
+ let out;
+ lookup('storage.googleapis.com', { all: true }, (err, ...rest) => {
+ out = { err, rest };
+ });
+ expect(out.err).toBeNull();
+ // Modern contract: a SINGLE array argument of { address, family } records.
+ expect(out.rest).toHaveLength(1);
+ expect(out.rest[0]).toEqual([{ address: '142.250.73.123', family: 4 }]);
+ });
+
+ it('returns the legacy positional form when options.all is falsy', () => {
+ const lookup = makePinnedLookup('142.250.73.123');
+ let out;
+ lookup('example.com', {}, (err, address, family) => {
+ out = { err, address, family };
+ });
+ expect(out.err).toBeNull();
+ expect(out.address).toBe('142.250.73.123');
+ expect(out.family).toBe(4);
+ });
+
+ it('reports family 6 for an IPv6 pinned address', () => {
+ const lookup = makePinnedLookup('2607:f8b0:400a:802::201b');
+ let all;
+ lookup('h', { all: true }, (_e, records) => { all = records; });
+ expect(all).toEqual([{ address: '2607:f8b0:400a:802::201b', family: 6 }]);
+
+ let legacyFamily;
+ lookup('h', undefined, (_e, _a, fam) => { legacyFamily = fam; });
+ expect(legacyFamily).toBe(6);
+ });
+
+ it('never yields an undefined address in either contract (the original bug)', () => {
+ const lookup = makePinnedLookup('74.125.195.207');
+ for (const options of [{ all: true }, { all: false }, {}, undefined]) {
+ lookup('h', options, (_e, a, _f) => {
+ // Under all:true, `a` is the array; otherwise the address string.
+ const address = Array.isArray(a) ? a[0]?.address : a;
+ expect(address).toBe('74.125.195.207');
+ expect(address).not.toBeUndefined();
+ });
+ }
+ });
+});