Skip to content

Bug: SVG executes contents of script tags. #25522

@nhunzaker

Description

@nhunzaker

Script tags within SVG execute their contents when rendered with React. This is surprising, and creates opportunities for XSS attacks when rendering user generated content.

React version: 17.02, 18.2.0

Steps To Reproduce

  1. Create an <svg> element with a <script> tag in it
  2. Render that element
  3. The children of that script tag will parse and execute as JavaScript

Link to code example:

https://codesandbox.io/s/modest-voice-kywwwu

The current behavior

In this example, you'll see that the script tag within HTML does not execute, however the script tag within SVG does.

The expected behavior

I would have expected the script's contents to be ignored in SVG, as it does in HTML.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: StaleAutomatically closed due to inactivityStatus: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions