Uncontrolled Recursion Affecting soupsieve package, versions [0.4,3.0)


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.31% (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 Learn

Learn about Uncontrolled Recursion vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-PYTHON-SOUPSIEVE-22549585
  • published14 Nov 2026
  • disclosed13 Nov 2026
  • creditzx, Daniel Coles

Introduced: 13 Nov 2026

NewCVE-2026-126193  (opens in a new tab)
CWE-674  (opens in a new tab)

How to fix?

Upgrade soupsieve to version 3.0 or higher.

Overview

Affected versions of this package are vulnerable to Uncontrolled Recursion via parse_pseudo_open in soupsieve/css_parser.py, which calls back into parse_selectors for each level of nested pseudo-class selector (:is(), :not(), :where(), :has()) without any recursion depth limit. An attacker who can supply a CSS selector string to soupsieve.compile(), soupsieve.select(), or Beautiful Soup's soup.select() / soup.select_one() can exhaust the Python call stack with roughly 330 levels of nesting (about 1.6 KB of input), raising an uncontrolled RecursionError. The existing SELECTOR_LIMIT token guard reaches only about 330 at the failing depth versus its ceiling of 8192, so it never fires. Because RecursionError is outside the parser's documented error contract of ValueError / SelectorSyntaxError, applications that catch only those exceptions experience an unexpected per-request failure.

Note: This is only exploitable when the application passes attacker-controlled CSS selector strings to the parser.

PoC

Requires only an installed Soup Sieve (any release from 0.4 through 2.10) and a default CPython recursion limit of 1000. No Beautiful Soup document or network setup is needed.

import soupsieve as sv

~330 levels of nested :is() around a single tag: about 1.6 KB of input.

depth = 330 selector = ":is(" * depth + "a" + ")" * depth print("selector length:", len(selector)) sv.compile(selector)

selector length: 1651
Traceback (most recent call last):
  ...
  File ".../soupsieve/css_parser.py", line 985, in parse_pseudo_open
    sel.selectors.append(self.parse_selectors(iselector, index, flags))
RecursionError: maximum recursion depth exceeded

The same failure was reproduced with :not(), :where(), and :has(), and through BeautifulSoup(...).select(selector). A negative control at depth 100 compiles successfully with a token count of 101, confirming the token guard is far from firing.

Note: Requires only an installed Soup Sieve and a default CPython recursion limit of 1000, with no Beautiful Soup document or network setup needed.

CVSS Base Scores

version 4.0
version 3.1