Repository navigation
Conversation
dialFunc split the address at the first colon, which cuts an IPv6 literal such as [2001:db8::1]:80 inside the address. The port then never matched "80" or "443", so a literal on port 80 was dialed with TLS on port 80 instead of 443, and a literal on port 443 was not refused. Use net.SplitHostPort and net.JoinHostPort. A missing port still means 443.
Contributor
|
Addressed in #66 . |
Author
|
Thanks @timflyio. Curious, what was the problem with my PR? |
Contributor
It turns out that theres no need to handle the missing port error from SplitHostPort or port defaulting. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Datum is an IPv6-native platform, so we seem to find subtle IPv6 issues in a lot of places. This is one of them.
What breaks
dialFuncsplits the address it is asked to dial at the first::For an IPv6 literal such as
[2001:db8::1]:80that cuts inside the address:hostnameis[andportis:db8::1]:80. Neither the"80"nor the"443"case matches, so:http://[2001:db8::1]/(the Transport asks for[2001:db8::1]:80) gets TLS dialed on port 80 instead of 443, and the request fails.[2001:db8::1]:443is not refused with "proxied request must be HTTP", so the TLS-passthrough guard does not apply to IPv6 literals.[2001:db8::1], fails to dial with a missing-port error instead of defaulting to 443.Literals on other ports (
[::1]:8443) happen to round-trip unchanged and work.Fix
Split with
net.SplitHostPortand rebuild withnet.JoinHostPort, so brackets are handled. A missing port is still treated as 443.An address
SplitHostPortcannot parse for another reason (an unbracketed::1, for example) is refused withErrBadRequest. Before, it was cut at the first colon and either refused for having no host or failed to dial.Unchanged
""or80becomes 443; explicit443is refused; an empty host is refused. Same messages.ControlContextalready usednet.SplitHostPort, and are untouched.Tests
TestDialFuncParsesAddressescovers names, IPv4 and IPv6 literals. It checks that:443is refused, that an empty host is refused (:80,[]:80, empty string), and that port 80, no port andhost:each dial 443 (read from the dial error, which names the address). An unbracketed::1is refused. The IPv6 cases fail without the change.TestTokenizerIPv6Upstreamsends a request through the proxy to a TLS echo server on[::1], with anallowed_hostsvalidator on the bracketed host, and checks that the server sees the injected credential. It is skipped if the machine has no IPv6 loopback. It uses an explicit port, so it passes without the change too; it guards the end-to-end path.