seanhess / web-view

Typed HTML with simplified layout, and easy composable styles. Inspired by Tailwindcss and Elm UI
Other
32 stars 1 forks source link

CDATA escaping for inline <script> and <style> tags #6

Open kfigiela opened 1 week ago

kfigiela commented 1 week ago

3 accidentally introduced a regression wrt. to CSS rendering. <script> and <style> tags are special in HTML, as they are encoded as CDATA. That essentially means – no escaping, but closing tag can't appear in the payload content and HTML does not provide a way to escape this.

At the moment:

For example, addClass $ cls "test" & prop "background" ("url('https://picsum.photos/200/300?random=1&foo=2=bar')" :: Text)) will generate incorrect result:

<style type='text/css'>
.empty { background:url(&#39;https://picsum.photos/200/300?random=1&amp;foo=2=bar&#39;) }
</style>

Potential solution could be to introduce External to AST, which would be always the same as Raw but would refuse to include any </ sequence which would prevent XSS/invalid HTML. This is what blaze-markup does for these tags.


Trivia: Historically, people would split string literals in JS payloads to "escape" them, e.g.

<script>document.write('<scr'+'ipt type="text/javascript" src="http://example.com/some.js"></sc'+'ript>');</script>
seanhess commented 1 week ago

That plans works for me!

seanhess commented 1 week ago

Let's make sure to add tests when we go in to fix