Skip to content

Commit

Permalink
fix: only lookup localhost for DNS lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Jun 3, 2022
1 parent eb7cd71 commit 1b025b4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/node/NodeWebSocketTransport.ts
Expand Up @@ -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, [], {
Expand Down

0 comments on commit 1b025b4

Please sign in to comment.