Cross-site Scripting (XSS)

Affecting preact-render-to-string package, versions <3.7.2

Do your applications use this vulnerable package? Test your applications

Overview

preact-render-to-string is a Render JSX and Preact components to an HTML string.

Affected versions of this package are vulnerable to Cross-site Scripting (XSS) attacks.

This attack is possible only only if the following two conditions are true:

  • The application is being rendered to HTML using ReactDOMServer API, and
  • The app includes a user-supplied attribute name in an HTML tag.

Server-rendered React apps, which contain the following pattern may by affected:

let props = {};
props[userProvidedData] = "hello";
let element = <div {...props} />;
let html = ReactDOMServer.renderToString(element);

Given the attacker could influence the userProvidedData, they could craft an attribute name that would triggler an XSS vulnerability, like:

></div><script>alert("hi")</script>`

Allowing the attacker to inject arbitrary markup:

<div ></div><script>alert("hi")</script>

Note: This vulnerability affects only some server-rendered React apps, which contain a the pattern. Purely client-rendered apps are not affected.

Remediation

Upgrade preact-render-to-string to versions 3.7.2 or higher.

References

CVSS Score

6.5
medium severity
  • Attack Vector
    Network
  • Attack Complexity
    Low
  • Privileges Required
    None
  • User Interaction
    Required
  • Scope
    Unchanged
  • Confidentiality
    High
  • Integrity
    None
  • Availability
    None
CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N
Credit
Unknown
CVE
CVE-2018-6341
CWE
CWE-79
Snyk ID
npm:preact-render-to-string:20180802
Disclosed
02 Aug, 2018
Published
02 Aug, 2018