Skip to content
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

Issue #11495 - Add UriCompliance rules that follow the HTTP / URI / Servlet specs for illegal & suspicious characters #11496

Merged
merged 15 commits into from
Mar 27, 2024

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Mar 7, 2024

Adds 2 more UriCompliance.Violations

  • ILLEGAL_PATH_CHARACTERS for both the URI and HTTP spec rules about illegal (not encoded) characters
  • SUSPICIOUS_PATH_CHARACTERS for Servlet spec rules on suspicious (encoded or not) characters

Fixes: #11495

…ervlet specs for illegal & suspicious characters
@joakime joakime added Bug For general bugs on Jetty side Specification For all industry Specifications (IETF / Servlet / etc) labels Mar 7, 2024
@joakime joakime requested a review from gregw March 7, 2024 13:46
@joakime joakime self-assigned this Mar 7, 2024
@joakime
Copy link
Contributor Author

joakime commented Mar 7, 2024

joakime and others added 6 commits March 7, 2024 08:26
Check for illegal and suspicious characters as we are parsing the path.
Only look for ambiguous paths if we know there are dots or encodings.
gregw and others added 3 commits March 9, 2024 10:26
…backslash' into fix/12.0.x/uricompliance-reject-backslash

# Conflicts:
#	jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/DefaultServletTest.java
@gregw
Copy link
Contributor

gregw commented Mar 22, 2024

@joakime status of this?

@joakime joakime requested a review from gregw March 22, 2024 22:48
@joakime
Copy link
Contributor Author

joakime commented Mar 22, 2024

@gregw this PR is green and ready for review

Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost... but one question needs to be answered... plus a little javadoc

_canonicalPath = null;
String param = _param;
_param = null;
parse(State.PATH, path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm cautious about this, as this now allows for a query and fragment to be passed in via this method. Can this be done without a call to parse? perhaps we should check for ? and # characters before parsing... or does the isPathValid already do that?
Note we should javadoc if the path is raw or encoded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a fair number of places that uses this HttpURI.Mutable.path(String) API.
Interestingly, we actually need to parse the path in some of those places to satisfy the Servlet 6.0 "suspicious characters" rule. (eg: sendRedirect, getRequestDispatcher, etc)
I'm not sure what isPathValid you are mentioning here.
It would be great if we had a parsePath that only did the path, and if it encountered something outside of the scope of PATH (eg: query / fragment / etc) that would also be an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note we should javadoc if the path is raw or encoded.

As far as I'm concerned, this behavior didn't change for HttpURI.Mutable.path(String).
But since it wasn't originally documented, I'm not sure the intent of this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gregw bump

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joakime I've pushed a fix from my concern.... if you don't like it, we can revert and I'll OK this anyway.

gregw
gregw previously approved these changes Mar 27, 2024
@joakime joakime merged commit 05aa1e1 into jetty-12.0.x Mar 27, 2024
7 of 10 checks passed
@joakime joakime deleted the fix/12.0.x/uricompliance-reject-backslash branch March 27, 2024 14:28
sbordet pushed a commit that referenced this pull request Mar 28, 2024
…ervlet specs for illegal & suspicious characters (#11496)

* Issue #11495 - Add UriCompliance rules that follow the HTTP / URI / Servlet specs for illegal & suspicious characters
* more illegalPathCharacterData test cases
* Correcting SUSPICIOUS_PATH_CHARACTERS semantic (encoded and decoded)
* Check for illegal and suspicious characters as we are parsing the path.
* Only look for ambiguous paths if we know there are dots or encodings.

---------
Co-authored-by: gregw <[email protected]>
MarkEWaite added a commit to MarkEWaite/jenkins that referenced this pull request Jun 7, 2024
Servlet spec 6.0 requires HTTP 400 when the URI contains suspicious characters

https://jakarta.ee/specifications/servlet/6.0/jakarta-servlet-spec-6.0.html#uri-path-canonicalization

  If suspicious sequences are discovered during the prior processing
  steps, the request must be rejected with a 400 bad request rather than
  dispatched to the target servlet.

Windows absolute path targetTmpPath.toAbsolutePath() includes backslash
that is a suspicious character.

Included in Jetty 12.0.8 and later.

* jetty/jetty.project#11495
* jetty/jetty.project#11496
MarkEWaite added a commit to MarkEWaite/jenkins that referenced this pull request Jun 7, 2024
Servlet spec 6.0 requires HTTP 400 when the URI contains suspicious characters

https://jakarta.ee/specifications/servlet/6.0/jakarta-servlet-spec-6.0.html#uri-path-canonicalization

  If suspicious sequences are discovered during the prior processing
  steps, the request must be rejected with a 400 bad request rather than
  dispatched to the target servlet.

Windows absolute path targetTmpPath.toAbsolutePath() includes backslash
that is a suspicious character.

Included in Jetty 12.0.8 and later.

* jetty/jetty.project#11495
* jetty/jetty.project#11496
MarkEWaite added a commit to MarkEWaite/jenkins that referenced this pull request Jun 7, 2024
Servlet spec 6.0 requires HTTP 400 when the URI contains suspicious characters

https://jakarta.ee/specifications/servlet/6.0/jakarta-servlet-spec-6.0.html#uri-path-canonicalization

  If suspicious sequences are discovered during the prior processing
  steps, the request must be rejected with a 400 bad request rather than
  dispatched to the target servlet.

Windows path r.jenkins.getRootDir() includes backslash that is a
suspicious character.

Included in Jetty 12.0.8 and later.

* jetty/jetty.project#11495
* jetty/jetty.project#11496
MarkEWaite added a commit to MarkEWaite/jenkins that referenced this pull request Jun 13, 2024
Servlet spec 6.0 requires HTTP 400 when the URI contains suspicious characters

https://jakarta.ee/specifications/servlet/6.0/jakarta-servlet-spec-6.0.html#uri-path-canonicalization

  If suspicious sequences are discovered during the prior processing
  steps, the request must be rejected with a 400 bad request rather than
  dispatched to the target servlet.

Windows absolute path targetTmpPath.toAbsolutePath() includes backslash
that is a suspicious character.

Included in Jetty 12.0.8 and later.

* jetty/jetty.project#11495
* jetty/jetty.project#11496
MarkEWaite added a commit to MarkEWaite/jenkins that referenced this pull request Jun 13, 2024
Servlet spec 6.0 requires HTTP 400 when the URI contains suspicious characters

https://jakarta.ee/specifications/servlet/6.0/jakarta-servlet-spec-6.0.html#uri-path-canonicalization

  If suspicious sequences are discovered during the prior processing
  steps, the request must be rejected with a 400 bad request rather than
  dispatched to the target servlet.

Windows path r.jenkins.getRootDir() includes backslash that is a
suspicious character.

Included in Jetty 12.0.8 and later.

* jetty/jetty.project#11495
* jetty/jetty.project#11496
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side build-all-tests Specification For all industry Specifications (IETF / Servlet / etc)
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Add UriCompliance rules that follow the HTTP / URI / Servlet specs for illegal & suspicious characters
2 participants