Repository navigation
Conversation
hostname() stripped every leading "[" and trailing "]" from a host
followed by a port, then validated what was left as a simple hostname,
domain, IPv4 or IPv6 address. "[1.2.3.4]:80", "[example.com]:80",
"[[::1]]:80" and "::1]:80" all validated. RFC 3986 (3.2.2) only
encloses an IPv6 (or IPvFuture) address in brackets, so a bracketed
host must now be exactly one pair around an IPv6 address.
email() likewise stripped repeated brackets from an address literal,
accepting "user@[[192.0.2.1]]" and "user@[192.0.2.1]]". It now strips
exactly one pair. Inside the pair, any further bracket is rejected,
since ipv6() accepts "]" as part of a zone ID ("::1%]").
This branch has not been deployed
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.
hostname()strips every leading[and trailing]from a host followed by a port, then validates what's left as a simple hostname, domain, IPv4 or IPv6 address. As a result, all of these validate on master:RFC 3986 section 3.2.2 only encloses an IPv6 (or IPvFuture) address in brackets.
url()already rejects these, buthostname()is often used onhost:portvalues directly.email()has the same flaw for address literals: withipv4_addressoripv6_addressset,user@[[192.0.2.1]],user@[192.0.2.1]]anduser@[[[2001:db8::1]]]validate.Changes
hostname(), a bracketed host before the port must be one pair of brackets around an IPv6 address. It's never tried as a hostname, domain or IPv4 address, and it's rejected whenskip_ipv6_addris set.email()strips exactly one pair of brackets from an address literal.ipv6()delegates toipaddress, which accepts almost any zone ID, including](::1%]). Without this check, stripping exactly one pair would newly acceptuser@[2001:db8::1%]].Tests
Of the 20 new cases in
test_hostname.pyandtest_email.py, 14 fail on master and all pass here. The other 6 already pass on master: positive cases for single-bracket IPv4 and IPv6 email literals, which had no tests, and 4 guards. Two of the guards,[::1%]]:80anduser@[2001:db8::1%]], would have been newly accepted by stripping exactly one pair without the inner-bracket check. The full suite (1594 tests),ruff check,ruff format,pyrightand bandit pass.A fuzz comparison against master covered
hostname()(with and withoutskip_ipv6_addr),url()andemail()address literals, over 30,000 mutated hosts. It found nothing newly accepted and no change forurl(). Every newly rejected value has brackets that don't enclose exactly one valid IPv6 address.