CVE-2022-25887: Vulnerability in sanitize-html Package

sanitize-html Updated 02 Oct 2025

Summary

31/08/2022
Yes i
High
7.5

CVE-2022-25887: Sanitize-html Vulnerable To REDoS Attacks. Affects sanitize-html versions < 2.7.1. Fixed in 2.7.1. How to fix ↓

Also tracked for

The same CVE-2022-25887 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

The sanitize-html package is an npm package used for sanitizing HTML input to prevent cross-site scripting (XSS) attacks. It provides a set of functions to remove potentially malicious HTML tags and attributes from user-generated content. However, versions before 2.7.1 are vulnerable to a Regular Expression Denial of Service (ReDoS) attack. This vulnerability arises from insecure global regular expression replacement logic used for HTML comment removal.

Vulnerability Detail

The vulnerability in sanitize-html allows an attacker to perform a ReDoS attack by providing specially crafted input. When the package attempts to remove HTML comments, the insecure regular expression replacement logic can be exploited to cause excessive backtracking. This can lead to a denial of service (DoS) condition, where the application becomes unresponsive or crashes. The impact of this vulnerability is high, as it can be exploited remotely without authentication, and it does not require user interaction.

How To Fix

Latest published version: 2.18.1 as of 23 Oct 2026

npm install sanitize-html@2.18.1

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

2.7.1

This is the first release that contains the fix.

npm install sanitize-html@2.7.1

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

There is no known workaround for this vulnerability. It is essential to upgrade to the fixed version of the sanitize-html package to mitigate the risk.

Conclusion

The sanitize-html package before version 2.7.1 is vulnerable to a ReDoS attack due to insecure global regular expression replacement logic. To mitigate this vulnerability, it is crucial to upgrade to version 2.7.1 or later. For further assistance or support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for sanitize-html →

Share this vulnerability

FAQ

sanitize-html is an npm package used for sanitizing HTML input to prevent cross-site scripting (XSS) attacks. It provides functions to remove potentially malicious HTML tags and attributes from user-generated content.

A Regular Expression Denial of Service (ReDoS) attack is a type of denial of service attack that exploits inefficient regular expressions. By providing specially crafted input, an attacker can cause the regular expression matching algorithm to enter into an exponential time complexity, leading to excessive backtracking and a significant impact on system performance.

If your application uses an outdated version of the sanitize-html package (before 2.7.1), it is vulnerable to a ReDoS attack. An attacker can exploit this vulnerability to cause a denial of service condition, potentially rendering your application unresponsive or crashing it.

No, authentication is not required to exploit this vulnerability. An attacker can remotely exploit this vulnerability without any authentication.

No, user interaction is not required to exploit this vulnerability. An attacker can exploit this vulnerability without any user interaction.

Related vulnerabilities

Recent vulnerabilities recorded for sanitize-html.

How To Fix

Latest published version: 2.18.1 as of 23 Oct 2026

npm install sanitize-html@2.18.1

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

2.7.1

This is the first release that contains the fix.

npm install sanitize-html@2.7.1

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback