Vulnerabilities in pkg:npm/@udecode/plate-media

PACKAGE
Advisory Identifier: GHSA-h3pq-667x-r789
Advisory Summary

CVE-2024-40631 is a HIGH (CVSS 8.1) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting @udecode/plate media libraries in the npm ecosystem. The issue involves plate media plugins has a xss in media embed element when using custom url parsers. Remediation is available by upgrading affected packages to version 36.0.10.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/@udecode/plate-media

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/@udecode/plate-media. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-h3pq-667x-r789 CVE-2024-40631 HIGH Plate media plugins has a XSS in media embed element when using custom URL parsers

CVE-2024-40631 at a Glance

CVE Identifier CVE-2024-40631
GHSA Identifier GHSA-h3pq-667x-r789
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product @udecode/plate media
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.1

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:N/S:U/C:H/I:H/A:N).

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

How to Fix CVE-2024-40631

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

@udecode/plate-media fixed: 36.0.10
npm install @udecode/plate-media@36.0.10
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 @udecode/plate-media

How to Check if You Are Affected

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

npm ls @udecode/plate-media

Analyze the terminal output to locate any version of @udecode/plate media in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 36.0.10), your application is affected.

Note: The npm ls @udecode/plate-media 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 @udecode/plate media, 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 Editors that use `MediaEmbedElement` and pass custom `urlParsers` to the `useMediaState` hook may be vulnerable to XSS if a custom parser allows `javascript:`, `data:` or `vbscript:` URLs to be embedded. Editors that do not use `urlParsers` and instead consume the `url` property directly may also be vulnerable if the URL is not sanitised. The default parsers `parseTwitterUrl` and `parseVideoUrl` are not affected. Examples of vulnerable code: ```tsx const { embed } = useMediaState({ urlParsers: [ // Custom parser that does not use an allowlist or validate the URL protocol (url) => ({ url }), ], }); return ( <iframe src={embed!.url} // ... /> ); ``` ```tsx const { url } = useMediaState(); return ( <iframe // url property used directly from useMediaState() with no sanitisation src={url} // ... /> ); ``` ```tsx const { url } = element; return ( <iframe // url property used directly from element with no sanitisation src={url} // ... /> ); ``` ### Patches `@udecode/plate-media` 36.0.10 resolves this issue by only allowing HTTP and HTTPS URLs during parsing. This affects only the `embed` property returned from `useMediaState`. In addition, the `url` property returned from `useMediaState` has been renamed to `unsafeUrl` to indicate that it has not been sanitised. The `url` property on `element` is also unsafe, but has not been renamed. If you're using either of these properties directly, you will still need to validate the URL yourself. ### Workarounds Ensure that any custom `urlParsers` do not allow `javascript:`, `data:` or `vbscript:` URLs to be returned in the `url` property of their return values. If `url` is consumed directly, validate the URL protocol before passing it to the `iframe` element. ### References How to verify the protocol of a URL: https://stackoverflow.com/a/43467144

CVE-2024-40631 Affected @udecode/plate media Versions

1 component(s)
Fixed Versions:
36.0.10
Product / Package Ecosystem Affected Versions Fixed Version
@udecode/plate-media
npm
< 36.0.10
36.0.10

References

Frequently Asked Questions

What is CVE-2024-40631?
CVE-2024-40631 is a security vulnerability in @udecode/plate media involving Plate media plugins has a XSS in media embed element when using custom URL parsers under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which @udecode/plate media versions are affected?
Affected versions include releases prior to 36.0.10 across affected packages: @udecode/plate-media.
What version fixes CVE-2024-40631?
Upgrading to 36.0.10 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @udecode/plate-media affected?
Yes, @udecode/plate-media is affected in releases prior to 36.0.10. Upgrade your dependency to 36.0.10 or later.
What is the CVSS score of CVE-2024-40631?
CVE-2024-40631 has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N.
What CWE is associated with CVE-2024-40631?
CVE-2024-40631 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-2024-40631?
Run the dependency tree command: 'npm ls @udecode/plate-media'. 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-h3pq-667x-r789",
  "modified" : "2024-07-15T21:38:09Z",
  "published" : "2024-07-15T18:33:22Z",
  "aliases" : [ "CVE-2024-40631" ],
  "summary" : "Plate media plugins has a XSS in media embed element when using custom URL parsers",
  "details" : "### Impact\nEditors that use `MediaEmbedElement` and pass custom `urlParsers` to the `useMediaState` hook may be vulnerable to XSS if a custom parser allows `javascript:`, `data:` or `vbscript:` URLs to be embedded. Editors that do not use `urlParsers` and instead consume the `url` property directly may also be vulnerable if the URL is not sanitised.\n\nThe default parsers `parseTwitterUrl` and `parseVideoUrl` are not affected.\n\nExamples of vulnerable code:\n\n```tsx\nconst { embed } = useMediaState({\n  urlParsers: [\n    // Custom parser that does not use an allowlist or validate the URL protocol\n    (url) => ({ url }),\n  ],\n});\n\nreturn (\n  <iframe\n    src={embed!.url}\n    // ...\n  />\n);\n```\n\n```tsx\nconst { url } = useMediaState();\n\nreturn (\n  <iframe\n    // url property used directly from useMediaState() with no sanitisation\n    src={url}\n    // ...\n  />\n);\n```\n\n\n```tsx\nconst { url } = element;\n\nreturn (\n  <iframe\n    // url property used directly from element with no sanitisation\n    src={url}\n    // ...\n  />\n);\n```\n\n### Patches\n`@udecode/plate-media` 36.0.10 resolves this issue by only allowing HTTP and HTTPS URLs during parsing. This affects only the `embed` property returned from `useMediaState`.\n\nIn addition, the `url` property returned from `useMediaState` has been renamed to `unsafeUrl` to indicate that it has not been sanitised. The `url` property on `element` is also unsafe, but has not been renamed. If you're using either of these properties directly, you will still need to validate the URL yourself.\n\n### Workarounds\nEnsure that any custom `urlParsers` do not allow `javascript:`, `data:` or `vbscript:` URLs to be returned in the `url` property of their return values.\n\nIf `url` is consumed directly, validate the URL protocol before passing it to the `iframe` element.\n\n### References\nHow to verify the protocol of a URL: https://stackoverflow.com/a/43467144",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:A/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@udecode/plate-media"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "36.0.10"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/udecode/plate/security/advisories/GHSA-h3pq-667x-r789"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-40631"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/udecode/plate/commit/1bc0971774fbfb770780c9bdb94746a6f0f196a0"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/udecode/plate"
  }, {
    "type" : "WEB",
    "url" : "https://stackoverflow.com/a/43467144"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-07-15T18:33:22Z",
    "nvd_published_at" : "2024-07-15T19:15:03Z"
  }
}