CVE-2024-4340
highpriority · track · 1EPSS 0.032 · 88 %ileDEEURUUSEPSS · scored 2026-10-27
Passing a heavily nested list to sqlparse.parse() leads to a Denial of Service due to RecursionError.
cvss
Technical severity, 0–10. One row per scoring source.
base score 0–10 · higher = more severe · hover a vector to decode⚠ sources disagree · medium–high · 6.9–7.5
ssvc
A stakeholder decision — act, attend, or track — from exploitation and impact.
weaknesses
The CWE weakness classes this flaw belongs to.
affected products (57)
Products and version ranges known to be affected.
- Red Hat Enterprise Linux Update Infrastructure 4all versionscert_bundDEcpe:/o:redhat:enterprise_linux:update_infrastructure_4
advisories (3)
Vendor and ecosystem advisories describing this.
- WID-SEC-W-2024-1328Red Hat Ansible Automation Platform: Mehrere SchwachstellenDeutsch2024-06-10csaf · cert_bundDE
Ein Angreifer kann mehrere Schwachstellen in Red Hat Ansible Automation Platform ausnutzen, um beliebigen Programmcode auszuführen, einen Denial-of-Service-Zustand erzeugen, vertrauliche Informationen offenzulegen, Sicherheitsmaßnahmen zu umgehen, Dateien zu manipulieren oder Cross-Site-Scripting (XSS)-Angriffe durchzuführen.
- GHSA-2m57-hf25-phggsqlparse parsing heavily nested list leads to Denial of Service2024-04-15ghsa · osvUS
### Summary Passing a heavily nested list to sqlparse.parse() leads to a Denial of Service due to RecursionError. ### Details + PoC Running the following code will raise Maximum recursion limit exceeded exception: ```py import sqlparse sqlparse.parse('[' * 10000 + ']' * 10000) ``` We expect a traceback of RecursionError: ```py Traceback (most recent call last): File "trigger_sqlparse_nested_list.py", line 3, in <module> sqlparse.parse('[' * 10000 + ']' * 10000) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/__init__.py", line 30, in parse return tuple(parsestream(sql, encoding)) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/engine/filter_stack.py", line 36, in run stmt = grouping.group(stmt) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/engine/grouping.py", line 428, in group func(stmt) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/engine/grouping.py", line 53, in group_brackets _group_matching(tlist, sql.SquareBrackets) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/engine/grouping.py", line 48, in _group_matching tlist.group_tokens(cls, open_idx, close_idx) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 328, in group_tokens grp = grp_cls(subtokens) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 161, in __init__ super().__init__(None, str(self)) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 165, in __str__ return ''.join(token.value for token in self.flatten()) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 165, in <genexpr> return ''.join(token.value for token in self.flatten()) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 214, in flatten yield from token.flatten() File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 214, in flatten yield from token.flatten() File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 214, in flatten yield from token.flatten() [Previous line repeated 983 more times] RecursionError: maximum recursion depth exceeded ``` ### Fix suggestion The [flatten()](https://github.com/andialbrecht/sqlparse/blob/master/sqlparse/sql.py#L207) function of TokenList class should limit the recursion to a maximal depth: ```py from sqlparse.exceptions import SQLParseError MAX_DEPTH = 100 def flatten(self, depth=1): """Generator yielding ungrouped tokens. This method is recursively called for all child tokens. """ if depth >= MAX_DEPTH: raise SQLParseError('Maximal depth reached') for token in self.tokens: if token.is_group: yield from token.flatten(depth + 1) else: yield token ``` ### Impact Denial of Service (the impact depends on the use). Anyone parsing a user input with sqlparse.parse() is affected.
- PYSEC-2026-1940sqlparse parsing heavily nested list leads to Denial of Service2026-07-07vendor · osvUS
### Summary Passing a heavily nested list to sqlparse.parse() leads to a Denial of Service due to RecursionError. ### Details + PoC Running the following code will raise Maximum recursion limit exceeded exception: ```py import sqlparse sqlparse.parse('[' * 10000 + ']' * 10000) ``` We expect a traceback of RecursionError: ```py Traceback (most recent call last): File "trigger_sqlparse_nested_list.py", line 3, in <module> sqlparse.parse('[' * 10000 + ']' * 10000) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/__init__.py", line 30, in parse return tuple(parsestream(sql, encoding)) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/engine/filter_stack.py", line 36, in run stmt = grouping.group(stmt) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/engine/grouping.py", line 428, in group func(stmt) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/engine/grouping.py", line 53, in group_brackets _group_matching(tlist, sql.SquareBrackets) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/engine/grouping.py", line 48, in _group_matching tlist.group_tokens(cls, open_idx, close_idx) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 328, in group_tokens grp = grp_cls(subtokens) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 161, in __init__ super().__init__(None, str(self)) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 165, in __str__ return ''.join(token.value for token in self.flatten()) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 165, in <genexpr> return ''.join(token.value for token in self.flatten()) File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 214, in flatten yield from token.flatten() File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 214, in flatten yield from token.flatten() File "/home/uriya/.local/lib/python3.10/site-packages/sqlparse/sql.py", line 214, in flatten yield from token.flatten() [Previous line repeated 983 more times] RecursionError: maximum recursion depth exceeded ``` ### Fix suggestion The [flatten()](https://github.com/andialbrecht/sqlparse/blob/master/sqlparse/sql.py#L207) function of TokenList class should limit the recursion to a maximal depth: ```py from sqlparse.exceptions import SQLParseError MAX_DEPTH = 100 def flatten(self, depth=1): """Generator yielding ungrouped tokens. This method is recursively called for all child tokens. """ if depth >= MAX_DEPTH: raise SQLParseError('Maximal depth reached') for token in self.tokens: if token.is_group: yield from token.flatten(depth + 1) else: yield token ``` ### Impact Denial of Service (the impact depends on the use). Anyone parsing a user input with sqlparse.parse() is affected.
also known as (7)
Other names and identifiers for this entity.
sources
Which sources assert this record, and when.
references (12)
External citations — patches, advisories, analysis.
- https://cxsecurity.com/cveshow/CVE-2024-4340/cnnvd
- https://github.com/advisories/GHSA-2m57-hf25-phggcnnvd
- https://github.com/andialbrecht/sqlparse/commit/b4a39d9850969b4e1d6940d32094ee0b42a2cf03cnnvd
- https://lists.debian.org/debian-lts-announce/2024/12/msg00022.htmlcnnvd
- https://research.jfrog.com/vulnerabilities/sqlparse-stack-exhaustion-dos-jfsa-2024-001031292/cnnvd
- https://github.com/advisories/GHSA-2m57-hf25-phggenisa_euvd
- https://github.com/andialbrecht/sqlparse/commit/b4a39d9850969b4e1d6940d32094ee0b42a2cf03enisa_euvd
- https://research.jfrog.com/vulnerabilities/sqlparse-stack-exhaustion-dos-jfsa-2024-001031292/enisa_euvd
Attackers weaponise vulnerabilities like this against internet-exposed services. See what is exposed on your perimeter with a free passive scan.
Free scan