fix(ssrf): answer a pinned lookup on a later tick so a failed connect cannot crash the server

Called back at once, a connect that fails right away (no route to an IPv6 address) tore the socket down while tls.connect was still setting it up; undici saw 'fetch failed' and the socket's own error then reached no listener and ended the process. The pinned lookup now answers on the next tick, as dns.lookup does.
This commit is contained in:
Maurice
2026-11-28 18:12:39 +01:00
parent d6ce33c51c
commit 41772c0d8e
4 changed files with 81 additions and 59 deletions
+12 -6
View File
@@ -796,12 +796,18 @@ export function createPinnedDispatcher(
connect: {
rejectUnauthorized,
lookup: (_hostname: string, opts: Record<string, unknown>, callback: Function) => {
// Node asks with `all: true` when it may choose between families itself.
if (opts?.all) {
callback(null, addresses);
} else {
callback(null, addresses[0].address, addresses[0].family);
}
// Answered on a later tick, as dns.lookup answers. Called back at once, a
// connect that fails right away (no route to the address) tears the socket
// down while tls.connect still sets it up, and its error then crashes the
// process because nothing listens for it yet.
process.nextTick(() => {
// Node asks with `all: true` when it may choose between families itself.
if (opts?.all) {
callback(null, addresses);
} else {
callback(null, addresses[0].address, addresses[0].family);
}
});
},
},
});