question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HttpProxyHandler incorrectly formats IPv6 host and port in CONNECT request

See original GitHub issue

Expected 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:closed
  • Created 7 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
normanmaurercommented, Dec 22, 2016

@ZuluForce @Scottmitch let me take care.

0reactions
normanmaurercommented, Jan 12, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can one distinguish the host and the port in an IPv6 URL?
A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within ...
Read more >
problem with sockets, ipv6 and fe80-Addresses — oracle-tech
ConnectException typically means the connection to the remote host was refused. On port 4000 runs a service. A service? What is it that...
Read more >
Troubleshoot IPv6 Dynamic Address Assignment with Cisco ...
This document describes the available options for dynamic IPv6 address assignment. Troubleshoot of Stateless Address Autoconfiguration (SLAAC) ...
Read more >
How I'm Using SNI Proxying and IPv6 to Share Port 443 ...
In a world of ubiquitous IPv6, this wouldn't be a problem - each of my ... the hostname being validated, snid will forward...
Read more >
Free Automated Malware Analysis Service - powered by Falcon ...
No relevant hosts were contacted. HTTP Traffic. No relevant HTTP requests were made. Memory Forensics. String, Context, Stream UID ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found