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

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). 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
    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

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.