summaryrefslogtreecommitdiff
path: root/test/internet
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2018-10-10 20:23:48 +0200
committerAnna Henningsen <anna@addaleax.net>2019-01-28 20:42:44 +0100
commitf399b01dc4dbb47f678301aea6f476527889b959 (patch)
tree55fda98222b9eb7c77990cb0053ed8d8a3ec3eff /test/internet
parent48149876dd195bb2bb072a1d8b1cb3ef0b9ae15d (diff)
downloadandroid-node-v8-f399b01dc4dbb47f678301aea6f476527889b959.tar.gz
android-node-v8-f399b01dc4dbb47f678301aea6f476527889b959.tar.bz2
android-node-v8-f399b01dc4dbb47f678301aea6f476527889b959.zip
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 'test/internet')
-rw-r--r--test/internet/test-dns-idna2008.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/internet/test-dns-idna2008.js b/test/internet/test-dns-idna2008.js
new file mode 100644
index 0000000000..ebabe322f0
--- /dev/null
+++ b/test/internet/test-dns-idna2008.js
@@ -0,0 +1,33 @@
+'use strict';
+
+// Verify that non-ASCII hostnames are handled correctly as IDNA 2008.
+//
+// * Tests will fail with NXDOMAIN when UTF-8 leaks through to a getaddrinfo()
+// that doesn't support IDNA at all.
+//
+// * "straße.de" will resolve to the wrong address when the resolver supports
+// only IDNA 2003 (e.g., glibc until 2.28) because it encodes it wrong.
+
+const { mustCall } = require('../common');
+const assert = require('assert');
+const dns = require('dns');
+
+const [host, expectedAddress] = ['straße.de', '81.169.145.78'];
+
+dns.lookup(host, mustCall((err, address) => {
+ assert.ifError(err);
+ assert.strictEqual(address, expectedAddress);
+}));
+
+dns.promises.lookup(host).then(mustCall(({ address }) => {
+ assert.strictEqual(address, expectedAddress);
+}));
+
+dns.resolve4(host, mustCall((err, addresses) => {
+ assert.ifError(err);
+ assert.deepStrictEqual(addresses, [expectedAddress]);
+}));
+
+new dns.promises.Resolver().resolve4(host).then(mustCall((addresses) => {
+ assert.deepStrictEqual(addresses, [expectedAddress]);
+}));