CVE-2026-104844: PostCSS: Quadratic complexity in flat selector parsing allows CPU exhaustion
Impact
. and # are not word delimiters in the tokenizer, so a flat selector such as .a.a.a... reaches splitWord() as a single word token carrying n class or id indexes. Three passes scanned those index arrays linearly for every index, making the parse O(n^2) in the number of indexes rather than in input length: uniqs(), the indices.forEach loop, and the Sass-interpolation filter. Parsing a 400 KB flat selector took ~34 s on a modern laptop, fully occupying a single thread. A benign selector of identical byte size parses in tens of milliseconds, so the cost is driven by the index count, not the input size. The nesting depth of such a selector is 0, so the maxNestingDepth guard added in 7.1.3 offers no protection.
Reachability is deployment dependent. Only consumers that parse untrusted, attacker-supplied selectors synchronously in a request path are exposed, for example CSS sanitizers, CSS-in-JS services and online playgrounds. Ordinary build-time use on trusted sources is not affected.
Patches
Fixed in 7.1.6. The three passes now use Set membership tests, making parsing linear in the number of indexes. There is no behaviour change: parsing is byte-identical on a differential corpus of 8413 selectors.
Workarounds
Cap the size of selectors accepted from untrusted sources before parsing.
Other sources
PostCSS Selector Parser is a CSS selector parser that integrates with PostCSS but does not require it. Prior to 7.1.6, src/parser.js splitWord() can receive a flat selector as one word token carrying many class or ID indexes because period and hash characters are not tokenizer word delimiters. The uniqs() deduplication and per-index class and ID membership checks repeatedly scan the class and ID index arrays, while a separate Sass-interpolation filtering pass also performs repeated linear scanning. Together, these passes make parsing quadratic in the number of indexes and allow a crafted selector to occupy a synchronous parser thread. The maxNestingDepth guard does not mitigate the issue because the hostile selector can have zero nesting depth. Only consumers that synchronously parse untrusted selectors in an exposed request path are affected; ordinary build-time parsing of trusted sources is not affected. This issue is fixed in version 7.1.6.
— NVD
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/postcss-selector-parserto a version that resolves this vulnerability.Fixed in 7.1.6 - Upgrade
Upgrade
PostCSS Selector Parserto a version that resolves this vulnerability.Fixed in 7.1.6 - Compensating control
Cap the size of selectors accepted from untrusted sources before parsing.
Event History
Frequently Asked Questions
Which deployments are realistically exposed to this issue?
Exposure is limited to consumers that synchronously parse untrusted CSS selectors on an exposed request path. Ordinary build-time parsing of trusted sources is not affected.
What does an attacker need to supply to trigger the problem?
An attacker needs to provide a crafted flat selector containing many class or ID indexes. The selector can have zero nesting depth and can monopolize the synchronous parser thread through CPU consumption.
Does the maximum nesting-depth setting prevent exploitation?
No. The hostile selector can have zero nesting depth, so the maxNestingDepth guard does not mitigate this issue.
What version contains the fix?
The issue is fixed in postcss-selector-parser version 7.1.6. Versions prior to 7.1.6 are affected in the exposed untrusted synchronous-parsing scenario.