GeezerVison is showing github.com — dns: do not consult hosts file in reverse lookups · nodejs/node@54a5095
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/dns.md +4Lines changed: 4 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -867,6 +867,10 @@ treated separately. | 867 | 867 |
| 868 | 868 | <!-- YAML | 869 | 869 | added: v0.1.16 | | 870 | +changes: | | 871 | + - version: REPLACEME | | 872 | + pr-url: https://github.com/nodejs/node/pull/64268 | | 873 | + description: Reverse lookups no longer consult hosts files. | 870 | 874 | --> | 871 | 875 |
| 872 | 876 | * `ip` {string} | |
Collapse file Copy file name to clipboardExpand all lines: src/cares_wrap.cc +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1020,6 +1020,8 @@ void ChannelWrap::Setup() { | 1020 | 1020 | options.timeout = timeout_; | 1021 | 1021 | options.tries = tries_; | 1022 | 1022 | options.qcache_max_ttl = 0; | | 1023 | + // Resolver APIs always perform DNS queries and must not consult hosts files. | | 1024 | + options.lookups = const_cast<char*>("b"); | 1023 | 1025 |
| 1024 | 1026 | int r; | 1025 | 1027 | if (!library_inited_) { | @@ -1033,7 +1035,7 @@ void ChannelWrap::Setup() { | 1033 | 1035 |
| 1034 | 1036 | /* We do the call to ares_init_option for caller. */ | 1035 | 1037 | int optmask = ARES_OPT_FLAGS | ARES_OPT_TIMEOUTMS | ARES_OPT_SOCK_STATE_CB | | 1036 | | - ARES_OPT_TRIES | ARES_OPT_QUERY_CACHE; | | 1038 | + ARES_OPT_TRIES | ARES_OPT_QUERY_CACHE | ARES_OPT_LOOKUPS; | 1037 | 1039 |
| 1038 | 1040 | if (max_timeout_ > 0) { | 1039 | 1041 | options.maxtimeout = max_timeout_; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-c-ares.js -14Lines changed: 0 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -76,17 +76,3 @@ dns.lookup('::1', common.mustSucceed((result, addressType) => { | 76 | 76 |
| 77 | 77 | assert.throws(() => dnsPromises.resolve('www.google.com', val), err); | 78 | 78 | }); | 79 | | - | 80 | | -// Windows doesn't usually have an entry for localhost 127.0.0.1 in | 81 | | -// C:\Windows\System32\drivers\etc\hosts | 82 | | -// so we disable this test on Windows. | 83 | | -// IBMi reports `ENOTFOUND` when get hostname by address 127.0.0.1 | 84 | | -if (!common.isWindows && !common.isIBMi) { | 85 | | - dns.reverse('127.0.0.1', common.mustSucceed((domains) => { | 86 | | - assert.ok(Array.isArray(domains)); | 87 | | - })); | 88 | | - | 89 | | - (async function() { | 90 | | - assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1'))); | 91 | | - })().then(common.mustCall()); | 92 | | -} |
Collapse file Copy file name to clipboard +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +const common = require('../common'); | | 4 | +const assert = require('assert'); | | 5 | +const dgram = require('dgram'); | | 6 | +const dns = require('dns'); | | 7 | +const dnstools = require('../common/dns'); | | 8 | + | | 9 | +const server = dgram.createSocket('udp4'); | | 10 | +const resolver = new dns.Resolver(); | | 11 | +const expectedHostname = 'reverse-dns-only.example'; | | 12 | + | | 13 | +server.on('message', common.mustCall((msg, { address, port }) => { | | 14 | + const parsed = dnstools.parseDNSPacket(msg); | | 15 | + const question = parsed.questions[0]; | | 16 | + | | 17 | + assert.strictEqual(question.domain, '1.0.0.127.in-addr.arpa'); | | 18 | + assert.strictEqual(question.type, 'PTR'); | | 19 | + | | 20 | + server.send(dnstools.writeDNSPacket({ | | 21 | + id: parsed.id, | | 22 | + questions: parsed.questions, | | 23 | + answers: [{ | | 24 | + type: 'PTR', | | 25 | + domain: question.domain, | | 26 | + value: expectedHostname, | | 27 | + }], | | 28 | + }), port, address); | | 29 | +})); | | 30 | + | | 31 | +server.bind(0, common.mustCall(() => { | | 32 | + resolver.setServers([`127.0.0.1:${server.address().port}`]); | | 33 | + resolver.reverse('127.0.0.1', common.mustSucceed((hostnames) => { | | 34 | + assert.deepStrictEqual(hostnames, [expectedHostname]); | | 35 | + server.close(); | | 36 | + })); | | 37 | +})); |
|