Your RSA-2048 keys break in 2030. Find every one of them before attackers do.
🐍 PyPI
Not in CISA KEV

GHSA-f2ff-p2ww-7p4p — sqlparse

Fix: andialbrecht/sqlparse@ef2012a

GHSA-f2ff-p2ww-7p4p is a Uncontrolled Resource Consumption vulnerability in sqlparse. A fix is available for sqlparse — see the affected versions and patch details below.

sqlparse: Quadratic O(n²) DoS in group_comments

Also known asCVE-2026-71491PYSEC-2026-3697
Published
Aug 17, 2026
Updated
Sep 10, 2026
Affected
1 pkg
Patched
1 / 1
Exploits
None indexed
Exploitation data as of Sep 30, 2026 · OSV.dev, NVD, FIRST.org (EPSS)

Exploitation Status

No confirmed exploitation observed yet

  • CISA assesses this as automatable — exploitation doesn’t require manual, per-target effort, which raises the odds of mass scanning and opportunistic attacks.
  • CISA’s own triage has not observed active exploitation or public proof-of-concept code for this CVE as of its last assessment.

Exploitation and automatability from CISA’s SSVC triage for GHSA-f2ff-p2ww-7p4p.

EPSS Exploitation Probability

via FIRST.org ↗
0.3%probability of exploitation in next 30 days
Lower Risk0.00%
Lower risk than most CVEs16th percentile — riskier than 16% of all scored CVEsHighest risk

Probability of exploitation in the next 30 days, from FIRST.org EPSS.

Real-World Exposure

1 pkg affected
🐍sqlparse

Real-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.

Description

Summary

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

Details

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

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

def group_comments(tlist):
    tidx, token = tlist.token_next_by(t=T.Comment)
    while token:
        eidx, end = tlist.token_not_matching(
            lambda tk: imt(tk, t=T.Comment) or tk.is_newline, idx=tidx)
        ...
        tidx, token = tlist.token_next_by(t=T.Comment, idx=tidx)

The while loop runs n times and each token_next_by / token_not_matching 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. group_comments runs first in group() (grouping.py:439), before the _group_matching token-count guard (grouping.py:34-39). So the entire quadratic cost is paid even on oversized input. MAX_GROUPING_TOKENS does not provide protection on this vector.
  2. It sits on the primary sanitizer path: format(sql, strip_comments=True), used by query loggers, SQL firewalls, ORMs, and migration tools.

PoC

Tested using Python 3.14:

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

Output:

n= 1000  format(strip_comments)=  106.0 ms
n= 2000  format(strip_comments)=  403.3 ms
n= 4000  format(strip_comments)= 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 Packages

1 total 1 fixed
EcosystemPackageVulnerable rangeFix
🐍PyPIsqlparseall versions0.6.0pip install --upgrade 'sqlparse==0.6.0'

Detection & mitigation playbook

Open-source dependency
  1. Detect

    Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for sqlparse, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.

  2. Fix

    Update sqlparse to 0.6.0 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-f2ff-p2ww-7p4p is resolved across your whole dependency graph.

  3. Workarounds

    Cap what an attacker can consume: apply request size, rate and timeout limits in front of the affected component, and run it with memory and CPU limits so exhaustion degrades one worker rather than the whole service.

Fixing This On Your OS

If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.

Red HatImportant
ProductFixed inAdvisory
Red Hat Ansible Automation Platform 2.5 for RHEL 8python3.12-sqlparse-0:0.6.0-1.el8apRHSA-2026:71114
Red Hat Ansible Automation Platform 2.6 for RHEL 10python-sqlparse-0:0.6.0-1.el10apRHSA-2026:71113
Red Hat Ansible Automation Platform 2.7 for RHEL 10python-sqlparse-0:0.6.0-1.el10apRHSA-2026:71112
Red Hat Ansible Automation Platform 2.5ansible-automation-platform-25/gateway-rhel8:1789605572RHSA-2026:71210
Red Hat Ansible Automation Platform 2.6ansible-automation-platform-26/eda-controller-rhel9:1789653608RHSA-2026:71179
Red Hat Ansible Automation Platform 2.7ansible-automation-platform-27/eda-controller-rhel9:1788917355RHSA-2026:67279
Red Hat Ansible Automation Platform 2.7ansible-automation-platform-27/hub-rhel9:1789572632RHSA-2026:71177
Red Hat Discovery 2discovery/discovery-server-rhel9:1788205779RHSA-2026:61783

Frequently Asked Questions

### Summary A comment-only statement (`-- c\n`*n) may cause a Denial of Service (DoS). ### Details Location: [sqlparse/engine/grouping.py:331-341](https://github.com/andialbrecht/sqlparse/blob/f80af6a4007f11ada847218df8c29dc859238290/sqlparse/engine/grouping.py#L332) (`group_comments`), invoked first in `group()` at `grouping.py:439`. Reachable via `sqlparse.parse()` and `sqlparse.format(sql, strip_comments=True)`. A statement made of many single-line comments (`'-- c\n'` repeated) lexes in O(n) but `group_comments` is O(n²): ```python def group_comments(tlist): tidx, token = tlist.toke
O3 Security · Impact-Aware SCA

Is GHSA-f2ff-p2ww-7p4p in your dependencies?

Find it across PyPI, including transitive dependencies.

GHSA-f2ff-p2ww-7p4p: DoS — Fixed in 0.6.0 | O3 Security