Inefficient Algorithmic Complexity Affecting soupsieve package, versions [,4.0.1)


Severity

Recommended
0.0
medium
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.3% (24th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-PYTHON-SOUPSIEVE-22549607
  • published14 Nov 2026
  • disclosed12 Nov 2026
  • creditUnknown

Introduced: 12 Nov 2026

NewCVE-2026-126189  (opens in a new tab)
CWE-407  (opens in a new tab)

How to fix?

Upgrade soupsieve to version 4.0.1 or higher.

Overview

Affected versions of this package are vulnerable to Inefficient Algorithmic Complexity via the :has() CSS pseudo-class selector in css_match.py, which causes quadratic-time matching when processing deeply nested or wide HTML/XML documents. When :has() is used with a descendant relative selector (e.g. div:has(p)), the library repeatedly searches each candidate element's entire subtree without reusing results, producing O(n²) time complexity relative to nesting depth. When :has() appears on the parent side of a child combinator (e.g. div:has(> p) > span), the parent is re-evaluated once per child rather than once total, producing O(n²) time complexity relative to the number of children. An attacker who controls the parsed HTML or XML can send a small document that occupies a worker for seconds to minutes.

Note: This is only exploitable when selectors are run against attacker-controlled documents. Selectors compiled with the NOCACHE flag continue to use the old uncached behavior and remain vulnerable even after upgrading.

Workaround

If upgrading is not possible: avoid using :has() with a descendant relative selector or on the parent side of a child combinator against untrusted documents; use the ignore pseudo-class to ignore :has; limit the size, nesting depth, and number of children per element of untrusted documents before selecting on them; or run selection on untrusted input with a time limit in a worker process that can be stopped.

PoC

import time
import bs4
import soupsieve as sv

cases = [
    ('<div>' * 8000, 'div:has(p)'),
    ('<div>' + '<span></span>' * 5000 + '</div>', 'div:has(> p) > span'),
]
for markup, selector in cases:
    soup = bs4.BeautifulSoup(markup, 'html.parser')
    t = time.process_time()
    sv.select(selector, soup)
    print(selector, time.process_time() - t)

On affected versions, doubling the nesting depth (first case) or the number of children (second case) roughly quadruples the time.

Note: The PoC uses bs4 and soupsieve with the html.parser backend and states no specific versions or operating system.

CVSS Base Scores

version 4.0
version 3.1