Skip to content

Escape JSON to avoid parsing the content as HTML#232

Merged
RyanGlScott merged 1 commit intohaskell:masterfrom
considerate:master
Nov 17, 2020
Merged

Escape JSON to avoid parsing the content as HTML#232
RyanGlScott merged 1 commit intohaskell:masterfrom
considerate:master

Conversation

@considerate
Copy link
Copy Markdown
Contributor

@considerate considerate commented Nov 16, 2020

By crafting a malicious string it was quite easy to escape the HTML
attribute that contained the JSON report data allowing injection of
arbitrary HTML using the report names.

This commit aims to mitigate the breakage of the reports when report names
contain unexpected characters. The JSON data is moved to a <script> tag and
the content is escaped by replacing significant HTML characters with their
corresponding JSON escape sequences. The '<' character is replaced with the
sequence "\u003c", '&' is replaced with "\u0026" and so on.

screenshot-2020-11-16T23:03:20+09:00

The processing of / is still not ideal, if a report name contains that character
then it is treated as a group separator.

Copy link
Copy Markdown
Member

@RyanGlScott RyanGlScott left a comment

Choose a reason for hiding this comment

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

Good catch! Is this bug present in all versions of criterion, or only after #229?

Comment thread Criterion/Report.hs
Comment thread Criterion/Report.hs Outdated
Comment thread Criterion/Report.hs Outdated
@considerate
Copy link
Copy Markdown
Contributor Author

considerate commented Nov 16, 2020

Is this bug present in all versions of criterion, or only after #229?

I've only tested with criterion-1.5.8.0 but I think it would be possible to inject HTML in previous versions as well. I'll test and see if it breaks in previous versions as well.

EDIT:
It seems to have been broken in previous versions as well:

screenshot-2020-11-17T02:11:07+09:00

@considerate considerate force-pushed the master branch 2 times, most recently from b6cf1e7 to b7982c5 Compare November 16, 2020 18:00
Comment thread Criterion/Report.hs
Comment thread Criterion/Report.hs
By crafting a malicious string it was quite easy to escape the HTML
attribute that contained the JSON report data.

This commit aims to mitigate the breakage of the reports when report
names contain unexpected characters. The JSON data is moved to a
<script> tag and the content is escaped by replacing significant HTML
characters with their corresponding JSON escape sequences. The '<'
character is replaced with the sequence "\u003c", '&' is replaced with
"\u0026" and so on.
@RyanGlScott RyanGlScott merged commit f494ba2 into haskell:master Nov 17, 2020
RyanGlScott added a commit that referenced this pull request Nov 17, 2020
@RyanGlScott
Copy link
Copy Markdown
Member

Thanks again! I've uploaded criterion-1.5.9.0 to Hackage with these changes.

@considerate
Copy link
Copy Markdown
Contributor Author

@RyanGlScott Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants