GHSA-cfqr-cjx5-5jcm: Pip/sqlparse vulnerability

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.

Affected Software

1 affected componentFixes available
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

Event History

Sep 1, 2026
Advisory Published
via GitHub·09:20 PM
Data Sourced
via GitHub·09:20 PM
DescriptionWeaknessAffected Software

Frequently Asked Questions

1

Who is exposed to this denial-of-service condition?

Applications are exposed if an attacker can control SQL that is passed through sqlparse's reindentation formatting path. The affected entry points are sqlparse.format(sql, reindent=True) and the sqlformat --reindent command.

2

Is the default formatting configuration affected?

Reindentation is opt-in. The expensive path is reached only when reindentation is enabled.

3

What input does an attacker need to supply?

The attacker needs to provide a carefully sized parenthesized tuple list that stays below the grouping-token cap. Inputs that are slightly larger may be rejected quickly by that cap instead of reaching the expensive reindentation work.

4

What can be done before a fix is deployed?

Do not enable reindentation for untrusted SQL input, or restrict access to formatting operations that use sqlparse.format with reindent=True or sqlformat --reindent. This prevents attacker-controlled input from reaching the vulnerable path.

5

How can I identify potentially affected usage?

Search application code and automation for calls to sqlparse.format with reindent=True and for uses of sqlformat --reindent. Prioritize cases where the SQL being formatted originates from users or other untrusted sources.

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