CVE-2026-59893
### Summary sqlparse contains a Regular Expression Denial of Service (ReDoS) vulnerability in its dollar-quoted SQL literal lexer. The regex pattern at `sqlparse/keywords.py:33` uses a backreference (`\1`) to match closing dollar-quote delimiters, causing O(n²) CPU complexity when processing inputs containing many unique, unmatched dollar-quote opening sequences. An attacker who can supply arbitrary SQL text to any application using sqlparse can trigger sustained CPU exhaustion, resulting in a denial of service. No authentication or special privileges are required. **Scope note:** the same regex shape — a lazy dot-all quantifier terminated by a delimiter, applied at every input position by the lexer loop — is also present in the two multiline-comment patterns. Those are covered by this advisory and by the same fix; see "Additional affected pattern: multiline comments" below. ### Details The vulnerable regex is defined in `sqlparse/keywords.py` as part of `SQL_REGEX`: ```python # sqlparse/keywords.py:33 (r'((?<![\w\"\$])\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal), ``` This pattern first captures a dollar-quote delimiter (e.g., `$tag$`) into group 1, then attempts to match any characters (`[\s\S]*?`) up to the same delimiter again via backreference `\1`. When no matching closing delimiter exists, the regex engine exhausts the remaining input before concluding there is no match. For a sequence of N unique unmatched openers, each opener triggers a full scan of the remaining string, yielding O(N²) total regex work. The lexer applies this regex at every character position (`sqlparse/lexer.py:136-138`): ```python # sqlparse/lexer.py:136-138 for pos, char in iterable: for rexmatch, action in self._SQL_REGEX: m = rexmatch(text, pos) ``` The data flow from public API to the vulnerable sink is: 1. `sqlparse/__init__.py:20` — `parse(sql)` accepts caller-controlled SQL. 2. `sqlparse/__init__.py:29` — delegates to `parsestream(sql, encoding)`. 3. `sql
Properties
- ghsa_id
- GHSA-prg7-hcfm-mfcr
- severity
- high
- summary
- sqlparse: Inefficient Regex Handling of Dollar-Quoted SQL Literals Leads to ReDoS (Denial of Service)
- cvss_score
- 7.5
- cve_id
- CVE-2026-59893
- cvss_vector
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
- is_ghsa_only
- false
- ghsa_published
- 2026-08-17T17:49:55Z
- source_url
- https://github.com/advisories/GHSA-prg7-hcfm-mfcr
- ghsa_updated
- 2026-08-17T17:49:55Z
Related Entities (4)
VULNERABLE_TO (1)
AFFECTS (1)
HAS_WEAKNESS (1)
REPORTED_BY (1)
Explore deeper with Ninja Signal's threat intelligence graph