CVE-2026-71491: sqlparse: Quadratic O(n²) DoS in group_comments

Published Aug 17, 2026
·
Updated

Summary A comment-only statement (-- c\nn) may cause a Denial of Service (DoS).

Details Location: sqlparse/engine/grouping.py:331-341 (groupcomments), invoked first in group() at grouping.py:439. Reachable via sqlparse.parse() and sqlparse.format(sql, stripcomments=True).

A statement made of many single-line comments ('-- c\n' repeated) lexes in O(n) but groupcomments is O(n²):

python def groupcomments(tlist): tidx, token = tlist.tokennextby(t=T.Comment) while token: eidx, end = tlist.tokennotmatching( lambda tk: imt(tk, t=T.Comment) or tk.isnewline, idx=tidx) ... tidx, token = tlist.tokennextby(t=T.Comment, idx=tidx)

The while loop runs n times and each tokennextby / tokennotmatching rescans the O(n) remaining tokens. When all tokens are comments/newlines nothing ever groups, yet the full scan is repeated per token.

Two following factors increase the severity:

1. groupcomments runs first in group() (grouping.py:439), before the groupmatching token-count guard (grouping.py:34-39). So the entire quadratic cost is paid even on oversized input. MAXGROUPINGTOKENS does not provide protection on this vector. 2. It sits on the primary sanitizer path: format(sql, stripcomments=True), used by query loggers, SQL firewalls, ORMs, and migration tools.

PoC Tested using Python 3.14:

python import time, sqlparse for n in (1000, 2000, 4000): s = "-- c\n" n t = time.perfcounter() sqlparse.format(s, stripcomments=True) print(f"n={n:5d} format(stripcomments)={1000(time.perfcounter()-t):7.1f} ms")

Output:

n= 1000 format(stripcomments)= 106.0 ms n= 2000 format(stripcomments)= 403.3 ms n= 4000 format(stripcomments)= 1602.8 ms

Time increase of ~4× per 2× input (quadratic). parse() shows the identical curve. Instrumented scan counts are exactly 1.0M / 4.0M / 16.0M tokens for n=1000/2000/4000. A ~250 KB comment-only payload forces minutes of CPU regardless of the 10000 token cap.

Impact Denial of Service

Other sources

sqlparse is a non-validating SQL parser module for Python. Prior to 0.6.0, groupcomments in sqlparse/engine/grouping.py repeatedly rescans comment-only statements before the MAXGROUPINGTOKENS guard, causing quadratic CPU consumption through sqlparse.parse() and sqlparse.format(sql, stripcomments=True). This issue is fixed in version 0.6.0.

— MITRE

Affected Software

3 affected componentsFixes available
pypi/sqlparse<0.6.0
pip/sqlparse<=0.5.5
0.6.0
debian/sqlparse<=0.4.2-1+deb12u1, <=0.5.3-1, <=0.5.5-2

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/sqlparse to a version that resolves this vulnerability.

    Fixed in 0.6.0
  2. Upgrade

    Upgrade sqlparse to a version that resolves this vulnerability.

    Fixed in 0.6.0

Event History

Aug 17, 2026
CVE Published
via MITRE·05:16 PM
Data Sourced
via MITRE·05:16 PM
DescriptionWeakness
Advisory Published
via GitHub·05:21 PM
Data Sourced
via GitHub·05:21 PM
DescriptionWeaknessAffected Software
Data Sourced
via NVD·06:18 PM
DescriptionSeverityWeakness
Sep 23, 2026
Data Sourced
via Launchpad·07:04 PM
Description
Data Sourced
via Debian·07:05 PM
DescriptionAffected Software
Sep 24, 2026
Data Sourced
via Ubuntu·07:04 PM
RemedyDescriptionSeverityAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2026-71491?

CVE-2026-71491 is rated with a risk level of 28.

2

How do I fix CVE-2026-71491?

To fix CVE-2026-71491, upgrade sqlparse to version 0.6.0 or later.

3

What is the impact of CVE-2026-71491?

CVE-2026-71491 can lead to a Denial of Service (DoS) due to excessive CPU consumption.

4

Which versions of sqlparse are affected by CVE-2026-71491?

CVE-2026-71491 affects all sqlparse versions prior to 0.6.0.

5

What type of attack does CVE-2026-71491 represent?

CVE-2026-71491 represents a quadratic time complexity issue that can be exploited for Denial of Service.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203