Skip to content

Commit

Permalink
dns: idna encode hostnames before resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
santigimeno committed Jan 18, 2019
1 parent 9a26546 commit 973bab3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
'use strict';

const cares = internalBinding('cares_wrap');
const { toASCII } = internalBinding('config').hasIntl ?
internalBinding('icu') : require('punycode');
const { isIP, isIPv4, isLegalPort } = require('internal/net');
const { customPromisifyArgs } = require('internal/util');
const errors = require('internal/errors');
Expand Down Expand Up @@ -213,6 +215,7 @@ function resolver(bindingName) {
throw new ERR_INVALID_CALLBACK();
}

name = toASCII(name, true);
var req = new QueryReqWrap();
req.bindingName = bindingName;
req.callback = callback;
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const {
validateHints,
emitInvalidHostnameWarning,
} = require('internal/dns/utils');
const { toASCII } = internalBinding('config').hasIntl ?
internalBinding('icu') : require('punycode');
const { codes, dnsException } = require('internal/errors');
const { isIP, isIPv4, isLegalPort } = require('internal/net');
const {
Expand Down Expand Up @@ -183,6 +185,7 @@ function createResolverPromise(resolver, bindingName, hostname, ttl) {
req.reject = reject;
req.ttl = ttl;

hostname = toASCII(hostname, true);
const err = resolver._handle[bindingName](req, hostname);

if (err)
Expand Down
3 changes: 2 additions & 1 deletion test/common/internet.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const addresses = {
// An accessible IPv4 DNS server
DNS4_SERVER: '8.8.8.8',
// An accessible IPv4 DNS server
DNS6_SERVER: '2001:4860:4860::8888'
DNS6_SERVER: '2001:4860:4860::8888',
IDNA_HOST: 'españa.icom.museum'
};

for (const key of Object.keys(addresses)) {
Expand Down
16 changes: 16 additions & 0 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ TEST(function test_resolveNs_failure(done) {
checkWrap(req);
});

TEST(async function test_resolve_idna(done) {
function validateResult(result) {
assert.ok(result.length > 0);
}

validateResult(await dnsPromises.resolve(addresses.IDNA_HOST));

const req = dns.resolve4(addresses.IDNA_HOST, function(err, result) {
assert.ifError(err);
validateResult(result);
done();
});

checkWrap(req);
});

TEST(async function test_resolveSrv(done) {
function validateResult(result) {
assert.ok(result.length > 0);
Expand Down

0 comments on commit 973bab3

Please sign in to comment.