-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #4275 fail URIs with ambiguous segments #5954
Conversation
Fix #4275 fail URIs with ambiguous segments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are changing HttpURI
parsing, I think we should go the extra mile and do it as per RFC3986.
https://tools.ietf.org/html/rfc3986#section-3.3 says that even the ,
can be used as separator between a segment and a segment-parameter.
But if we go to the ABNF, possibly any sub-delims
can be present, and we should not consider those as part of the segment.
Doing so would probably require another compliance mode.
I changed testAmbiguousSegments()
and using a ,
instead of ;
fails the test.
@sbordet I don't see why we should treat ',' as a parameter separator? It might be used as such in some schemes, but not in HTTP. We will never split a segment by ',', but we do split by ';'. I think we need to be absolutely consistent with our handling to avoid issues, so if we start splitting on ',' here, we'd have to split everywhere and I don't think that is valid to do. We are treating |
Invert sense of ambiguous path segment compliance added test
Because the RFC says:
So if The fact that it's not used typically in HTTP does not mean pentesters can't generate such URIs to validate URI handling. |
We only have an issue with HTTP schema URIs as that is all we handle. We never split on Remember, we are not disallowing |
There are multiple things to consider here. First there's Reserved Characters - https://tools.ietf.org/html/rfc3986#section-2.2
Which means The following example URIs should be considered in this PR.
Then we have Remove Dot Segments - https://tools.ietf.org/html/rfc3986#section-5.2.4 This is getting quite complicated, and I'm wondering if we REALLY need to support URI parameters at all? I have been unable to find another web server that supports them. Two examples:
|
An interesting read on a complex / contrived URI example. |
I retract this statement, I've found many examples in REST libraries that use various forms of the reserved characters in the URI to mean special things to the REST library. Some even making the "contrived" example in the devtest link look easy to follow. |
@sbordet and @joakime, you are over complicating this and missing the actual issue! Our URI handling is correct according to both the RFC and the servlet spec. However, there is a problem between those two spec. The RFC says that This is ONLY a problem with |
…75-ambiguous-path-segments
Note also that the code doesn't actually treat However, I will double check how we handle things like |
OK, I think I have found one more related issue. The RFC says the URI is: URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] We correctly normalise |
Fixed tests for `%2e%2e`
+ Correctly handle canonical trailing '.' and '..' + Perform canonical path resolution before decoding + Treat decoding of %2f as an ambiguous segment. + better tests of ambiguous segments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the majority of this PR, I just don't like one aspect of the ambiguousSegments list.
+ Fixed test failures that were using %2f
Signed-off-by: Greg Wilkins <[email protected]>
@sbordet nudge |
jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java
Outdated
Show resolved
Hide resolved
+ simplified tests
jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java
Outdated
Show resolved
Hide resolved
jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java
Show resolved
Hide resolved
Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
updates from review
if (query != null) | ||
_query = query; | ||
if (fragment != null) | ||
_fragment = fragment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not do null checks for just assignments.
Path needs null check because path.length()
may NPE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm doing null checks because if we parse the path, we may discover params, fragments and queries in it. So either we through if they are non null, or just not overwrite them unless we have explicit non null values.
updates from review
Rewrite rule depending on probably bug that setURIPathQuery did not actually set query if none was passed. This is a bit of a work around, but further review is needed to see if anything else relied on that behaviour.
Re re Fix rewrite tests for #5954. Restore setPathQuery behaviour to preserve queries if none are set.
Re re Fix rewrite tests for #5954. Restore setPathQuery behaviour to preserve queries if none are set.
Cleanup setPathQuery from #5954 so that it does not retain an old query if the passed string does not contain a query
Fix #4275 fail URIs with ambiguous segments.