Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns: idna encode hostnames before resolution #25559

Closed
wants to merge 4 commits into from

Conversation

santigimeno
Copy link
Member

Fixes: #25558

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the dns Issues and PRs related to the dns subsystem. label Jan 18, 2019
lib/dns.js Outdated
@@ -213,6 +215,7 @@ function resolver(bindingName) {
throw new ERR_INVALID_CALLBACK();
}

name = toASCII(name, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function can theoretically throw in

error('overflow');
. Do we need to handle it?

Copy link
Member Author

@santigimeno santigimeno Jan 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk, if so, shouldn't we also handle it here to be lenient whether it uses icu or punycode?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url.parse is synchronous so it's less of an issue. Here the error could only lead to an uncaught exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to ignore exceptions. Thanks

@targos
Copy link
Member

targos commented Jan 18, 2019

/cc @saghul @cjihrig @bnoordhuis

Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments. I think the C++ code which does the utf-8 decoding also needs to go, it should assume ASCII, and throw on failure.

@@ -22,6 +22,8 @@
'use strict';

const cares = internalBinding('cares_wrap');
const { toASCII } = internalBinding('config').hasIntl ?
internalBinding('icu') : require('punycode');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the policy here, considering punycode is deprecated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, we do the same thing in lib/url.js, so it's probably fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using punycode is the fallback if Node.js is compiled without ICU.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's only deprecated for userland.

@@ -213,6 +215,11 @@ function resolver(bindingName) {
throw new ERR_INVALID_CALLBACK();
}

try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be needed if we were only using the ICU based toASCII?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is no

@saghul
Copy link
Member

saghul commented Jan 18, 2019

Thanks for picking this up @santigimeno ❤️

@santigimeno
Copy link
Member Author

I think the C++ code which does the utf-8 decoding also needs to go, it should assume ASCII, and throw on failure

I'm not sure you can remove the node::Utf8Value name(env->isolate(), string); code as it's needed to convert a Local<String> into a const char*

@saghul
Copy link
Member

saghul commented Jan 18, 2019

I'm not sure you can remove the node::Utf8Value name(env->isolate(), string); code as it's needed to convert a Local<String> into a const char*

Isn't there an equivalent that does the job in ASCII instead?

@santigimeno
Copy link
Member Author

Isn't there an equivalent that does the job in ASCII instead?

I don't know, but what's the issue being ASCII a subset of UTF-8?

@@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domaintest.みんな might be a better testing domain name, info here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 also, I'd say a comment is missing.

@bnoordhuis
Copy link
Member

@santigimeno Do you have access to node-private? Because this PR is a spiritual duplicate of https://github.com/nodejs-private/node-private/pull/147 :)

@santigimeno
Copy link
Member Author

Do you have access to node-private?

Not really, first time I hear about that repo. Feel free to close this if it's already handled there.

@bnoordhuis
Copy link
Member

@santigimeno Sorry for the delay, Santi. I've moved it to #25679.

@santigimeno
Copy link
Member Author

Closing in favor of #25679. Thanks for the heads up Ben.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dns Issues and PRs related to the dns subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DNS resolution fails for internationalized domain names
8 participants