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 #4334 - Improve testing of ErrorHandler behavior #4335

Merged
merged 2 commits into from Nov 20, 2019

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Nov 20, 2019

Signed-off-by: Joakim Erdfelt joakim.erdfelt@gmail.com

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@joakime joakime added the Test label Nov 20, 2019
@joakime joakime self-assigned this Nov 20, 2019
@joakime joakime added this to In progress in Jetty 9.4.24 via automation Nov 20, 2019
@joakime joakime moved this from In progress to Review in progress in Jetty 9.4.24 Nov 20, 2019
+ Cleanup from PR review

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>

if (contentType.contains("text/html"))
{
assertThat(content, not(containsString("<script>")));
Copy link

Choose a reason for hiding this comment

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

The usefulness of such an attack isn't as obvious as script tags in HTML, but we should assure that (potentially malformed) JSON or XML messages in exceptions are properly escaped as well. Eg. new Exception(""}{"I am injected JSON":"evil"}{"void":"") or new Exception("evil"), or whatever could break out of the JSON/XML structure and create or modify elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's been addressed.
The ErrorHandler only produces text/html, text/json, or text/plain output.

For text/json all content from exceptions (the stacktrace, messages, causes, and supressed) are filtered via StringUtil.sanitizeXmlString()

For text/json all values are filtered via the same StringUtil.sanitizeXmlString().

For text/plain they are left alone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add another test for the JSON example you provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's fine.
See commit 217602e

The generated text/json looks like this ...

{
"cause1":"java.lang.RuntimeException: &quot;}, &quot;glossary&quot;: {\n &quot;title&quot;: &quot;example&quot;\n }\n {&quot;",
"cause0":"javax.servlet.ServletException: java.lang.RuntimeException: &quot;}, &quot;glossary&quot;: {\n &quot;title&quot;: &quot;example&quot;\n }\n {&quot;",
"message":"javax.servlet.ServletException: java.lang.RuntimeException: &quot;}, &quot;glossary&quot;: {\n &quot;title&quot;: &quot;example&quot;\n }\n {&quot;",
"url":"/jsonmessage/",
"status":"500"
}

Jetty 9.4.24 automation moved this from Review in progress to Reviewer approved Nov 20, 2019
@joakime joakime merged commit ba1fe28 into jetty-9.4.x Nov 20, 2019
Jetty 9.4.24 automation moved this from Reviewer approved to Done Nov 20, 2019
@joakime joakime deleted the jetty-9.4.x-improve-error-handler-output branch November 21, 2019 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Jetty 9.4.24
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants