CVE-2024-40631
JSON

8.1high

Cross-site Scripting (XSS) in media embed element when using custom URL parsers in plate media

Severity
8.1high CVSS:3.1 by GitHub_M
Exploit likelihood
0.50% (higher than 44% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-h3pq-667x-r789

Description

Plate media is an open source, rich-text editor for React. 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 consume the `url` property directly may also be vulnerable if the URL is not sanitised. The default parsers `parseTwitterUrl` and `parseVideoUrl` are not affected. `@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. Users are advised to upgrade. Users unable to upgrade should 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.

Affected

Product or packageVersionsReported by
udecode plate< 36.0.10CVE List
@udecode/plate-media (npm)before 36.0.10GitHub Advisory Database

All scores

GitHub_M8.1high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N
GitHub8.1high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N
GitHubhigh CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:A/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N

Classification

CWE-79

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

Plate media is an open source, rich-text editor for React. 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 consume the `url` property directly may also be vulnerable if the URL is not sanitised. The default parsers `parseTwitterUrl` and `parseVideoUrl` are not affected. `@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. Users are advised to upgrade. Users unable to upgrade should 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.

GitHub Advisory Database
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:

const { embed } = useMediaState({
  urlParsers: [
    // Custom parser that does not use an allowlist or validate the URL protocol
    (url) => ({ url }),
  ],
});

return (
  <iframe
    src={embed!.url}
    // ...
  />
);
const { url } = useMediaState();

return (
  <iframe
    // url property used directly from useMediaState() with no sanitisation
    src={url}
    // ...
  />
);
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

NVD (es)

Plate media es un editor de texto enriquecido de código abierto para React. Los editores que usan `MediaEmbedElement` y pasan `urlParsers` personalizados al enlace `useMediaState` pueden ser vulnerables a XSS si un analizador personalizado permite incrustar URL `javascript:`, `data:` o `vbscript:`. Los editores que no utilizan `urlParsers` y consumen la propiedad `url` directamente también pueden ser vulnerables si la URL no está sanitizada. Los analizadores predeterminados `parseTwitterUrl` y `parseVideoUrl` no se ven afectados. `@udecode/plate-media` 36.0.10 resuelve este problema al permitir solo URL HTTP y HTTPS durante el análisis. Esto afecta sólo a la propiedad `embed` devuelta por `useMediaState`. Además, se cambió el nombre de la propiedad `url` devuelta por `useMediaState` a `unsafeUrl` para indicar que no se ha sanitizado. La propiedad `url` en `element` tampoco es segura, pero no se le ha cambiado el nombre. Si utiliza cualquiera de estas propiedades directamente, aún deberá validar la URL usted mismo. Se recomienda a los usuarios que actualicen. Los usuarios que no puedan actualizar deben asegurarse de que los `urlParsers` personalizados no permitan que las URL `javascript:`, `data:` o `vbscript:` se devuelvan en la propiedad `url` de sus valores de retorno. Si `url` se consume directamente, valide el protocolo de URL antes de pasarlo al elemento `iframe`.

References

Sources

SourceRecordLicence
CVE ListCVE-2024-40631 changed 2024-08-02CVE Terms of Use
GitHub Advisory DatabaseGHSA-h3pq-667x-r789 changed 2026-09-10CC-BY-4.0
NVDCVE-2024-40631 changed 2026-06-17Public domain