CVE-2026-71491: sqlparse Denial of Service Vulnerability
HIGHCVE-2026-71491 is a HIGH denial of service vulnerability (CWE-400: Uncontrolled Resource Consumption) affecting sqlparse libraries in the PyPI ecosystem. The issue involves quadratic o(n²) dos in group_comments. Remediation is available by upgrading affected packages to version 0.6.0.
CVE-2026-71491 at a Glance
How to Fix CVE-2026-71491
To remediate this vulnerability, upgrade all affected sqlparse dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install sqlparse>=0.6.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show sqlparse
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2026-71491, inspect your installed packages using pip:
pip show sqlparse
Analyze the terminal output to locate any version of sqlparse in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.6.0), your application is affected.
Note: The pip show sqlparse command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-400: Uncontrolled Resource Consumption, where the product does not properly control the allocation and maintenance of a limited resource. In sqlparse, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2026-71491 Affected sqlparse Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
sqlparse
|
PyPI |
< 0.6.0
|
0.6.0
|
References
Frequently Asked Questions
What is CVE-2026-71491?
Which sqlparse versions are affected?
What version fixes CVE-2026-71491?
Is sqlparse affected?
What CWE is associated with CVE-2026-71491?
How can I check PyPI dependencies for CVE-2026-71491?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-f2ff-p2ww-7p4p",
"modified" : "2026-08-17T17:21:00Z",
"published" : "2026-08-17T17:21:00Z",
"aliases" : [ "CVE-2026-71491" ],
"summary" : "sqlparse: Quadratic O(n²) DoS in group_comments",
"details" : "### Summary\nA comment-only statement (`-- c\\n`*n) may cause a Denial of Service (DoS).\n\n### Details\nLocation: [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)`.\n\nA statement made of many single-line comments (`'-- c\\n'` repeated) lexes in O(n) but `group_comments` is O(n²):\n\n```python\ndef group_comments(tlist):\n tidx, token = tlist.token_next_by(t=T.Comment)\n while token:\n eidx, end = tlist.token_not_matching(\n lambda tk: imt(tk, t=T.Comment) or tk.is_newline, idx=tidx)\n ...\n tidx, token = tlist.token_next_by(t=T.Comment, idx=tidx)\n```\n\nThe `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.\n\nTwo following factors increase the severity:\n\n1. `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.\n2. It sits on the primary sanitizer path: `format(sql, strip_comments=True)`, used by query loggers, SQL firewalls, ORMs, and migration tools.\n\n### PoC\nTested using Python 3.14:\n\n```python\nimport time, sqlparse\nfor n in (1000, 2000, 4000):\n s = \"-- c\\n\" * n\n t = time.perf_counter()\n sqlparse.format(s, strip_comments=True)\n print(f\"n={n:5d} format(strip_comments)={1000*(time.perf_counter()-t):7.1f} ms\")\n```\n\nOutput:\n\n```\nn= 1000 format(strip_comments)= 106.0 ms\nn= 2000 format(strip_comments)= 403.3 ms\nn= 4000 format(strip_comments)= 1602.8 ms\n```\n\nTime 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.\n\n### Impact\nDenial of Service",
"severity" : [ {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "sqlparse"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.6.0"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 0.5.5"
}
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-f2ff-p2ww-7p4p"
}, {
"type" : "WEB",
"url" : "https://github.com/andialbrecht/sqlparse/commit/ef2012a5eeb491e604dea2b00d516904a3830c87"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/andialbrecht/sqlparse"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-400", "CWE-407" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2026-08-17T17:21:00Z",
"nvd_published_at" : null
}
}