HttpProxyHandler incorrectly formats IPv6 host and port in CONNECT request
See original GitHub issueExpected behavior
The HttpProxyHandler is expected to be capable of issuing a valid CONNECT request for a tunneled connection to an IPv6 host. In this case we are passing an IPv6 address (eg fd00:c0de:42::c:293a:5736) rather than a host name.
Actual behavior
The HttpProxyHandler does not properly concatenate the IPv6 address and port. The resulting error after we fail to connect will show you the problem:
io.netty.handler.proxy.ProxyConnectException: http, none, /fd00:c0de:42:0:5:562d:d54:1:3128 => /fd00:c0de:42:0:50:5694:2fda:1:4287, status: 503 Service Unavailable
In both cases you can see the IPv6 address is formatted without brackets: fd00:c0de:42:0:50:5694:2fda:1:4287
should be [fd00:c0de:42:0:50:5694:2fda:1]:4287
. This is just an exception message so it doesn’t prove it’s formatting incorrectly. However, if you look at the request on the wire you can see it is certainly wrong:
CONNECT fd00:c0de:42:0:50:5694:2fda:1:4287 HTTP/1.1\r\n
host: fd00:c0de:42:0:50:5694:2fda:1:4287\r\n
\r\n
Here is the problem method from HttpProxyHandler:
@Override
protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception {
InetSocketAddress raddr = destinationAddress();
String rhost;
if (raddr.isUnresolved()) {
rhost = raddr.getHostString();
} else {
rhost = raddr.getAddress().getHostAddress();
}
final String host = rhost + ':' + raddr.getPort();
FullHttpRequest req = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.CONNECT,
host,
Unpooled.EMPTY_BUFFER, false);
req.headers().set(HttpHeaderNames.HOST, host);
if (authorization != null) {
req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization);
}
return req;
}
Specifically: final String host = rhost + ':' + raddr.getPort();
Steps to reproduce
- Setup an HTTP Proxy with IPv6.
- Setup a target server with an IPv6 address.
- Attempt to establish a connection to the target server through the proxy, giving the HttpProxyHandler an IPv6 IP address for the target. ** We can successfully connect to the proxy server with IPv6. The problem seems to be specific to the target of the tunneled connection using an IPv6 address.
Minimal yet complete reproducer code (or URL to code)
- I am not able to create a reproducer or patch with my company at this time. I think the issue is relatively straightforward though.
Netty version
4.1.4.Final
JVM version (e.g. java -version
)
Java 8 update 92
OS version (e.g. uname -a
)
Attempted on Ubuntu Linux 14.04 and Mac OSX. I don’t think the OS matters in this case.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (6 by maintainers)
@ZuluForce @Scottmitch let me take care.
Fixed by https://github.com/netty/netty/pull/6195