Skip to content

React DOM escapes any values #3565

Description

@boan-jfm

I have discussed this particular sentence with a colleague:

By default, React DOM escapes any values embedded in JSX before rendering them. Thus it ensures that you can never inject anything that’s not explicitly written in your application. Everything is converted to a string before being rendered.

https://reactjs.org/docs/introducing-jsx.html#jsx-prevents-injection-attacks

Specific these two quotes: "React DOM escapes any values embedded in JSX before rendering them" and "Everything is converted to a string before being rendered"

As far as we know, everything is assigned via a Text-node and not escaped as the first sentence describes.

Mimicked example

const test = `<script>console.log("My log")</script>`;
let body = document.querySelector('body');
let content = new Text(test);
body.appendChild(content);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions