Skip to content

XSS in media embed element when using custom URL parsers

High
12joan published GHSA-h3pq-667x-r789 Jul 15, 2024

Package

npm @udecode/plate-media (npm)

Affected versions

<36.0.10

Patched versions

36.0.10

Description

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

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N

CVE ID

CVE-2024-40631

Weaknesses