lit / lit.dev

The Lit website
https://lit.dev
BSD 3-Clause "New" or "Revised" License
120 stars 186 forks source link

[docs] Add info on automatic XSS-prevention / escaped characters #448

Open interactiveRob opened 5 years ago

interactiveRob commented 5 years ago

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.

mikesamuel commented 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:

The team is aware of those risks and is working on addressing them.

interactiveRob commented 5 years ago

@mikesamuel Thanks for this info!

mikesamuel commented 5 years ago

On diving deeper, it turns out html`<button @onclick=${ x }>` is not problematic.

Will edit my summary.

lastmjs commented 4 years ago

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

leonheess commented 3 years ago

What's the status of this?

mikesamuel commented 3 years ago

@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.

empijei commented 1 month ago

Is there any update on this?