Vulnerabilities in pkg:npm/react-admin

PACKAGE
Advisory Identifier: GHSA-5jcr-82fh-339v
Advisory Summary

CVE-2023-25572 is a MODERATE (CVSS 5.4) cross-site-scripting attack on `<richtextfield>` vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting React admin libraries in the npm ecosystem. The issue involves cross-site-scripting attack on `<richtextfield>`. Remediation is available by upgrading affected packages to version 3.19.12, 4.7.6.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/react-admin

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/react-admin. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-5jcr-82fh-339v CVE-2023-25572 MODERATE Cross-Site-Scripting attack on `<RichTextField>`

CVE-2023-25572 at a Glance

CVE Identifier CVE-2023-25572
GHSA Identifier GHSA-5jcr-82fh-339v
Severity MODERATE
CVSS v3.1 Base Score 5.4
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product React admin
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.4

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2023-25572

To remediate this vulnerability, upgrade all affected React admin dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

react-admin fixed: 3.19.12
npm install react-admin@3.19.12
react-admin fixed: 4.7.6
npm install react-admin@4.7.6
ra-ui-materialui fixed: 4.7.6
npm install ra-ui-materialui@4.7.6
ra-ui-materialui fixed: 3.19.12
npm install ra-ui-materialui@3.19.12
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls react-admin

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2023-25572, inspect your project dependencies using npm:

npm ls react-admin

Analyze the terminal output to locate any version of React admin in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.19.12), your application is affected.

Note: The npm ls react-admin command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In React admin, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact All React applications built with react-admin and using the `<RichTextField>` are affected. `<RichTextField>` outputs the field value using `dangerouslySetInnerHTML` without client-side sanitization. If the data isn't sanitized server-side, this opens a possible Cross-Site-Scripting (XSS) attack. Proof of concept: ```jsx import { RichTextField } from 'react-admin'; const record = { id: 1, body: ` <p> <strong>War and Peace</strong> is a novel by the Russian author <a href="https://en.wikipedia.org/wiki/Leo_Tolstoy" onclick="document.getElementById('stolendata').value='credentials';">Leo Tolstoy</a>, published serially, then in its entirety in 1869. </p> <p onmouseover="document.getElementById('stolendata').value='credentials';"> It is regarded as one of Tolstoy's finest literary achievements and remains a classic of world literature. </p> <img src="x" onerror="document.getElementById('stolendata').value='credentials';" /> `, }; const VulnerableRichTextField = () => ( <> <RichTextField record={record} source="body" /> <hr /> <h4>Stolen data:</h4> <input id="stolendata" defaultValue="none" /> </> ); ``` ### Patches Versions 3.19.12 and 4.7.6 now use `DOMPurify` to escape the HTML before outputting it with React and `dangerouslySetInnerHTML` ### Workarounds You don't need to upgrade if you already sanitize HTML data server-side. Otherwise, you'll have to replace the `<RichTextField>` by a custom field doing sanitization by hand: ```tsx // react-admin v4 import * as React from 'react'; import { memo } from 'react'; import PropTypes from 'prop-types'; import get from 'lodash/get'; import Typography from '@material-ui/core/Typography'; import { useRecordContext, sanitizeFieldRestProps, fieldPropTypes } from 'react-admin'; import purify from 'dompurify'; export const removeTags = (input) => input ? input.replace(/<[^>]+>/gm, '') : ''; const RichTextField = memo( props => { const { className, emptyText, source, stripTags, ...rest } = props; const record = useRecordContext(props); const value = get(record, source); return ( <Typography className={className} variant="body2" component="span" {...sanitizeFieldRestProps(rest)} > {value == null && emptyText ? ( emptyText ) : stripTags ? ( removeTags(value) ) : ( <span dangerouslySetInnerHTML={{ __html: purify.sanitize(value), }} /> )} </Typography> ); } ); RichTextField.defaultProps = { addLabel: true, stripTags: false, }; RichTextField.propTypes = { // @ts-ignore ...Typography.propTypes, ...fieldPropTypes, stripTags: PropTypes.bool, }; RichTextField.displayName = 'RichTextField'; export default RichTextField; ``` ### References https://github.com/marmelab/react-admin/pull/8644, https://github.com/marmelab/react-admin/pull/8645

CVE-2023-25572 Affected React admin Versions

4 component(s)
Fixed Versions:
3.19.124.7.6
Product / Package Ecosystem Affected Versions Fixed Version
react-admin
npm
< 3.19.12
3.19.12
react-admin
npm
≥ 4.0.0
< 4.7.6
4.7.6
ra-ui-materialui
npm
≥ 4.0.0
< 4.7.6
4.7.6
ra-ui-materialui
npm
< 3.19.12
3.19.12

References

Frequently Asked Questions

What is CVE-2023-25572?
CVE-2023-25572 is a security vulnerability in React admin involving Cross-Site-Scripting attack on `<RichTextField>` under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which React admin versions are affected?
Affected versions include releases prior to 3.19.12, 4.7.6 across affected packages: react-admin, ra-ui-materialui.
What version fixes CVE-2023-25572?
Upgrading to 3.19.12, 4.7.6 (or the latest patched release for your respective branch) resolves the vulnerability.
Is react-admin affected?
Yes, react-admin is affected in releases prior to 3.19.12, 4.7.6. Upgrade your dependency to 3.19.12, 4.7.6 or later.
Is ra-ui-materialui affected?
Yes, ra-ui-materialui is affected in releases prior to 4.7.6, 3.19.12. Upgrade your dependency to 4.7.6, 3.19.12 or later.
What is the CVSS score of CVE-2023-25572?
CVE-2023-25572 has a CVSS v3.1 base score of 5.4 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2023-25572?
CVE-2023-25572 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check npm dependencies for CVE-2023-25572?
Run the dependency tree command: 'npm ls react-admin'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-5jcr-82fh-339v",
  "modified" : "2023-02-14T00:32:21Z",
  "published" : "2023-02-14T00:32:21Z",
  "aliases" : [ "CVE-2023-25572" ],
  "summary" : "Cross-Site-Scripting attack on `<RichTextField>`",
  "details" : "### Impact\n\nAll React applications built with react-admin and using the `<RichTextField>` are affected. \n\n`<RichTextField>` outputs the field value using `dangerouslySetInnerHTML` without client-side sanitization. If the data isn't sanitized server-side, this opens a possible Cross-Site-Scripting (XSS) attack. \n\nProof of concept:\n\n```jsx\nimport { RichTextField } from 'react-admin';\n\nconst record = {\n    id: 1,\n    body: `\n<p>\n<strong>War and Peace</strong> is a novel by the Russian author\n<a href=\"https://en.wikipedia.org/wiki/Leo_Tolstoy\" onclick=\"document.getElementById('stolendata').value='credentials';\">Leo Tolstoy</a>,\npublished serially, then in its entirety in 1869.\n</p>\n<p onmouseover=\"document.getElementById('stolendata').value='credentials';\">\nIt is regarded as one of Tolstoy's finest literary achievements and remains a classic of world literature.\n</p>\n<img src=\"x\" onerror=\"document.getElementById('stolendata').value='credentials';\" />\n`,\n};\n\nconst VulnerableRichTextField = () => (\n    <>\n        <RichTextField record={record} source=\"body\" />\n        <hr />\n        <h4>Stolen data:</h4>\n        <input id=\"stolendata\" defaultValue=\"none\" />\n    </>\n);\n```\n\n### Patches\n\nVersions 3.19.12 and 4.7.6 now use `DOMPurify` to escape the HTML before outputting it with React and `dangerouslySetInnerHTML`\n\n### Workarounds\n\nYou don't need to upgrade if you already sanitize HTML data server-side. \n\nOtherwise, you'll have to replace the `<RichTextField>` by a custom field doing sanitization by hand:\n\n```tsx\n// react-admin v4\nimport * as React from 'react';\nimport { memo } from 'react';\nimport PropTypes from 'prop-types';\nimport get from 'lodash/get';\nimport Typography from '@material-ui/core/Typography';\nimport { useRecordContext, sanitizeFieldRestProps, fieldPropTypes } from 'react-admin';\nimport purify from 'dompurify';\n\nexport const removeTags = (input) =>\n    input ? input.replace(/<[^>]+>/gm, '') : '';\n\nconst RichTextField = memo(\n    props => {\n        const { className, emptyText, source, stripTags, ...rest } = props;\n        const record = useRecordContext(props);\n        const value = get(record, source);\n\n        return (\n            <Typography\n                className={className}\n                variant=\"body2\"\n                component=\"span\"\n                {...sanitizeFieldRestProps(rest)}\n            >\n                {value == null && emptyText ? (\n                    emptyText\n                ) : stripTags ? (\n                    removeTags(value)\n                ) : (\n                    <span\n                        dangerouslySetInnerHTML={{\n                            __html: purify.sanitize(value),\n                        }}\n                    />\n                )}\n            </Typography>\n        );\n    }\n);\n\nRichTextField.defaultProps = {\n    addLabel: true,\n    stripTags: false,\n};\n\nRichTextField.propTypes = {\n    // @ts-ignore\n    ...Typography.propTypes,\n    ...fieldPropTypes,\n    stripTags: PropTypes.bool,\n};\n\nRichTextField.displayName = 'RichTextField';\n\nexport default RichTextField;\n```\n\n### References\n\nhttps://github.com/marmelab/react-admin/pull/8644, https://github.com/marmelab/react-admin/pull/8645\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "react-admin"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.19.12"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "react-admin"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0"
      }, {
        "fixed" : "4.7.6"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "ra-ui-materialui"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0"
      }, {
        "fixed" : "4.7.6"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "ra-ui-materialui"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.19.12"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/marmelab/react-admin/security/advisories/GHSA-5jcr-82fh-339v"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-25572"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/marmelab/react-admin/pull/8644"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/marmelab/react-admin/pull/8645"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/marmelab/react-admin"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/marmelab/react-admin/releases/tag/v3.19.12"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/marmelab/react-admin/releases/tag/v4.7.6"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-02-14T00:32:21Z",
    "nvd_published_at" : "2023-02-13T21:15:00Z"
  }
}