Validate path, query and fragment for authority-less file URLs - #432
Open
sahvx655-wq wants to merge 1 commit into
Open
Validate path, query and fragment for authority-less file URLs#432sahvx655-wq wants to merge 1 commit into
sahvx655-wq wants to merge 1 commit into
Conversation
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.
isValidreturns as soon as it sees afile:scheme with a blank authority, and that return sits above the line callingisValidPath,isValidQueryandisValidFragment. Every ordinary file URL has no authority, sinceURI.getRawAuthority()is null forfile:/xandfile:///xalike, so for a validator configured with the file scheme that whole stage is unreachable. I went looking after checking whether the percent-encoded traversal guard from VALIDATOR-383 held across schemes:isValid("file:///../../etc/passwd")andisValid("file:///..%2f..%2fetc/passwd")both come back true, while the byte-identical path written under an authority,file://localhost/../../etc/passwd, is correctly rejected. The option flags behave the same way, sofile:///tmp/a//bpasses withALLOW_2_SLASHESoff andfile:///tmp/x#fragpasses withNO_FRAGMENTSon.The special case exists only to excuse a file URL from carrying an authority, so I have narrowed it to skip the authority check alone rather than to leave the method. Keeping the decision in
isValidmeans every scheme reaches the same three per-part checks; moving containment out to callers would leave the hole open for anyone who configures the file scheme, and an application that normalises a validatedfile:URL into a filesystem path is exactly where that gets expensive. One deliberate behaviour change worth flagging: an opaque URI such asfile:etc/passwdhas a null raw path and is now rejected, which is whathttp:example.comalready does. The existing file expectations intestValidator276,testValidator391FAILSandtestValidator391OKare unchanged, and both added tests fail without the runtime change.Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.