Skip to content

← Actionable
High, CVSS 8.7

sqlparse: Quadratic O(n²) DoS in group_comments

CVE-2026-71491GHSA-f2ff-p2ww-7p4p

What to do

Vendor fix available. Upgrade each affected package to the fixed version on its release line (sqlparse 0.6.0), redeploy, then verify what is actually installed.

This page has no inventory attached, so it cannot say whether you are affected. A vendor fix is not proof that your deployment is fixed.

Affected packages

  • PyPI sqlparse

    Affected
    <= 0.5.5
    Fixed in
    0.6.0

Sources

Severity and exploitation
Exploitation
No confirmed exploitation recorded. Patch Next marks exploitation only from CISA KEV.
CVSS 4.0
8.7 · 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 · score source
EPSS
  • CVE-2026-71491: 0.26% estimated exploitation activity in the next 30 days; percentile 18.18 (FIRST EPSS, 2026-11-03). This is a model estimate, not proof of exploitation or customer exposure.
Source description

As published by the source; long descriptions are shortened.

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²): 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…

Dates and revisions
Published by the source
Last modified by the source
Source last checked
  1. Revision 1 · created ·

    Published from ghsa record GHSA-f2ff-p2ww-7p4p

Agent brief

Preview the exact text before you copy it. Commands are read-only suggestions; review them before running anything.

# Patch Next advisory brief: CVE-2026-71491

Advisory: sqlparse: Quadratic O(n²) DoS in group_comments
IDs: CVE-2026-71491, GHSA-f2ff-p2ww-7p4p
Record: https://patchnext.com/advisories/cve-2026-71491 (revision 1, source checked 26 Oct 2026, 13:50 UTC)
Inventory: none attached. This brief comes from a public page and does not say whether any deployment is affected.
Severity: High (CVSS 8.7)
Exploitation: no confirmed exploitation recorded. Patch Next confirms exploitation only from CISA KEV.
Vendor response: Vendor fix available; fixed versions by package: sqlparse 0.6.0. A vendor fix does not mean a deployment is fixed.

## Affected components
- PyPI sqlparse: affected <= 0.5.5; fixed in 0.6.0

## Suggested inspection (read-only)
- `python -m pip show sqlparse`: prints the installed version. Run with the environment that serves production active.

## Supported action
Upgrade each affected component to a fixed version on its release line. For a transitive dependency, upgrade the parent package or add an override or constraint, then regenerate the lockfile. Redeploy every environment that ran an affected version.

## Required regression checks
- Run the test suite and a production build.
- Exercise the features that depend on sqlparse.
- Repeat the inspection and confirm that only fixed versions remain installed.

## Rollback considerations
- Keep the previous lockfile and deployment artifact. Rolling back reinstates the vulnerable version, so apply any documented mitigation while you fix forward.

## Unresolved questions
- Which deployments run an affected version?
- Exploitation status can change. Check again before lowering the priority.
- Mark the work resolved only after the fixed version is verified in production.

## Sources
- Verified: https://github.com/advisories/GHSA-f2ff-p2ww-7p4p (GitHub-reviewed advisory GHSA-f2ff-p2ww-7p4p lists affected ranges: PyPI sqlparse >=0 <=0.5.5)

Commands are suggestions: review each one before running it.

Loading voting…