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

Avoid potential for reverse name lookup #5305

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public String transport(ChannelAndMethod channelAndMethod, @Nullable Void unused
@Nullable
@Override
public String peerName(ChannelAndMethod channelAndMethod, @Nullable Void unused) {
return channelAndMethod.getChannel().getConnection().getAddress().getHostName();
Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently it is possible to read the cached hostname from InetAddress with new InetSocketAddress(channelAndMethod.getChannel().getConnection().getAddress(), 0).getHostString(). In this case it doesn't seem to change anything because the address really only has the ip. Added this note in case you find some other place where this could come handy.

// not using InetAddress.getHostName() since that can trigger reverse name lookup
return null;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public String transport(ReceiveRequest request, @Nullable GetResponse response)
@Nullable
@Override
public String peerName(ReceiveRequest request, @Nullable GetResponse response) {
return request.getConnection().getAddress().getHostName();
// not using InetAddress.getHostName() since that can trigger reverse name lookup
return null;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String url(HttpClientConfig request) {
if (hostAddress instanceof InetSocketAddress) {
InetSocketAddress inetHostAddress = (InetSocketAddress) hostAddress;
return (request.isSecure() ? "https://" : "http://")
+ inetHostAddress.getHostName()
+ inetHostAddress.getHostString()
+ ":"
+ inetHostAddress.getPort()
+ (uri.startsWith("/") ? "" : "/")
Expand Down