CVE-2026-84305: sqlparse: Reindentation of tuple lists causes near-cap quadratic CPU consumption

Published Sep 1, 2026
·
Updated

Summary

When SQL is formatted with reindentation enabled, ReindentFilter repeatedly rebuilds prefixes of the current statement to calculate token offsets. An attacker who controls SQL sent to this opt-in formatting path can supply a parenthesized tuple list that remains just below the grouping-token cap. Thousands of offset calculations then traverse an expanding token tree, causing multi-second CPU consumption from an input of roughly 16 KB and degrading service availability.

Details

ReindentFilter.getoffset() joins the tokens returned by flattenuptotoken() to calculate the current output position. Each call begins by flattening the current statement from its start and walks until the target token. Tuple-list reindentation invokes this calculation repeatedly as it processes many parenthesized values, so later calls redo an increasingly large amount of prior work.

The vulnerable path is reached through sqlparse.format(sql, reindent=True) and sqlformat --reindent. A carefully sized tuple list completes grouping below the configured token cap and then enters the expensive reindentation path; a slightly larger input may instead be rejected quickly by the cap.

Relevant code locations:

- sqlparse/formatter.py:170 — enabling ReindentFilter - sqlparse/filters/reindent.py:30 — repeated flattening from the statement start - sqlparse/filters/reindent.py:44 — prefix joining for offset calculation - sqlparse/filters/reindent.py:216 — tuple-list processing path

PoC

A complete validated reproduction is attached as reindenttuplelistcpudos-poc.zip. The archive contains reproduction/ at its root, uses Git and Docker, and compares two same-shape tuple-list inputs formatted with reindentation enabled.

Extract the archive beside this report, then run:

console ./reproduction/run.sh

Observed result:

The 600-tuple baseline completed in 0.649 seconds, while the below-cap 1,425-tuple input completed in 4.999 seconds. The run emitted EVOHUNTREINDENTDOSVERIFIED and completed successfully.

Verification method:

The verification helper formats two same-shape tuple-list payloads with reindent=True and fails unless the larger payload completes successfully, takes at least 2.0 seconds, and takes at least 4x the baseline.

Limitations:

No reproduction blocker was recorded. Timing varies by host, and exploitation requires the reindentation option or corresponding CLI mode to be enabled.

Impact

This is a CPU resource-exhaustion vulnerability in workflows that reindent attacker-controlled SQL. A small crafted tuple-list input can occupy a worker for several seconds, enabling request delays, reduced throughput, or worker starvation when payloads are processed repeatedly or concurrently.

The affected reindentation behavior is opt-in, and sqlparse itself does not provide network exposure; reachability depends on the consuming application or CLI workflow. The demonstrated effect is CPU consumption in a single formatting call, not process termination, code execution, or confidentiality or integrity impact.

Other sources

sqlparse is a non-validating SQL parser module for Python. Prior to 0.6.0, sqlparse.format(sql, reindent=True) and sqlformat --reindent route attacker-controlled parenthesized tuple lists through ReindentFilter.getoffset() in sqlparse/filters/reindent.py, where flattenuptotoken() repeatedly rebuilds and joins the statement prefix. Thousands of offset calculations walk an expanding token tree, producing quadratic CPU consumption for inputs that remain below MAXGROUPINGTOKENS and causing request delays, reduced throughput, or worker starvation. This issue is fixed in version 0.6.0.

— MITRE

Affected Software

2 affected componentsFixes available
pypi/sqlparse<0.6.0
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
  2. Upgrade

    Upgrade sqlparse to a version that resolves this vulnerability.

    Fixed in 0.6.0

Event History

Sep 1, 2026
CVE Published
via MITRE·06:33 PM
Data Sourced
via MITRE·06:33 PM
DescriptionWeakness
Data Sourced
via NVD·07:17 PM
DescriptionSeverityWeakness
Advisory Published
via GitHub·09:20 PM
Data Sourced
via GitHub·09:20 PM
DescriptionWeaknessAffected Software

Frequently Asked Questions

1

Who is realistically exposed to this issue?

Applications that use sqlparse to format attacker-controlled SQL with sqlparse.format(sql, reindent=True), or expose the sqlformat command with the --reindent option, are exposed. The impact is CPU exhaustion that can delay requests, reduce throughput, or starve workers.

2

What input or access does an attacker need?

An attacker needs to supply SQL that reaches reindentation and contains parenthesized tuple lists engineered to trigger many offset calculations. The described inputs can remain below MAX_GROUPING_TOKENS.

3

Are default sqlparse parsing operations affected?

The issue is specifically described in the reindentation paths: sqlparse.format(sql, reindent=True) and sqlformat --reindent. The provided information does not identify other parsing or formatting configurations as affected.

4

What should be done if upgrading cannot happen immediately?

Avoid applying reindentation to attacker-controlled SQL by disabling reindent=True and not exposing sqlformat --reindent to untrusted input. Upgrade to sqlparse 0.6.0 when possible.

5

How can teams determine whether they may already be affected?

Review application code and operational tooling for sqlparse.format calls that set reindent=True and for sqlformat invocations using --reindent on untrusted SQL. Review performance incidents for high CPU, request delays, reduced throughput, or worker starvation associated with formatting inputs containing large parenthesized tuple lists.

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