CVE-2026-104844: PostCSS: Quadratic complexity in flat selector parsing allows CPU exhaustion
Medium CVSS 5.9
- OSV id
- GHSA-rj75-hqrm-r3gf
- Also known as
- CVE-2026-104844
- Published
- Last modified
Affected packages
| Package | Affected versions | Fixed in |
|---|---|---|
| postcss-selector-parser npm |
>= 7.0.0, < 7.1.6 | 7.1.6 |
| postcss-selector-parser npm |
< 6.1.5 | 6.1.5 |
Versions we track that it affects: postcss-selector-parser 6.1.0, postcss-selector-parser 6.0.10; postcss-selector-parser 6.1.0, postcss-selector-parser 6.0.10
How to fix it
postcss-selector-parser (npm)
Upgrade postcss-selector-parser to 7.1.6 or later.
npm install postcss-selector-parser@7.1.6
# if it is an indirect dependency: npm update postcss-selector-parser (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
postcss-selector-parser (npm)
Upgrade postcss-selector-parser to 6.1.5 or later.
npm install postcss-selector-parser@6.1.5
# if it is an indirect dependency: npm update postcss-selector-parser (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
Not sure whether your project uses an affected version? Check your lockfile below for free.
Details
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.
References
- GHSA-rj75-hqrm-r3gf on OSV.dev
- Web: https://github.com/postcss/postcss-selector-parser/security/advisories/GHSA-rj75-hqrm-r3gf
- Advisory: https://nvd.nist.gov/vuln/detail/CVE-2026-104844
- Web: https://github.com/postcss/postcss-selector-parser/pull/346
- Web: https://github.com/postcss/postcss-selector-parser/commit/62b191792df0a0bc56062e5a875bc74aae2a51cd
- Web: https://github.com/postcss/postcss-selector-parser/commit/70b0779c843462197380d25daa02d1528bf7eae5
- Package: https://github.com/postcss/postcss-selector-parser
- Web: https://github.com/postcss/postcss-selector-parser/releases/tag/6.1.5
- Web: https://github.com/postcss/postcss-selector-parser/releases/tag/7.1.6
Am I affected?
Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.
About this data
Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.