Repository navigation
Return the explicit port of a URL with an IPv6 host from portRFC - #118632
Conversation
`portRFC('http://[2001:db8::1]:8080/')` returned `0`, and with an explicit
default it returned that default, so the answer was indistinguishable from a URL
that has no port. `domainRFC` parses the very same authority correctly, so the
RFC-conformant family disagreed with itself.
`getURLHostRFC` returns an IP-literal host without its brackets (RFC 3986,
3.2.2: `IP-literal = "[" ( IPv6address / IPvFuture ) "]"`), so the character
right after the host is `]`, not the `:` of the port, and `extractPort` gave up
there. Skip the closing bracket.
`port` is left as it is: its host parser does not accept a bracketed host at
all, so it has no port to return there.
The `portRFC` half of the IPv6 section of `01284_port` asserted the old answers
- it was added as a known limitation of `getURLHost` - and now expects the port.
Closes: #118487
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [618a330] Summary: ✅
AI ReviewSummaryThis PR fixes Final Verdict✅ Approve. The previously reported LLVM Coverage ReportMeasured on commit 618a330.
Changed lines: Changed C/C++ lines covered: 30/31 (96.77%) · Uncovered code |
`portRFC('http://user:password@[2001:db8::1]:8080/')` still returned the default
port, and `domainRFC` returned an empty host for it: `getURLHostRFC` entered
IP-literal mode only when the bracket was the first character of the authority,
while RFC 3986 allows a userinfo before it (3.2: `authority = [ userinfo "@" ]
host [ ":" port ]`).
The bracket is recognized after `@` now, and a complete IP-literal is returned
as the host whether or not a userinfo preceded it. Inside an IP-literal `@` is
not a userinfo separator at all - it is not allowed there - so it makes the host
invalid, which is what `02845_domain_rfc_support_ipv6` pins for
`[2001::db@81]:80`.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Addressed: Inside an IP-literal |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units14 translation units recompiled, 26 s compile time in total, 14 of them have a recent master baseline. |
|
@alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
ClickHouse#118632 taught getURLHostRFC to parse a bracketed IPv6 host, including after a userinfo@ prefix, but several related bugs remain in the same parser, on top of that fix: - A bracketed host with an embedded IPv4 tail, e.g. "::ffff:192.168.0.1" or a NAT64 literal "64:ff9b::192.0.2.33", was rejected outright: any '.' while scanning inside brackets returned an empty host, even though this is a valid IPv6 address form and parseIPv6Whole already supports it. This is the bug reported in ClickHouse#118890. - The bracket contents were never validated as an actual IPv6 address, so a non-IPv6 string like "2001db81" was silently accepted as the host. Validate it with parseIPv6Whole (already used elsewhere in the codebase, e.g. isIPAddressInRange.cpp). - Nothing following the closing ']' was checked, so "[2001:db8::1]evil.com" returned "2001:db8::1" as the host. Only end of input, ':', '/', '?', or '#' may legally follow it. - colon_pos, dot_pos, and has_terminator_after_colon carried over across '@', so a colon or dot in the userinfo (e.g. "user:password@") could validate a malformed host afterward using state that actually describes the userinfo, not the host - reset all three at '@'. - userinfo may contain more than one ':' (RFC 3986), but the second one was read as the host:port separator before the parser ever reached '@', rejecting valid authorities like "user:pass:word@[2001:db8::1]:80". - A second raw '@' was accepted as if it were another userinfo separator, returning the segment in between as the host: "[email protected]@evil.com" returned "paypal.com" instead of being rejected - userinfo cannot legally contain an unescaped '@' at all, so a second one makes the whole authority unparseable. - A host starting with a literal '.', e.g. ".com", was accepted by checkAndReturnHost (shared by domain() and domainRFC()), since it only checked for a dot with nothing after it, not nothing before it either. Closes: ClickHouse#118890 Related: ClickHouse#118632
Closes: #118487
Related: #118482
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
portRFCnow returns the explicit port of a URL whose host is an IPv6 address in brackets, such ashttp://[2001:db8::1]:8080/, instead of the default port.Description
portRFC('http://[2001:db8::1]:8080/')returned0, and with an explicit default it returned that default, so the answer was indistinguishable from a URL that has no port.domainRFCparses the very same authority correctly, so the RFC-conformant family disagreed with itself.getURLHostRFCreturns an IP-literal host without its brackets (RFC 3986, 3.2.2:IP-literal = "[" ( IPv6address / IPvFuture ) "]"), so the character right after the host is], not the:of the port, andextractPortgave up there. It now skips the closing bracket.portis left as it is: its host parser does not accept a bracketed host at all, so it has no port to return there.The
portRFChalf of the IPv6 section of01284_portasserted the old answers - it was added as a known limitation ofgetURLHost- and now expects the port.Workflow [PR]
Sync PR [sync-upstream/pr/118632]