From 9e122b689f8d8281b56cf79f57fd9471b3989e38 Mon Sep 17 00:00:00 2001 From: NHTanvir Date: Wed, 18 Nov 2026 11:38:08 +0600 Subject: [PATCH] fix(webhooks): prefer IPv4 when one callback address is needed, so localhost works on Node 18 Node 18 resolves localhost to ::1 first and has no happy-eyeballs fallback, so deliveries to a receiver bound to 127.0.0.1 were refused. The choice is still made only among addresses that passed the SSRF filter. dist/ rebuilt. Closes #3 --- dist/webhooks/post.js | 4 +++- src/webhooks/post.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/webhooks/post.js b/dist/webhooks/post.js index f0a49fe..20c1920 100644 --- a/dist/webhooks/post.js +++ b/dist/webhooks/post.js @@ -24,7 +24,9 @@ function guardedLookup(allowPrivate) { } if (opts["all"]) return callback(null, usable); - const first = usable[0]; + // One address wanted (Node 18 has no happy-eyeballs fallback): prefer IPv4, as Node did before v17, + // so "localhost" reaches a receiver bound to 127.0.0.1 instead of failing on ::1. + const first = (usable.find((a) => a.family === 4) ?? usable[0]); return callback(null, first.address, first.family); }); }); diff --git a/src/webhooks/post.ts b/src/webhooks/post.ts index 03b5e71..54e62b8 100644 --- a/src/webhooks/post.ts +++ b/src/webhooks/post.ts @@ -45,7 +45,9 @@ function guardedLookup(allowPrivate: boolean): LookupFunction { return callback(new BlockedAddressError(`${hostname} resolves only to non-public addresses`)); } if (opts["all"]) return callback(null, usable); - const first = usable[0] as LookupAddress; + // One address wanted (Node 18 has no happy-eyeballs fallback): prefer IPv4, as Node did before v17, + // so "localhost" reaches a receiver bound to 127.0.0.1 instead of failing on ::1. + const first = (usable.find((a) => a.family === 4) ?? usable[0]) as LookupAddress; return callback(null, first.address, first.family); }); }) as LookupFunction;