mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
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:
@@ -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);
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user