-
Notifications
You must be signed in to change notification settings - Fork 974
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
Normalize IDN hostnames before DNS resolution to prevent UnknownHostException #608
Conversation
@arturobernalg Just a question. Why not having this normalization logic in |
e59415d
to
3726527
Compare
You right. And we avoid duplicated code. |
f900a90
to
4b06d10
Compare
@@ -44,8 +45,9 @@ public class SystemDefaultDnsResolver implements DnsResolver { | |||
@Override | |||
public InetAddress[] resolve(final String host) throws UnknownHostException { | |||
try { | |||
final String normalizedHost = IDN.toASCII(host); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg I would do IDN.toASCII
only if the hostname fails TextUtils#isAllASCII
for the sake of optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Catching IllegalArgumentException
and recovering from it (for instance, by keeping the original hostmame) would be nice here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ok2c Please do another pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Do you have any objections to doing the test TextUtils#isAllASCII
prior to doing IDN.toASCII
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ok2c done
1037377
to
12007d9
Compare
…UnknownHostException during connection.
7fb5b5d
to
3c78786
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Looks good to me
@arturobernalg Please cherry-pick to |
…UnknownHostException during connection. (#608)
Done |
This PR addresses an issue where Unicode hostnames cause UnknownHostException during DNS resolution. The change normalizes hostnames to punycode using IDN.toASCII() before passing them to the DNS resolver.