# sqlparse denial of service in tuple formatting

Source: https://junglewise.ai/threats/sqlparse-denial-of-service-in-tuple-formatting-e8c49585  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-02-13. Updated: 2026-09-26  
License: CC BY 4.0 with a link back

Severity: medium · CVSS 4 · Published 2026-02-13

sqlparse is a popular Python library for parsing and formatting SQL queries. The library contains a flaw that causes it to hang (stop responding) when attempting to format SQL queries containing long lists of tuples, such as those used in Django's composite primary key queries. An attacker or malicious application could exploit this to cause a denial of service by submitting specially crafted SQL queries.

Technologies: [sqlparse (PyPI)](https://junglewise.ai/threats/technologies/sqlparse). Vendors: [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is This vulnerability exploited in the wild?** No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.

**How severe is This vulnerability?** Medium severity, with a CVSS score of 4, published 13 February 2026.

**Which products and versions are affected?** sqlparse (PyPI) ECOSYSTEM:introduced=0,fixed=0.5.4.

**Is there a fix for This vulnerability?** Yes. sqlparse (PyPI): upgrade to 0.5.4 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is This vulnerability attacked?** It is attacked over the network, in a software library.

**Am I affected?** Check whether you run sqlparse (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- sqlparse (PyPI): upgrade to 0.5.4 or later

  ```sh
  pip install "sqlparse>=0.5.4"
  ```


## Technical details

A denial-of-service vulnerability exists in sqlparse's tuple formatting logic due to inefficient recursion or iteration when processing large parenthesized tuple lists (CWE-770: Allocation of Resources Without Limits or Throttling). The vulnerability is triggered when the library attempts to format SQL containing multiple nested or sequential tuples, such as "IN ((1,1), (1,2), ..., (1,N))" with many entries. The attack vector is network-based if sqlparse is used in a web application or API to format user-supplied SQL. No authentication is required. An attacker can cause the process to hang indefinitely, consuming CPU resources and preventing legitimate requests from being processed. The vulnerability was patched in version 0.5.4 by adding hard limits for grouping operations to prevent resource exhaustion.

## Affected products

- sqlparse sqlparse <=0.5.3

## Timeline

- 2026-02-13: disclosed
- 2026-02-13: patched: Fixed in version 0.5.4

## References

- [https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-27jp-wm6q-gp25](https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-27jp-wm6q-gp25)
- [https://github.com/andialbrecht/sqlparse/commit/40ed3aa958657fa4a82055927fa9de70ab903360](https://github.com/andialbrecht/sqlparse/commit/40ed3aa958657fa4a82055927fa9de70ab903360)

## Related threats

- [sqlparse quadratic CPU consumption in reindent filter](https://junglewise.ai/threats/cve-2026-84305-sqlparse-quadratic-cpu-consumption-in-reindent-filter)
- [sqlparse quadratic DoS in group_comments](https://junglewise.ai/threats/cve-2026-71491-sqlparse-quadratic-dos-in-group-comments)
- [sqlparse code injection in Python and PHP output modes](https://junglewise.ai/threats/cve-2026-59894-sqlparse-code-injection-in-python-and-php-output-modes)
- [sqlparse inefficient regex handling in dollar-quoted literals](https://junglewise.ai/threats/cve-2026-59893-sqlparse-inefficient-regex-handling-in-dollar-quoted-literals)
- [sqlparse TokenList CPU denial of service](https://junglewise.ai/threats/cve-2026-54284-sqlparse-tokenlist-cpu-denial-of-service)
