Open interactiveRob opened 5 years ago
lit-html works by building a DOM tree, so injection of whole script elements is not an issue, but there are others.
The known XSS risks are:
<img src=bogus onerror=alert(document.origin)>
can inject code even though straightforward <script>
injection fails.html`<script>${ x }</script>`
html`<iframe srcdoc=${ x }>`
or html`<script src=${ x }></script>`
html`<div .innerHTML=${ x }>`
html`<button @onclick=${ x }>`
The team is aware of those risks and is working on addressing them.
@mikesamuel Thanks for this info!
On diving deeper, it turns out html`<button @onclick=${ x }>`
is not problematic.
Will edit my summary.
Is there any official documentation on the security/threat model of lit-html? I feel this is very important information and would be very useful to include as a section on the official website: https://lit-html.polymer-project.org
What's the status of this?
@lastmjs https://github.com/Polymer/polymer-resin#readme captures my threat modelling when I wrote resin. I don't speak for the Polymer project though.
Is there any update on this?
Description
In this article, it mentions that 'lit-html' includes XSS-prevention. That's what lead me to this library. https://benfrain.com/html-templating-with-vanilla-javascript-es2015-template-literals/
Naturally, I wanted to verify that before using lit-html so I searched for 'escape' and 'XSS' in the documentation, but I wasn't able to find any mention of that functionality anywhere.
By trial and error, I found out that lit-html automatically removes tags when using the html tagged template literal.
I also could not find info about the unsafeHTML directive in the docs although it is included in the source code.