CVE-2026-85999: Soup Sieve Denial of Service Vulnerability
MODERATECVE-2026-85999 is a MODERATE (CVSS 5.3) denial of service vulnerability (CWE-400: Uncontrolled Resource Consumption) affecting Soup Sieve libraries in the PyPI ecosystem. The issue involves polynomial-time redos (o(n²)) in the whitespace/comment trimming regex `re_ws_end` (triggers on valid selectors). Remediation is available by upgrading affected packages to version 2.9.0.
CVE-2026-85999 at a Glance
Security Impact
CVSS: 5.3
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L).
How to Fix CVE-2026-85999
To remediate this vulnerability, upgrade all affected Soup Sieve dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install soupsieve>=2.9.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show soupsieve
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2026-85999, inspect your installed packages using pip:
pip show soupsieve
Analyze the terminal output to locate any version of Soup Sieve in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.9.0), your application is affected.
Note: The pip show soupsieve command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-400: Uncontrolled Resource Consumption, where the product does not properly control the allocation and maintenance of a limited resource. In Soup Sieve, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2026-85999 Affected Soup Sieve Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
soupsieve
|
PyPI |
< 2.9.0
|
2.9.0
|
References
Frequently Asked Questions
What is CVE-2026-85999?
Which Soup Sieve versions are affected?
What version fixes CVE-2026-85999?
Is soupsieve affected?
What is the CVSS score of CVE-2026-85999?
What CWE is associated with CVE-2026-85999?
How can I check PyPI dependencies for CVE-2026-85999?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-j934-xhv5-fg8f",
"modified" : "2026-09-17T20:32:53Z",
"published" : "2026-09-17T20:32:53Z",
"aliases" : [ "CVE-2026-85999" ],
"summary" : "Soup Sieve: Polynomial-time ReDoS (O(n²)) in the whitespace/comment trimming regex `RE_WS_END` (triggers on VALID selectors)",
"details" : "## Summary\n\nBefore tokenizing, `selector_iter` trims leading/trailing whitespace and comments by running two regexes over the whole raw selector with `.search()`. The trailing one, `RE_WS_END = re.compile(r'{WSC}*$')`, is anchored only at the end (`$`), not the start. Because `.search()` retries the pattern at every offset, a long run of whitespace or CSS comments that is not sitting exactly at the end of the string makes each retry greedily consume the run and then fail `$`, producing O(n²) time. This triggers on perfectly valid selectors — e.g. a descendant combinator with a long whitespace gap, `a` + `\" \"*n` + `b` — so no malformed input is required. A single valid ~20 KB selector stalls the interpreter for ~10 s of CPU.\n\n## Trust model (Q0)\n\nThe selector string is the input, reaching this code via `soupsieve.compile()`, the `soupsieve.select/iselect/match/filter` helpers, and BeautifulSoup's `soup.select(selector)` / `soup.select_one(selector)`. Exploitable wherever an application passes a user-controlled CSS selector to BeautifulSoup/soupsieve. Applications using only hard-coded selectors are unaffected.\n\n## Root cause (exact anchors) — `src/soupsieve/css_parser.py`\n\n```python\n# line 185-186\nRE_WS_BEGIN = re.compile(fr'^{WSC}*') # anchored at start -> .search() only tries pos 0 -> linear (safe)\nRE_WS_END = re.compile(fr'{WSC}*$') # NOT anchored at start -> .search() tries every offset\n\n# selector_iter, lines ~1322-1326\nm = RE_WS_BEGIN.search(pattern)\nindex = m.end(0) if m else 0\nm = RE_WS_END.search(pattern) # <-- O(n^2) here\nend = (m.start(0) - 1) if m else (len(pattern) - 1)\n```\n\n`WSC = (?:{WS}|{COMMENTS})`. For `RE_WS_END = (?:WS|COMMENTS)*$`, `.search()` walks start offsets 0..n. Whenever the offset lands inside a long whitespace/comment run, `(?:WS|COMMENTS)*` greedily consumes to the run's end, then `$` fails (a non-whitespace char follows), the engine backtracks the whole run, the offset advances by one, and the work repeats — O(n) offsets × O(n) per attempt = O(n²). `RE_WS_BEGIN` avoids this because `^` pins it to a single start offset.\n\nThe intent (trim trailing whitespace/comments) can be met with an anchored/loopless approach; the current unanchored `.search()` of a `*$` pattern is the defect.\n\n## Reproduction environment (discipline #12 — published artifact)\n\n- git HEAD `751c57b` (2.9, `PYTHONPATH=src`): `cd src && python3 ../poc/poc_redos_ws_trim.py`.\n- Published PyPI `soupsieve 2.8.4` (fresh `uv pip install soupsieve beautifulsoup4`): `cd poc && ../.venv-published/bin/python poc_redos_ws_trim.py` → same O(n²) (evidence: `poc/evidence_redos_ws_trim_PUBLISHED_2.8.4.log`).\n- Python 3.11.15 and 3.14.6 both reproduce.\n\n## PoC (`poc/poc_redos_ws_trim.py`)\n\n```python\nimport sys, time\nsys.path.insert(0, \".\")\nimport soupsieve as sv\n\ndef ct(sel):\n t0 = time.perf_counter()\n try:\n sv.compile(sel); st = \"ok\"\n except Exception as e:\n st = type(e).__name__\n return time.perf_counter() - t0, st\n\nprint(f\"soupsieve {sv.__version__}\\n\")\n\nprint(\"VALID selector 'a' + ' '*n + 'b' (descendant combinator, lots of whitespace):\")\nfor n in (2000, 4000, 8000, 16000):\n dt, st = ct(\"a\" + \" \" * n + \"b\")\n print(f\" n={n:<6} len={n+2:<7} {dt*1000:9.1f} ms [{st}]\")\n\npayload = \"a\" + \" \" * 20000 + \"b\"\ndt, st = ct(payload)\nprint(f\"\\n[+] Single call: compile('a' + ' '*20000 + 'b') (len={len(payload)})\")\nprint(f\"[+] wall time = {dt:.2f} s [{st}]\")\n```\n\nIsolated confirmation that the cost is in `RE_WS_END.search` specifically (`poc/isolate_ws_trim.py`): `RE_WS_END` on `\"div\"+\" \"*n+\">\"` is O(n²) (2000→100 ms, 4000→448 ms, 8000→1622 ms, 16000→6719 ms), while the start-anchored `RE_WS_BEGIN` on `\" \"*n+\"x\"` stays linear (32000→1.5 ms). Profiling `compile` shows the entire wall time in 2 `re.Pattern.search` calls, not `.match`.\n\n## Evidence — HEAD 2.9 (verbatim `poc/evidence_redos_ws_trim.log`)\n\n```\nsoupsieve 2.9\n\nVALID selector 'a' + ' '*n + 'b' (descendant combinator, lots of whitespace):\n n=2000 len=2002 112.3 ms [ok]\n n=4000 len=4002 411.5 ms [ok]\n n=8000 len=8002 1602.9 ms [ok]\n n=16000 len=16002 6464.1 ms [ok]\n\nVALID-looking 'a' + '/*x*/'*n + 'b' (CSS comment run):\n n=1000 len=5002 48.9 ms [SelectorSyntaxError]\n n=2000 len=10002 194.8 ms [SelectorSyntaxError]\n n=4000 len=20002 780.2 ms [SelectorSyntaxError]\n n=8000 len=40002 3145.3 ms [SelectorSyntaxError]\n\n[+] Single call: compile('a' + ' '*20000 + 'b') (len=20002)\n[+] wall time = 10.23 s [ok]\n```\n\n## Evidence — published 2.8.4 (verbatim `poc/evidence_redos_ws_trim_PUBLISHED_2.8.4.log`)\n\n```\nsoupsieve 2.8.4\n\nVALID selector 'a' + ' '*n + 'b':\n n=2000 len=2002 102.7 ms [ok]\n n=4000 len=4002 404.3 ms [ok]\n n=8000 len=8002 1618.2 ms [ok]\n n=16000 len=16002 6457.9 ms [ok]\n[+] Single call: compile('a' + ' '*20000 + 'b') wall time = 10.11 s [ok]\n```\n\n## Impact — calibrated\n\n- Confirmed: quadratic CPU per `compile()`/`select()` call on an attacker-controlled selector, triggered by a long internal whitespace or CSS-comment run. ~8 KB → ~1.6 s; ~20 KB → ~10 s; scaling ~×4 per input doubling. Notably fires on WELL-FORMED selectors, so it does not depend on a parser error path.\n- Realistic exposure: services that accept user-supplied CSS selectors and feed them to BeautifulSoup/soupsieve.\n- NOT claimed: exponential blowup, memory corruption, or code execution. Availability (DoS) only, and only where selectors are attacker-influenced.\n\n## Distinction from the IDENTIFIER/VALUE ReDoS\n\nThis is a separate root cause and a separate fix: the cost here is entirely in the `RE_WS_END = {WSC}*$` trim step run with `.search()` before tokenizing (measured in `re.Pattern.search`), whereas the IDENTIFIER/VALUE issue is adjacent-quantifier backtracking during token `.match()`. They can be fixed independently.\n\n## Remediation\n\n- Anchor or de-loop the trailing-trim step: instead of `.search()` of `{WSC}*$`, scan trailing whitespace/comments from the end directly (e.g. reverse scan, or `re.compile(r'^{WSC}*').match` on a reversed-equivalent), so no per-offset retry occurs.\n- Alternatively strip whitespace/comments in a single forward tokenizing pass rather than with a pre-pass `*$` search.\n- Defense-in-depth: cap selector length before compiling.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "soupsieve"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.9.0"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/facelessuser/soupsieve/security/advisories/GHSA-j934-xhv5-fg8f"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-85999"
}, {
"type" : "WEB",
"url" : "https://github.com/facelessuser/soupsieve/commit/cf198fcddc9230f06ed39f974eba0ce076b85cda"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/facelessuser/soupsieve"
}, {
"type" : "WEB",
"url" : "https://github.com/facelessuser/soupsieve/releases/tag/2.9"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-1333", "CWE-400" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2026-09-17T20:32:53Z",
"nvd_published_at" : "2026-09-17T16:18:16Z"
}
}