Skip to content

XSS vulnerability when using SSR #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
romandecker opened this issue Mar 16, 2020 · 3 comments
Closed

XSS vulnerability when using SSR #9

romandecker opened this issue Mar 16, 2020 · 3 comments

Comments

@romandecker
Copy link

There's a potential XSS problem when using this library with server-side-rendering (which is arguably one of the most prominent use-cases to render json-ld):

const React = require("react");
const express = require("express");
const ReactDOMServer = require("react-dom/server");
const { JsonLd } = require("react-schemaorg");

const dangerous = "</script><script>alert('xss')</script>";

express()
  .get("/", (req, res) =>
    res.send(
      ReactDOMServer.renderToString(
        <div>
          <p>It's ok here: {dangerous}</p>
          <p>
            But not here: <JsonLd item={{ name: dangerous }} />
          </p>
        </div>
      )
    )
  )
  .listen(2000, () => console.log("Listening on port 2000"));

This will result in an alert being shown when accessing http://localhost:2000. Here's a repo to quickly reproduce the issue: https://github.com/DeX3/react-schemaorg-ssr-xss-poc

@Eyas
Copy link
Collaborator

Eyas commented Mar 16, 2020

Nice! Thanks for the report. Indeed we'll want the item set to only be a valid JSON object.

@Eyas
Copy link
Collaborator

Eyas commented Mar 16, 2020

Oh I misread, I thought you were setting the whole item to a string with "</script>" but I just realized you're setting just the 'name' property.

@Eyas Eyas closed this as completed in 22e7dec Mar 17, 2020
@Eyas
Copy link
Collaborator

Eyas commented Mar 17, 2020

This should be released later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants