Description
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.
Published: 2026-08-17
Score: 8.7 High
EPSS: n/a
KEV: No
Impact: n/a
Action: n/a
AI Analysis

Impact

The vulnerability lies in sqlparse’s grouping logic. Prior to version 0.6.0 the function that handles comment grouping repeatedly rescanned comment‑only statements before the MAX_GROUPING_TOKENS guard, resulting in quadratic CPU consumption when parsing or formatting SQL containing comments. An attacker can exploit this by submitting crafted SQL that causes the parser to perform excessive work, exhausting CPU resources and effectively denying service. The weakness matches CWE‑400 (Uncontrolled Resource Consumption) and CWE‑407 (Improper Access Control).

Affected Systems

The affected product is the Python library sqlparse from the vendor andialbrecht. Any installation of sqlparse with an older release – 0.5.x or earlier – is vulnerable. Code that employs sqlparse.parse() or sqlparse.format(sql, strip_comments=True) on untrusted input may trigger the issue.

Risk and Exploitability

The CVSS score of 8.7 indicates high severity, while the EPSS score is not available and the vulnerability is not listed in CISA’s KEV catalog, making public exploitation risk uncertain. The attack vector is essentially any pathway that allows an attacker to supply SQL text to the library, such as a web application or a background job that processes user data. Once triggered, the flaw does not leak data or modify state, but it can consume disproportionate CPU capacity, potentially leading to application slowdown or outage. The high score and lack of mitigation controls suggest urgent attention.

Generated by OpenCVE AI on August 17, 2026 at 18:24 UTC.

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade sqlparse to version 0.6.0 or later
  • If an upgrade cannot be performed immediately, implement input size limits or sanitise SQL before parsing to avoid large comment blocks
  • As a temporary measure, disable comment processing in sqlparse.format by ensuring strip_comments=True is used only on trusted, size‑checked input

Generated by OpenCVE AI on August 17, 2026 at 18:24 UTC.

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-f2ff-p2ww-7p4p sqlparse: Quadratic O(n²) DoS in group_comments
History

Mon, 17 Aug 2026 22:30:00 +0000

Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'yes', 'Exploitation': 'none', 'Technical Impact': 'partial'}, 'version': '2.0.3'}


Mon, 17 Aug 2026 17:30:00 +0000

Type Values Removed Values Added
Description 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.
Title sqlparse: Quadratic O(n²) DoS in group_comments
Weaknesses CWE-400
CWE-407
References
Metrics cvssV4_0

{'score': 8.7, 'vector': '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'}


Subscriptions

No data.

cve-icon MITRE

Status: PUBLISHED

Assigner: GitHub_M

Published:

Updated: 2026-08-17T22:01:34.222Z

Reserved: 2026-08-06T19:56:23.725Z

Link: CVE-2026-71491

cve-icon Vulnrichment

Updated: 2026-08-17T22:00:15.893Z

cve-icon NVD

Status : Received

Published: 2026-08-17T18:18:12.120

Modified: 2026-08-17T22:17:26.670

Link: CVE-2026-71491

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

Updated: 2026-08-17T18:30:04Z

Weaknesses
  • CWE-400

    Uncontrolled Resource Consumption

  • CWE-407

    Inefficient Algorithmic Complexity