Snyk has a proof-of-concept or detailed explanation of how to exploit this vulnerability.
The probability is the direct output of the EPSS model, and conveys an overall sense of the threat of exploitation in the wild. The percentile measures the EPSS probability relative to all known EPSS scores. Note: This data is updated daily, relying on the latest available EPSS model version. Check out the EPSS documentation for more details.
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 applicationsUpgrade soupsieve to version 4.0.1 or higher.
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.
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.
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.