Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
const {
ObjectDefineProperties,
ObjectDefineProperty,
StringPrototypeStartsWith,
Symbol,
} = primordials;

Expand Down Expand Up @@ -108,7 +109,16 @@ function onlookup(err, addresses) {
if (err) {
return this.callback(new DNSException(err, 'getaddrinfo', this.hostname));
}
this.callback(null, addresses[0], this.family || isIP(addresses[0]));

const family = this.family || isIP(addresses[0]);
const address = addresses[0];
if (address && family === 6 && StringPrototypeStartsWith(address, 'fe80::')) {
// If the address is an IPv6 link-local address, we should not return it
this.callback(null, undefined, undefined);
} else {
this.callback(null, address, family);
}

if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) {
stopPerf(this, kPerfHooksDnsLookupContext, { detail: { addresses } });
}
Expand Down
11 changes: 10 additions & 1 deletion lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
ObjectDefineProperty,
Promise,
ReflectApply,
StringPrototypeStartsWith,
Symbol,
} = primordials;

Expand Down Expand Up @@ -88,7 +89,15 @@ function onlookup(err, addresses) {
}

const family = this.family || isIP(addresses[0]);
this.resolve({ address: addresses[0], family });
const address = addresses[0];

if (address && family === 6 && StringPrototypeStartsWith(address, 'fe80::')) {
// If the address is an IPv6 link-local address, we should not return it
this.resolve({});
} else {
this.resolve({ address, family });
}

if (this[kPerfHooksDnsLookupContext] && hasObserver('dns')) {
stopPerf(this, kPerfHooksDnsLookupContext, { detail: { addresses } });
}
Expand Down
11 changes: 11 additions & 0 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,17 @@ TEST(function test_lookup_ip_promise(done) {
});
});

TEST(async function test_lookup_ipv6_loopback(done) {
const response = await dnsPromises.lookup('ipv6_loopback', { verbatim: true });
assert.strictEqual(Object.keys(response).length, 0);

util.promisify(dns.lookup)('ipv6_loopback').then(({ address, family }) => {
assert.strictEqual(address, undefined);
assert.strictEqual(family, undefined);

done();
});
});

TEST(async function test_lookup_null_all(done) {
assert.deepStrictEqual(await dnsPromises.lookup(null, { all: true }), []);
Expand Down