GHSA-f2ff-p2ww-7p4p: Pip/sqlparse vulnerability

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

Affected Software

1 affected componentFixes available
pip/sqlparse<=0.5.5
0.6.0

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

Event History

Aug 17, 2026
Advisory Published
via GitHub·05:21 PM
Data Sourced
via GitHub·05:21 PM
DescriptionWeaknessAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of GHSA-f2ff-p2ww-7p4p?

The severity of GHSA-f2ff-p2ww-7p4p is categorized as risk 30.

2

What is the impact of GHSA-f2ff-p2ww-7p4p?

GHSA-f2ff-p2ww-7p4p may lead to a Denial of Service (DoS) when a comment-only statement is processed.

3

How do I fix GHSA-f2ff-p2ww-7p4p?

To fix GHSA-f2ff-p2ww-7p4p, update to the patched version of sqlparse as recommended in the official advisory.

4

Which version of sqlparse is affected by GHSA-f2ff-p2ww-7p4p?

GHSA-f2ff-p2ww-7p4p affects certain versions of sqlparse prior to the fix being applied.

5

Is GHSA-f2ff-p2ww-7p4p widely exploited?

There is currently no indication that GHSA-f2ff-p2ww-7p4p is widely exploited in the wild.

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