CVE-2026-140010: HTML Minifier Next: Regular expressions in `minify()` cause O(n²) backtracking on ignored and custom-fragment content
HTML Minifier Next is a configurable HTML minifier and the enhanced successor to HTML Minifier. Prior to html-minifier-next 9.1.2, and from html-minifier 3.1.1 until 5.0.1, minify() in src/htmlminifier.js uses ambiguous regular expressions that can repeatedly rescan ignored or custom-fragment content. The ignoreCustomFragments whitespace-splitting variant dates to html-minifier 3.1.1, while html-minifier 5.0.0 carries both that variant and the RELASTHTMLTAG variant used for htmlmin:ignore content. With collapseWhitespace enabled, a long htmlmin:ignore block without a matching tag reaches RELASTHTMLTAG when the ignore-block placeholder and intervening text are followed by a real element; independently, a long whitespace run in a default custom fragment reaches the whitespace-splitting expression. Either form can cause quadratic regular-expression backtracking and occupy a CPU core for seconds or minutes. This issue is fixed in html-minifier-next 9.1.2 and html-minifier 5.0.1.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/html-minifier-nextto a version that resolves this vulnerability.Fixed in 9.1.2 - Upgrade
Upgrade
npm/html-minifierto a version that resolves this vulnerability.Fixed in 5.0.1
Event History
Frequently Asked Questions
Which versions need to be upgraded?
Upgrade html-minifier-next to 9.1.2 or later, or html-minifier to 5.0.1 or later. The affected html-minifier-next releases are those before 9.1.2; for html-minifier, the affected range is 3.1.1 through versions before 5.0.1.
What processing conditions trigger the excessive CPU use?
collapseWhitespace must be enabled. One trigger is a long htmlmin:ignore block without a matching tag, where the ignored-block placeholder and intervening text are followed by a real element; another is a long whitespace run in a default custom fragment.
What happens when a triggering input is minified?
The ambiguous regular expressions can perform quadratic backtracking while repeatedly rescanning content. A single minify() operation can occupy a CPU core for seconds or minutes.