Skip to main content

CVE-2020-4054 — Cross-site Scripting in sanitize — CVE Details

HIGH

Cross-site Scripting in Sanitize

Published June 16, 2020Updated July 8, 2026Source: OSV

What Should I Do?

Address in Next Maintenance Window

Low exploitation probability (1.92%). Schedule for your next planned update.

Does your project use an affected sanitize version?

Paste your Gemfile.lock to check it for CVE-2020-4054 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.

Check my Gemfile.lock

Summary

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

Advisory Timeline

  • First published June 16, 2020 (2355 days ago).
  • Last revised July 8, 2026 — 2212 days after initial publication.

Remediation

Upgrade to the fixed version using your package manager.

Bundler
Update sanitize to 5.2.1 or later
gem install sanitize -v 5.2.1

After upgrading, scan your dependencies again to confirm the vulnerability is resolved.

Affected Packages (1)

Affects 1 ecosystem: RubyGems (1).

PackageFixed In
sanitize RubyGems · Affected: 3.0.0, 3.0.1, 3.0.2, 3.0.3 (+21 more)5.2.1

Vulnerability Classification

Common Weakness Enumeration (CWE) identifiers for this vulnerability type.

  • CWE-79
    Cross-site Scripting (XSS)MITRE

CVSS Score Breakdown

What the CVSS (Common Vulnerability Scoring System) 7.3 score means for each attack dimension.

Attack Vector
Network
Attack Complexity
Low
Privileges Required
None
User Interaction
None
Scope
Unchanged
Confidentiality
Low
Integrity
Low
Availability
Low

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L

Frequently Asked Questions

What is CVE-2020-4054?
Cross-site Scripting in Sanitize. This vulnerability has been assigned a severity rating of HIGH (CVSS score: 7.3/10).
How do I check if my project is affected by CVE-2020-4054?
CVE-2020-4054 affects sanitize. It has a 1.9% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2020-4054 and 200,000+ other known vulnerabilities.

Severity & Exploitability

CVSS Score
7.3

Significant impact if exploited, or exploitable with modest effort.

EPSS Score (30-day exploit probability)
1.92%
EPSS percentile: 80.5

This places it in the top quartile of EPSS-scored vulnerabilities — 80.5% of tracked vulnerabilities score at or below it, so it is more likely to be exploited than most of the tracked corpus.

Also Known As

GHSA-p4x4-rw2p-8j8m

Related CVEs

  • CVE-2026-126366
    HIGH

    msgpack-ruby JRuby decoder makes uncapped header-count allocations; a 5-byte message forces multi-GiB OOM

  • CVE-2018-3740
    HIGH

    Sanitize vulnerable to Improper Input Validation and Cross-site Scripting

  • CVE-2023-36823
    HIGH

    Sanitize vulnerable to Cross-site Scripting via insufficient neutralization of `style` element content

  • CVE-2026-126081
    HIGH

    Action Pack: Possible Strong Parameters Bypass in Parameters#each_key

  • CVE-2023-23627
    MEDIUM

    Improper neutralization of `noscript` element content may allow XSS in Sanitize

Check your own dependencies

Free, with no signup for up to 10 packages.

Check my Gemfile.lock