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

Follow WHATWG guidance for incorrectly-closed HTML comments #2058

Merged
merged 3 commits into from
Nov 21, 2020

Conversation

flavorjones
Copy link
Member

@flavorjones flavorjones commented Aug 3, 2020

This changeset introduces test coverage for both JRuby and CRuby implementations with respect to handling HTML parse errors within comments.

It then introduces a libxml2 patch to comply with the behavior suggested by the WHATWG "Living Standard" doc with respect to incorrectly-closed comments.

It's important to note that WHATWG's guidance is non-normative, but is what's followed by most popular browsers. Further, the difference in behavior between browsers and server-side sanitization done by a library relying on Nokogiri and libxml2 allows opportunity for XSS attacks (https://owasp.org/www-project-top-ten/OWASP_Top_Ten_2017/Top_10-2017_A7-Cross-Site_Scripting_(XSS)).

@codeclimate
Copy link

codeclimate bot commented Aug 3, 2020

Code Climate has analyzed commit 6c1c5fa and detected 0 issues on this pull request.

View more on Code Climate.

@flavorjones flavorjones force-pushed the flavorjones-explore-comment-errors branch from ce3c0bd to 1d0ab01 Compare August 3, 2020 22:49
@AppVeyorBot
Copy link

@flavorjones flavorjones force-pushed the flavorjones-explore-comment-errors branch 2 times, most recently from 48e4a33 to b8719a4 Compare August 4, 2020 12:48
@AppVeyorBot
Copy link

Build nokogiri 1.0.626 failed (commit 039b8d37d3 by @flavorjones)

@flavorjones flavorjones force-pushed the flavorjones-explore-comment-errors branch from b8719a4 to 6c1c5fa Compare August 4, 2020 15:53
@AppVeyorBot
Copy link

@flavorjones
Copy link
Member Author

Also see related upstream merge request: https://gitlab.gnome.org/GNOME/libxml2/-/merge_requests/82

this is pre-work related to what I think is an upstream issue in
libxml2 regarding parsing comments.
@flavorjones flavorjones force-pushed the flavorjones-explore-comment-errors branch from 4f0e359 to eaa9c73 Compare November 21, 2020 20:59
@flavorjones flavorjones merged commit ee3504a into master Nov 21, 2020
@flavorjones flavorjones deleted the flavorjones-explore-comment-errors branch November 21, 2020 21:06
@flavorjones flavorjones added this to the v1.11.0 milestone Nov 21, 2020
flavorjones added a commit that referenced this pull request Aug 17, 2021
…ed-html-comments

feat(cruby): patch libxml2 to handle abruptly-closed HTML comments

---

**What problem is this PR intended to solve?**

Hackerone user [tehryanx](https://hackerone.com/tehryanx?type=user) reported a method of potentially confusing Loofah sanitizers by taking advantage of the difference between how abruptly-closed comments are handled by libxml2 and how they're handled by WHATWG-guidance-compliant modern browsers.

WHATWG advises to treat `<!-->` and `<!--->` as empty comments, but libxml2 today treats these as the _start_ of a comment.

https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-closing-of-empty-comment

I've submitted this patch upstream at https://gitlab.gnome.org/GNOME/libxml2/-/merge_requests/124

Similar prior art is for incorrectly-closed comments:

- #2058
- https://gitlab.gnome.org/GNOME/libxml2/-/merge_requests/82


**Have you included adequate test coverage?**

Yes!


**Does this change affect the behavior of either the C or the Java implementations?**

This is a behavior change to libxml2/CRuby. Note that nekoHTML/JRuby already follow WHATWG guidance and so JRuby behavior is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants