Skip to content

make it clearer that @html is dangerous #7253

@ecstrema

Description

@ecstrema

Describe the problem

We just started a hackaton for the weekend, and decided to use svelte. 2 out of 4 of us had never used it before, so I recommended going through the tutorial.

The first reaction was (translated) "Happy to see that they tell users how to setup for xss attacks at the 4th page of the tutorial"

Followed by "In react they make you write __dangerousInnerHTML to make it clear that it's a bad idea, but here they are almost selling it as 'look how simple it is'".

They were talking about the @html tag and its corresponding page in the tutorial.

Describe the proposed solution

the @html tag is a great feature, but with great powers...

I would take three steps:

  1. Move the page to the end of the tutorial. Imo it has nothing to do in the introduction.
  2. Issue an error when @html is used, with an option to disable it.
  3. In svelte 4, deprecate @html for @dangerousInnerHtml or something alike.

Alternatives considered

EDIT: Bad alternative

add a sanitize option to @html blocks

<div>{@html:sanitize content}</div>

That would filter <script> tags and other "dangerous" elements.
That is probably too complex/dangerous to implement.

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions