CVE-2024-40631: @udecode/plate media Cross-Site Scripting Vulnerability
HIGHCVE-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.
CVE-2024-40631 at a Glance
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).
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.
npm install @udecode/plate-media@36.0.10
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
CVE-2024-40631 Affected @udecode/plate media Versions
1 component(s)| 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?
Which @udecode/plate media versions are affected?
What version fixes CVE-2024-40631?
Is @udecode/plate-media affected?
What is the CVSS score of CVE-2024-40631?
What CWE is associated with CVE-2024-40631?
How can I check npm dependencies for CVE-2024-40631?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"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"
}
}