CVE-2018-3740 is a high-severity (CVSS 7.5) Cross-site Scripting (XSS) vulnerability in sanitize. A fix is available for sanitize — see the affected versions and patch details below.
Sanitize vulnerable to Improper Input Validation and Cross-site Scripting
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
How urgent is this, really
Where this sits among everything scored
Real-World Exposure
sanitizeReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects RubyGems packages — download data is not available via public APIs for these ecosystems.
Description
When Sanitize <= 4.6.2 is used in combination with libxml2 >= 2.9.2, a specially crafted HTML fragment can cause libxml2 to generate improperly escaped output, allowing non-whitelisted attributes to be used on whitelisted elements.
This can allow HTML and JavaScript injection, which could result in XSS if Sanitize's output is served to browsers.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 💎RubyGems | sanitize | ≥ 3.0.0&&< 4.6.3 | 4.6.3bundle update sanitize --conservative |
Affected Products
sanitizesanitize_projectDetection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for sanitize, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update sanitize to 4.6.3 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2018-3740 is resolved across your whole dependency graph.
Workarounds
Escape or sanitise the affected output on the server side rather than relying on client-side filtering, and add a Content-Security-Policy that blocks inline script execution so injected markup cannot run even if it reaches the page.
Frequently Asked Questions
Is CVE-2018-3740 in your dependencies?
Find it across RubyGems, including transitive dependencies.