Repository navigation
split the authority before IDN conversion in isValidAuthority - #438
Open
sahvx655-wq wants to merge 1 commit into
Open
sahvx655-wq wants to merge 1 commit into
sahvx655-wq wants to merge 1 commit into
Conversation
isValidAuthority converted the whole authority with IDN.toASCII and split the result. Nameprep folds the fullwidth '@' and ':' to ASCII and punycode encodes a whole label, so the conversion invented delimiters that are not in the URL and pulled the userinfo or port into the host label. Match the raw authority instead and let DomainValidator convert the host alone.
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.
mvn; that'smvnon the command line by itself.UrlValidator.isValidAuthoritypasses the whole authority, userinfo and port included, toDomainValidator.unicodeToASCIIand only then splits the converted text withAUTHORITY_PATTERN. I got there from a plain false negative:isValid("http://президент.рф:8080/")is false although the same host without a port passes, and printing the converted authority showedxn--d1abbgf6aiiy.xn--:8080-uye2a, the port punycoded into the last label. The ordering has a worse side, because nameprep folds compatibility characters to ASCII: a fullwidth commercial at (U+FF20) or colon (U+FF1A) comes back as a real@or:, soisValid("http://example.com\uFF20apache.org/")is true withexample.comread as userinfo and onlyapache.orgchecked as the host, whilejava.net.URIsees a single registry-based authority with no userinfo. That is host confusion through Unicode normalisation (the HostSplit pattern): the validator approves a URL after parsing a structure the URL does not have, anduser:pass@hôst.comis likewise checked as the unrelated hosthst-zlb.com.The fix stays in the regex: the host group of
AUTHORITY_REGEXnow admits non-ASCII characters, so the raw authority is split first and the whole-authority conversion goes away, sinceDomainValidator.isValidalready converts the host it is handed. An all-ASCII authority matches exactly as before, and the format code point, boundary hyphen and port range checks still run on the userinfo and port paths. It belongs inisValidAuthoritybecause that is the only place that knows where the host starts and ends; a caller cannot undo a split made on the wrong string.testIdnAuthorityfails on master at its first assertion and passes with the change, and the defaultmvngoal with-Ddoclint=allis green (3300 tests, Checkstyle, PMD, SpotBugs, japicmp and RAT clean). The comment onunicodeToASCIIis corrected becauseUrlValidatorno longer calls it.