CVE-2026-71491
sqlparse: Quadratic CPU usage when parsing comment-only statements.
- CVSS 8.7
- 400
- Resource Management
- Remote
sqlparse is a non-validating SQL parser module for Python. Prior to 0.6.0, group_comments in sqlparse/engine/grouping.py repeatedly rescans comment-only statements before the MAX_GROUPING_TOKENS guard, causing quadratic CPU consumption through sqlparse.parse() and sqlparse.format(sql, strip_comments=True). This issue is fixed in version 0.6.0.
- CWE
- 400
- CVSS base score
- 8.7
- Published
- 2026-08-17
- OWASP
- A04 Insecure Design
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Resource Management
- Subcategory
- Resource Exhaustion
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- sqlparse
- Fixed by upgrading
- Yes
Solution
Upgrade sqlparse to version 0.6.0 or later.
Vulnerable code sample
from sqlparse.sql import Comment
def group_comments(tlist):
"""Group comments."""
# VULNERABLE: For each comment, this rescans backwards to find an adjacent
# comment, causing quadratic runtime on inputs with many comments.
for token in tlist.tokens:
if not token.is_comment:
continue
idx = tlist.token_index(token)
prev_ = tlist.token_prev(idx, skip_ws=True)
if prev_ and prev_.is_comment:
group = tlist.group_tokens(Comment,
tlist.token_index(prev_),
idx + 1)
if group:
group_comments(group)Patched code sample
from sqlparse.sql import Comment
def group_tokens(tlist, start_idx, end_idx):
"""Group tokens from start_idx to end_idx."""
group_end_idx = end_idx
for i in range(end_idx - 1, start_idx - 1, -1):
if tlist.tokens[i].is_whitespace:
group_end_idx -= 1
else:
break
return tlist.group_tokens(Comment, start_idx, group_end_idx)
def group_comments(tlist):
"""Group comments."""
# FIX: Use a single linear pass to group adjacent comments, which avoids
# quadratic runtime.
start_idx = None
for i, token in enumerate(tlist.tokens):
if start_idx is None and token.is_comment:
start_idx = i
elif start_idx is not None:
if not (token.is_comment or token.is_whitespace):
group_tokens(tlist, start_idx, i)
start_idx = None
if start_idx is not None:
group_tokens(tlist, start_idx, len(tlist.tokens))Payload
__VAITP_MODEL_REFUSED__
Cite this entry
@misc{vaitp:cve202671491,
title = {{sqlparse: Quadratic CPU usage when parsing comment-only statements.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-71491},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-71491/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
