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


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.54% (46th 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-22549586
  • published14 Nov 2026
  • disclosed13 Nov 2026
  • creditUnknown

Introduced: 13 Nov 2026

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

How to fix?

Upgrade soupsieve to version 4.0 or higher.

Overview

Affected versions of this package are vulnerable to Inefficient Algorithmic Complexity via the descendant combinator matching logic in css_match.py, where matching a selector containing one or more descendant combinators (a b) takes time that grows polynomially with document nesting depth. For a selector with k descendant combinators, matching against a chain of n nested elements takes O(n^(k+1)) time because ancestor walks are repeated without caching, re-evaluating the same ancestors against the same selector parts on every pass. An attacker who controls the HTML or XML passed to Soup Sieve can supply a deeply nested document of roughly 1 KB to keep a CPU busy for close to a minute against an ordinary selector such as section div div.

Note: This is only exploitable when selectors are compiled with the NOCACHE flag, or on versions prior to 4.0.0 where caching was not yet implemented. After upgrading, the NOCACHE flag disables the fix and restores polynomial-time behaviour.

Workaround

If upgrading is not possible: use child combinators (a > b) instead of descendant combinators where document structure is known; limit the size and nesting depth of untrusted documents before selecting on them; or run selection on untrusted input in a worker process with a time limit.

PoC

import time
import bs4
import soupsieve as sv

soup = bs4.BeautifulSoup('<div>' * 200, 'html.parser')
t = time.process_time()
sv.select('section div div div', soup)
print(time.process_time() - t)

On affected versions, doubling the nesting depth multiplies the time by about 2^(k+1), where k is the number of descendant combinators: about 4x for section div, 8x for section div div, and 16x for section div div div.

CVSS Base Scores

version 4.0
version 3.1