Accept IPv4-embedded IPv6 addresses in UrlValidator#405
Merged
Conversation
isValidAuthority matched a bracketed IPv6 host against IPV6_REGEX before handing it to InetAddressValidator.isValidInet6Address, but the regex only special-cased the upper-case ::FFFF: mapped form and otherwise excluded the dot needed for an embedded IPv4 part, so lower-case ::ffff:1.2.3.4, ::1.2.3.4 and 2001:db8::1.2.3.4 were rejected while the upper-case form was accepted. Widen the bracket pattern to hex, colon and dot and let isValidInet6Address make the decision.
Member
|
TY @sahvx655-wq , verified locally and merged 🚀 |
garydgregory
added a commit
that referenced
this pull request
Jun 20, 2026
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.
While checking how UrlValidator handles IPv6 literals I noticed it accepts
http://[::FFFF:129.144.52.38]/(the case covered bytestValidator452) but rejects the same address in the standard lower-case mapped formhttp://[::ffff:129.144.52.38]/, and likewise rejects the IPv4-compatible::1.2.3.4and embedded2001:db8::1.2.3.4notations. The cause isIPV6_REGEXused byisValidAuthority: it only special-cases the literal upper-case::FFFF:prefix and otherwise matches[0-9a-fA-F:]+, which has no., so any bracketed host with an embedded IPv4 part fails the authority match beforeInetAddressValidator.isValidInet6Addressis ever consulted. That validator already accepts all of these forms, so the URL path and a direct address check disagree.The bracketed group is captured and then handed to
isValidInet6Address, so the regex only needs to delimit the candidate rather than judge it; I widened it to[0-9a-fA-F:.]+and left the real decision to the address validator. Keeping the judgement in one place stops the two paths drifting apart again, and malformed hosts (bad octet, stray::, over-long group) are still rejected because the address validator rejects them. Left unfixed, code using UrlValidator as an allow gate silently turns away legitimate IPv4-mapped IPv6 URLs.mvn; that'smvnon the command line by itself.