# CVE-2022-25887: sanitize-html Regular Expression Denial of Service

Source: https://junglewise.ai/threats/cve-2022-25887-sanitize-html-regular-expression-denial-of-service  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2022-08-31. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2022-25887 · Severity: low · CVSS 3.1 · Published 2022-08-31

sanitize-html is a popular JavaScript library used to remove malicious code from HTML content on websites and web applications. A regular expression bug in the HTML comment removal logic allows attackers to send specially crafted input that causes the library to consume excessive CPU resources, potentially slowing or crashing the affected application and denying service to legitimate users.

Technologies: [sanitize-html (npm)](https://junglewise.ai/threats/technologies/sanitize-html). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2022-25887 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2022-25887 being exploited in the wild.

**How severe is CVE-2022-25887?** Low severity, with a CVSS score of 3.1, published 31 August 2022.

**Which products and versions are affected?** sanitize-html (npm) SEMVER:introduced=0,fixed=2.7.1.

**Is there a fix for CVE-2022-25887?** Yes. sanitize-html (npm): upgrade to 2.7.1 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2022-25887 attacked?** It is attacked over the network.

**Am I affected by CVE-2022-25887?** Check whether you run sanitize-html (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- sanitize-html (npm): upgrade to 2.7.1 or later

  ```sh
  npm install sanitize-html@2.7.1
  ```


## Technical details

The vulnerability is a Regular Expression Denial of Service (ReDoS) flaw in the global regular expression replacement logic used for HTML comment removal in sanitize-html versions before 2.7.1. The vulnerable code uses a poorly constructed regex pattern that exhibits catastrophic backtracking when processing certain malformed input. An attacker can craft HTML containing nested or specially formatted comments to trigger the ReDoS condition, causing the regex engine to enter exponential time complexity. No authentication or special privileges are required; the vulnerability is triggered when untrusted HTML input is processed by the library. The fix was released in version 2.7.1 with an improved regex pattern that avoids pathological backtracking.

## Affected products

- Apostrophe CMS sanitize-html before 2.7.1

## Identifiers

- CVE-2022-25887
- GHSA-cgfm-xwp7-2cvr

## Timeline

- 2022-08-31: disclosed
- 2022-07-20: patched: Version 2.7.1 released with fix

## References

- [https://github.com/apostrophecms/sanitize-html/pull/557](https://github.com/apostrophecms/sanitize-html/pull/557)

## Related threats

- [sanitize-html incomplete : meta refresh URL scheme bypass](https://junglewise.ai/threats/cve-2026-113661-apostrophecms-incomplete-meta-http-equiv-refresh-content-still)
- [ApostropheCMS sanitize-html: SMIL animation namespace-prefix bypass allows javascript: URI injection (XSS)](https://junglewise.ai/threats/cve-2026-113657-apostrophecms-is-an-open-source-node-js-content-management)
- [sanitize-html noscript XSS bypass](https://junglewise.ai/threats/cve-2026-113654-apostrophecms-is-an-open-source-node-js-content-management)
- [sanitize-html unbounded recursion denial of service](https://junglewise.ai/threats/cve-2026-113650-apostrophecms-is-an-open-source-node-js-content-management)
- [sanitize-html stored XSS via SVG SMIL URI-list scheme bypass](https://junglewise.ai/threats/cve-2026-84371-sanitize-html-stored-xss-via-svg-smil-uri-list-scheme-bypass)
