CVE-2026-59894 — Vulnerability in sqlparse — CVE Details
sqlparse: Generated Python and PHP snippets allow SQL string breakout through unescaped backslashes
What Should I Do?
Address in Next Maintenance Window
Low exploitation probability (0.18%). Schedule for your next planned update.
Does your project use an affected sqlparse version?
Paste your requirements.txt to check it for CVE-2026-59894 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.
Summary
Summary
The documented Python and PHP output modes generate source-code snippets from caller-supplied SQL. Their output filters escape quote characters without first escaping existing backslashes. Crafted SQL can therefore neutralize the generated quote escape, terminate the intended language string, and place attacker-controlled code into the generated snippet. If a downstream consumer executes or imports that generated source, the injected code runs in the consumer's environment.
Details
The Python output filter places SQL in a single-quoted string and replaces each single quote with an escaped quote. The PHP output filter performs the equivalent operation for a double-quoted string. Neither transformation escapes pre-existing backslashes before escaping quotes. A backslash supplied immediately before a quote causes the generated backslash to be escaped instead of the quote, allowing the quote to close the string.
The affected modes are exposed through sqlparse.format(..., output_format='python'), sqlparse.format(..., output_format='php'), and the corresponding sqlformat -l options. Formatting produces the injected source but does not itself execute it; code execution occurs when a downstream workflow treats the generated snippet as Python or PHP code.
Relevant code locations:
sqlparse/formatter.py:193— selection of the output-language filterssqlparse/filters/output.py:45— opening of the generated Python stringsqlparse/filters/output.py:65— incomplete Python quote escapingsqlparse/filters/output.py:91— opening of the generated PHP stringsqlparse/filters/output.py:114— incomplete PHP quote escaping
PoC
A complete validated reproduction is attached as output_format_snippet_injection-poc.zip. The archive contains reproduction/ at its root, uses Git and Docker, and validates the Python output path by generating and executing a snippet containing a controlled marker-file write.
Extract the archive beside this report, then run:
./reproduction/run.sh
Observed result:
The generated Python snippet placed the attacker-controlled pathlib.Path(...).write_text(...) expression outside the intended SQL string. Executing the snippet wrote the expected proof marker, emitted EVOHUNT_OUTPUT_FORMAT_INJECTION_VERIFIED, and completed successfully.
Verification method:
The verification helper calls sqlparse.format(..., output_format='python'), executes the generated snippet, and fails unless the injected Python expression writes the exact proof marker file.
Limitations:
No reproduction blocker was recorded. The attached harness directly verifies the Python output path; exploitation also requires a downstream consumer to execute or import the generated source.
Impact
This is source-code injection in the opt-in Python and PHP snippet-generation modes. An attacker who controls SQL converted by one of these modes can inject language code into the generated artifact. If that artifact is subsequently executed, the attacker can run code with the permissions and access of the downstream Python or PHP process.
The demonstrated end-to-end result is code execution through a generated Python snippet. Formatting the SQL alone does not execute the payload, and ordinary parsing, splitting, or formatting without these output modes is not shown to be affected.
Advisory Timeline
- First published August 17, 2026 (101 days ago).
- Last revised September 10, 2026 — 23 days after initial publication.
Remediation
Upgrade to the fixed version using your package manager.
pip install "sqlparse>=0.6.0"
After upgrading, scan your dependencies again to confirm the vulnerability is resolved.
Affected Packages (1)
Affects 1 ecosystem: PyPI (1).
| Package | Fixed In |
|---|---|
| sqlparse PyPI · Affected: 0.1.0, 0.1.1, 0.1.10, 0.1.11 (+34 more) | 0.6.0 |
Vulnerability Classification
Common Weakness Enumeration (CWE) identifiers for this vulnerability type.
- CWE-94Code InjectionMITRE
CVSS Score Breakdown
What the CVSS (Common Vulnerability Scoring System) 8.5 score means for each attack dimension.
CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:H/SI:H/SA:L
References
Frequently Asked Questions
- What is CVE-2026-59894?
- sqlparse: Generated Python and PHP snippets allow SQL string breakout through unescaped backslashes. This vulnerability has been assigned a severity rating of MEDIUM (CVSS score: 8.5/10).
- How do I check if my project is affected by CVE-2026-59894?
- CVE-2026-59894 affects sqlparse. It has a 0.2% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-59894 and 200,000+ other known vulnerabilities.
Severity & Exploitability
Significant impact if exploited, or exploitable with modest effort.
This is a below-median EPSS score — only 4.6% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.
Also Known As
Related CVEs
- CVE-2024-4340HIGH
sqlparse parsing heavily nested list leads to Denial of Service
- CVE-2026-71491HIGH
sqlparse: Quadratic O(n²) DoS in group_comments
- CVE-2024-4340HIGH
sqlparse parsing heavily nested list leads to Denial of Service
- CVE-2026-71491HIGH
sqlparse: Quadratic O(n²) DoS in group_comments
- CVE-2026-59893HIGH
sqlparse: Inefficient Regex Handling of Dollar-Quoted SQL Literals Leads to ReDoS (Denial of Service)
- CVE-2026-54284HIGH
sqlparse: TokenList.__init__ materializes O(subtree) value per group, causing CPU DoS before depth/token caps trigger
- GHSA-27jp-wm6q-gp25MEDIUM
sqlparse: formatting list of tuples leads to denial of service
- CVE-2026-84305MEDIUM
sqlparse: Reindentation of tuple lists causes near-cap quadratic CPU consumption