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

PackageAffected versionsFixed 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

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.

or paste its content

Needed when you paste. package.json and pyproject.toml only have version ranges: use the lockfile next to them.

Only package names and versions are checked; the file itself is not kept. We use your email to send this report and nothing else unless you tick the box above. Privacy policy.

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.