CVE-2020-4054 — Cross-site Scripting in sanitize — CVE Details
Cross-site Scripting in Sanitize
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.
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:
iframemathnoembednoframesnoscriptplaintextscriptstylesvgxmp
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:
- Open an issue in the Sanitize repo.
- See Sanitize's security policy.
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.
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).
| Package | Fixed 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-79Cross-site Scripting (XSS)MITRE
CVSS Score Breakdown
What the CVSS (Common Vulnerability Scoring System) 7.3 score means for each attack dimension.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L
References
- https://github.com/rgrove/sanitize/security/advisories/GHSA-p4x4-rw2p-8j8mWEB
- https://nvd.nist.gov/vuln/detail/CVE-2020-4054ADVISORY
- https://github.com/rgrove/sanitize/commit/a11498de9e283cd457b35ee252983662f7452aa9WEB
- https://github.com/rgrove/sanitizePACKAGE
- https://github.com/rgrove/sanitize/releases/tag/v5.2.1WEB
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/sanitize/CVE-2020-4054.ymlWEB
- https://usn.ubuntu.com/4543-1WEB
- https://www.debian.org/security/2020/dsa-4730WEB
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
Significant impact if exploited, or exploitable with modest effort.
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
Related CVEs
- CVE-2026-126366HIGH
msgpack-ruby JRuby decoder makes uncapped header-count allocations; a 5-byte message forces multi-GiB OOM
- CVE-2018-3740HIGH
Sanitize vulnerable to Improper Input Validation and Cross-site Scripting
- CVE-2023-36823HIGH
Sanitize vulnerable to Cross-site Scripting via insufficient neutralization of `style` element content
- CVE-2026-126081HIGH
Action Pack: Possible Strong Parameters Bypass in Parameters#each_key
- CVE-2023-23627MEDIUM
Improper neutralization of `noscript` element content may allow XSS in Sanitize