Skip to content

Cross-site Scripting in Sanitize

High severity GitHub Reviewed Published Jun 16, 2020 in rgrove/sanitize • Updated May 16, 2023

Package

bundler sanitize (RubyGems)

Affected versions

>= 3.0.0, < 5.2.1

Patched versions

5.2.1

Description

When HTML is sanitized using Sanitize's "relaxed" config or a custom config that allows certain elements, some content in a <math> or <svg> element may not be sanitized correctly even if math and svg are not in the allowlist.

You are likely to be vulnerable to this issue if you use Sanitize's relaxed config or a custom config that allows one or more of the following HTML elements:

  • iframe
  • math
  • noembed
  • noframes
  • noscript
  • plaintext
  • script
  • style
  • svg
  • xmp

Impact

Using carefully crafted input, an attacker may be able to sneak arbitrary HTML through Sanitize, potentially resulting in XSS (cross-site scripting) or other undesired behavior when that HTML is rendered in a browser.

Releases

This problem has been fixed in Sanitize 5.2.1.

Workarounds

If upgrading is not possible, a workaround is to override the default value of Sanitize's :remove_contents config option with the following value, which ensures that the contents of math and svg elements (among others) are removed entirely when those elements are not in the allowlist:

%w[iframe math noembed noframes noscript plaintext script style svg xmp]

For example, if you currently use Sanitize's relaxed config, you can create a custom config object that overrides the default value of :remove_contents like this:

custom_config = Sanitize::Config.merge(
  Sanitize::Config::RELAXED,
  :remove_contents => %w[iframe math noembed noframes noscript plaintext script style svg xmp]
)

You would then pass this custom config to Sanitize when sanitizing HTML.

For more information

If you have any questions or comments about this advisory:

Credits

Many thanks to Michal Bentkowski of Securitum for reporting this bug and helping to verify the fix.

References

References

@rgrove rgrove published to rgrove/sanitize Jun 16, 2020
Reviewed Jun 16, 2020
Published to the GitHub Advisory Database Jun 16, 2020
Last updated May 16, 2023

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
None
User interaction
None
Scope
Unchanged
Confidentiality
Low
Integrity
Low
Availability
Low

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:N/UI:N/S:U/C:L/I:L/A:L

EPSS score

0.141%
(51st percentile)

Weaknesses

CVE ID

CVE-2020-4054

GHSA ID

GHSA-p4x4-rw2p-8j8m

Source code

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