From 1b025b4c8466fe64da0fa2050eaa02b7764770b1 Mon Sep 17 00:00:00 2001 From: Randolf J Date: Sat, 4 Jun 2022 01:04:11 +0200 Subject: [PATCH] fix: only lookup `localhost` for DNS lookups --- src/node/NodeWebSocketTransport.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/node/NodeWebSocketTransport.ts b/src/node/NodeWebSocketTransport.ts index 03b4a925e4ef6..b2886889a7c1c 100644 --- a/src/node/NodeWebSocketTransport.ts +++ b/src/node/NodeWebSocketTransport.ts @@ -23,13 +23,15 @@ export class NodeWebSocketTransport implements ConnectionTransport { // TODO(jrandolf): Starting in Node 17, IPv6 is favoured over IPv4 due to a change // in a default option: // - https://github.com/nodejs/node/issues/40537, - // Due to this, we parse and resolve the hostname manually with the previous - // behavior according to: + // Due to this, for Firefox, we must parse and resolve the `localhost` hostname + // manually with the previous behavior according to: // - https://nodejs.org/api/dns.html#dnslookuphostname-options-callback // because of https://bugzilla.mozilla.org/show_bug.cgi?id=1769994. const url = new URL(urlString); - const { address } = await dns.lookup(url.hostname, { verbatim: false }); - url.hostname = address; + if (url.hostname === 'localhost') { + const { address } = await dns.lookup(url.hostname, { verbatim: false }); + url.hostname = address; + } return new Promise((resolve, reject) => { const ws = new NodeWebSocket(url, [], {