{"id":"GHSA-h3pq-667x-r789","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) =\u003e ({ url }),\n  ],\n});\n\nreturn (\n  \u003ciframe\n    src={embed!.url}\n    // ...\n  /\u003e\n);\n```\n\n```tsx\nconst { url } = useMediaState();\n\nreturn (\n  \u003ciframe\n    // url property used directly from useMediaState() with no sanitisation\n    src={url}\n    // ...\n  /\u003e\n);\n```\n\n\n```tsx\nconst { url } = element;\n\nreturn (\n  \u003ciframe\n    // url property used directly from element with no sanitisation\n    src={url}\n    // ...\n  /\u003e\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","aliases":["CVE-2024-40631"],"modified":"2024-07-15T21:38:09Z","published":"2024-07-15T18:33:22Z","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"},"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"}],"affected":[{"package":{"name":"@udecode/plate-media","ecosystem":"npm","purl":"pkg:npm/%40udecode/plate-media"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"36.0.10"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/07/GHSA-h3pq-667x-r789/GHSA-h3pq-667x-r789.json"}}],"schema_version":"1.9.0","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"}]}