diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2018-10-10 21:23:48 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-01-28 22:42:44 +0300 |
commit | f399b01dc4dbb47f678301aea6f476527889b959 (patch) | |
tree | 55fda98222b9eb7c77990cb0053ed8d8a3ec3eff /lib/internal/dns | |
parent | 48149876dd195bb2bb072a1d8b1cb3ef0b9ae15d (diff) |
dns: use IDNA 2008 to encode non-ascii hostnames
Before this commit, Node.js left it up to the system resolver or c-ares.
Leaving it to the system resolver introduces platform differences
because:
* some support IDNA 2008
* some only IDNA 2003 (glibc until 2.28), and
* some don't support IDNA at all (musl libc)
c-ares doesn't support IDNA either although curl does, by virtue of
linking against libidn2. Upgrading from libidn1 to libidn2 in order
to get proper IDNA 2008 support was the fix for curl's CVE-2016-8625.
libidn2 is not an option (incompatible license) but ICU has an IDNA API
and we already use that in one place. For non-ICU builds, we fall back
to the bundled punycode.js that also supports IDNA 2008.
Fixes: https://github.com/nodejs-private/security/issues/97
Fixes: https://github.com/nodejs/node/issues/25558
PR-URL: https://github.com/nodejs/node/pull/25679
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'lib/internal/dns')
-rw-r--r-- | lib/internal/dns/promises.js | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index be49ebf2106..25696bf2228 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -6,6 +6,7 @@ const { emitInvalidHostnameWarning, } = require('internal/dns/utils'); const { codes, dnsException } = require('internal/errors'); +const { toASCII } = require('internal/idna'); const { isIP, isIPv4, isLegalPort } = require('internal/net'); const { getaddrinfo, @@ -86,7 +87,7 @@ function createLookupPromise(family, hostname, all, hints, verbatim) { req.resolve = resolve; req.reject = reject; - const err = getaddrinfo(req, hostname, family, hints, verbatim); + const err = getaddrinfo(req, toASCII(hostname), family, hints, verbatim); if (err) { reject(dnsException(err, 'getaddrinfo', hostname)); @@ -184,7 +185,7 @@ function createResolverPromise(resolver, bindingName, hostname, ttl) { req.reject = reject; req.ttl = ttl; - const err = resolver._handle[bindingName](req, hostname); + const err = resolver._handle[bindingName](req, toASCII(hostname)); if (err) reject(dnsException(err, bindingName, hostname)); |