The vulnerability is a memory exhaustion issue in the soupsieve library, caused by parsing large comma-separated CSS selector lists. The root cause is the lack of a limit on the number of selectors that can be parsed from a single selector string. An attacker could provide a crafted, large selector string to functions like soupsieve.compile() or BeautifulSoup.select(), causing the application to allocate a large amount of memory, leading to a denial of service.
The patch addresses this by introducing a SELECTOR_LIMIT (set to 8192) in soupsieve/css_parser.py. The CSSParser class is modified to track the number of parsed selectors. The primary vulnerable function is CSSParser.parse_selectors, where the selector string is parsed. The patch adds a counter and a check within this function to ensure the number of selectors does not exceed the defined limit. Additionally, other parsing functions like CSSParser.parse_pseudo_class, CSSParser.parse_pseudo_class_custom, and CSSParser.parse_pseudo_nth were also patched to account for selectors within pseudo-classes, preventing bypasses of the main limit.