# CVE-2026-59893: sqlparse inefficient regex handling in dollar-quoted literals

Source: https://junglewise.ai/threats/cve-2026-59893-sqlparse-inefficient-regex-handling-in-dollar-quoted-literals  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-08-17. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2026-59893 · Severity: high · CVSS 7.5 · Published 2026-08-17

sqlparse is a SQL parser library used by many Python applications to parse and format SQL queries. A flaw in its regex pattern matching allows attackers to submit specially crafted SQL text with many unmatched dollar-quote delimiters, causing the parser to consume excessive CPU resources in a quadratic time pattern. Applications that accept user-supplied SQL—such as web interfaces, database tools, or query formatters—can be forced to hang or become unresponsive, disrupting service for legitimate users without requiring authentication.

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

## Quick answers

**Is CVE-2026-59893 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2026-59893 being exploited in the wild.

**How severe is CVE-2026-59893?** High severity, with a CVSS score of 7.5, published 17 August 2026.

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

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

**How is CVE-2026-59893 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2026-59893?** 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.6.0 or later

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


## Technical details

The vulnerability is a Regular Expression Denial of Service (ReDoS) in the dollar-quoted SQL literal pattern at sqlparse/keywords.py:33. The regex uses a backreference (`\1`) to match closing delimiters: `(r'((?<![\w\"\$])\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal)`. When processing SQL with many unique, unmatched opening dollar-quote sequences (e.g., `$a0$x $a1$x $a2$x ...`), the regex engine exhausts the remaining input at each position before backtracking, resulting in O(n²) time complexity. The same issue affects multiline comment patterns (`/*` and `/*+`). The lexer applies all regex patterns at every input character position without timeout or length limits, making the flaw exploitable via any public API (`sqlparse.parse()`, `sqlparse.format()`, `sqlparse.split()`) that accepts user-controlled SQL. Empirical testing confirms 3.3× slowdown when input doubles (n=1000 → n=2000, 0.397s → 1.314s). A patch replacing the backreference approach with deterministic O(n) delimiter matching is available in version 0.6.0.

## Affected products

- andialbrecht sqlparse <= 0.5.6.dev0

## Identifiers

- CVE-2026-59893
- GHSA-prg7-hcfm-mfcr
- PYSEC-2026-3698

## Timeline

- 2026-08-13: disclosed: GitHub Security Advisory published
- 2026-08-17: patched: Fix released in sqlparse 0.6.0

## References

- [https://api.github.com/users/EQSTLab](https://api.github.com/users/EQSTLab)
- [https://github.com/EQSTLab](https://github.com/EQSTLab)
- [https://api.github.com/users/EQSTLab/gists%7B/gist_id%7D](https://api.github.com/users/EQSTLab/gists%7B/gist_id%7D)
- [https://api.github.com/users/EQSTLab/repos](https://api.github.com/users/EQSTLab/repos)
- [https://avatars.githubusercontent.com/u/148991397?v=4](https://avatars.githubusercontent.com/u/148991397?v=4)
- [https://api.github.com/users/EQSTLab/events%7B/privacy%7D](https://api.github.com/users/EQSTLab/events%7B/privacy%7D)

## 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 TokenList CPU denial of service](https://junglewise.ai/threats/cve-2026-54284-sqlparse-tokenlist-cpu-denial-of-service)
- [PYSEC-2026-1940 - sqlparse parsing heavily nested list leads to Denial of Service](https://junglewise.ai/threats/cve-2024-4340-sqlparse-denial-of-service-via-heavily-nested-list)
