michalmuskala / jason

A blazing fast JSON parser and generator in pure Elixir.
Other
1.6k stars 170 forks source link

:html_safe is NOT HTML save #109

Closed kaaboaye closed 4 years ago

kaaboaye commented 4 years ago

If json contains the following string <!-- anything here <script> it will comment out the rest of HTML braking the website.

The problem?

Adding the :html_safe to encode/2 doesn't escape this sequence.

https://hexdocs.pm/jason/Jason.html#encode/2

Reproduction

<script>
const a = "<!-- <script>"
</script>
<h1>This is commented out</h1>

Why is that?

Because of the HTML Spec https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements