Skip to content

Plate allows arbitrary DOM attributes in element.attributes and leaf.attributes

High severity GitHub Reviewed Published Sep 20, 2024 in udecode/plate • Updated Sep 20, 2024

Package

npm @udecode/plate-core (npm)

Affected versions

>= 37.0.0, < 38.0.6
>= 22.0.0, < 36.5.9
< 21.5.1

Patched versions

38.0.6
36.5.9
21.5.1

Description

Impact

One longstanding feature of Plate is the ability to add custom DOM attributes to any element or leaf using the attributes property. These attributes are passed to the node component using the nodeProps prop.

Note: The attributes prop that is typically rendered alongside nodeProps is unrelated.

[{
  type: 'p',
  attributes: { 'data-my-attribute': 'This will be rendered on the paragraph element' },
  children: [{
    bold: true,
    attributes: { 'data-my-attribute': 'This will be rendered on the bold leaf element' },
    text: 'Bold text',
  }],
}]
const ParagraphElement = ({ attributes, nodeProps, children }) => (
  <p
    {...attributes}
    {...nodeProps} // Arbitrary DOM attributes are injected here
  >
    {children}
  </p>
);

const BoldLeaf = ({ attributes, nodeProps, children }) => (
  <strong
    {...attributes}
    {...nodeProps} // Arbitrary DOM attributes are injected here
  >
    {children}
  </strong>
);

It has come to our attention that this feature can be used for malicious purposes, including cross-site scripting (XSS) and information exposure (specifically, users' IP addresses and whether or not they have opened a malicious document).

Note that the risk of information exposure via attributes is only relevant to applications in which web requests to arbitrary URLs are not ordinarily allowed. Plate editors that allow users to embed images from arbitrary URLs, for example, already carry the risk of leaking users' IP addresses to third parties.

All Plate editors using an affected version of @udecode/plate-core are vulnerable to these information exposure attacks via the style attribute and other attributes that can cause web requests to be sent.

In addition, whether or not a Plate editor is vulnerable to cross-site scripting attacks using attributes depends on a number of factors. The most likely DOM attributes to be vulnerable are href and src on links and iframes respectively. Any component that spreads {...nodeProps} onto an <a> or <iframe> element and does not later override href or src will be vulnerable to XSS.

<a
  href={sanitizedHref}
  {...attributes}
  {...nodeProps} // Definitely vulnerable to XSS since `href` can be overridden
>
<a
  {...attributes}
  {...nodeProps} // Probably not vulnerable to XSS via `href`
  href={sanitizedHref}
>
<a
  {...attributes}
  {...nodeProps} // May be vulnerable to XSS via `href` if `href` is sometimes omitted from `sanitizedLinkProps`
  {...sanitizedLinkProps}
>

React does not allow passing a string to event handler props like onClick, so these are unlikely (but not impossible) to be vulnerable.

The attack surface is larger for users running older browsers, which may be vulnerable to XSS in DOM attributes that are less dangerous (although still vulnerable to information exposure) in modern browsers such as style or background.

Potential attack vectors for delivering malicious Slate content to users include:

  • Opening a malicious document stored on the server
  • Pasting a malicious Slate fragment into a document
  • Receiving malicious Slate operations on a collaborative document

Patches

In patched versions of Plate, we have disabled element.attributes and leaf.attributes for most attribute names by default, with some exceptions including target, alt, width, height, colspan and rowspan on the link, image, video, table cell and table header cell plugins.

If this is a breaking change for you, you can selectively re-enable attributes for certain plugins as follows. Please carefully research and assess the security implications of any attribute you allow, as even seemingly innocuous attributes such as style can be used maliciously.

Plate >= 37

For custom plugins, specify the list of allowed attribute names in the node.dangerouslyAllowAttributes plugin configuration option.

const ImagePlugin = createPlatePlugin({
  key: 'image',
  node: {
    isElement: true,
    isVoid: true,
    dangerouslyAllowAttributes: ['alt'],
  },
});

To modify an existing plugin, use the extend method.

const MyImagePlugin = ImagePlugin.extend({
  node: {
    dangerouslyAllowAttributes: ['alt'],
  },
});

Plate < 37

Note that the patch has been backported to versions @udecode/plate-core@21.5.1 and @udecode/plate-core@36.5.9 only.

For custom plugins, specify the list of allowed attribute names in the dangerouslyAllowAttributes plugin configuration option.

const createImagePlugin = createPluginFactory({
  key: 'image',
  isElement: true,
  isVoid: true,
  dangerouslyAllowAttributes: ['alt'],
});

To modify an existing plugin, pass dangerouslyAllowAttributes to the plugin factory.

createImagePlugin({
  dangerouslyAllowAttributes: ['alt'],
});

Workarounds

If you are unable to upgrade to any of the patched versions, you should use a tool like patch-package or yarn patch to remove the logic from @udecode/plate-core that adds attributes to nodeProps.

This logic can be found in the getRenderNodeProps function and looks something like this. The entire if statment can safely be removed.

  if (!newProps.nodeProps && attributes) {
    newProps.nodeProps = attributes;
  }

After applying the patch, be sure to test its effectiveness by rendering a Slate value containing an attributes property on some element.

[{
  type: 'p',
  attributes: { 'data-vulnerable': true },
  children: [{ text: 'My paragraph' }],
}]

If the patch was successful, the data-vulnerable="true" attribute should not be present on any DOM element when the Plate editor is rendered in the browser.

References

@12joan 12joan published to udecode/plate Sep 20, 2024
Published to the GitHub Advisory Database Sep 20, 2024
Reviewed Sep 20, 2024
Published by the National Vulnerability Database Sep 20, 2024
Last updated Sep 20, 2024

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 v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements None
Privileges Required Low
User interaction None
Vulnerable System Impact Metrics
Confidentiality High
Integrity High
Availability Low
Subsequent System Impact Metrics
Confidentiality None
Integrity None
Availability None

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:L/SC:N/SI:N/SA:N

EPSS score

0.045%
(17th percentile)

Weaknesses

CVE ID

CVE-2024-47061

GHSA ID

GHSA-73rg-f94j-xvhx

Source code

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.