mediumVulnerability

CVE-2026-59894

### 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 filters - `sqlparse/filters/output.py:45` — opening of the generated Python string - `sqlparse/filters/output.py:65` — incomplete Python quote escaping - `sqlparse/filters/output.py:91` — opening of the generated PHP string - `sqlparse/filters/output.py:114` — incomplete PHP quote escaping ### PoC A complete validated reproduction is attached as [output_format_snippet_injection-poc.zip](https://github.com/user-attachments/files/29410134/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 exec

Properties

ghsa_id
GHSA-3496-9g83-7v6x
severity
medium
summary
sqlparse: Generated Python and PHP snippets allow SQL string breakout through unescaped backslashes
cve_id
CVE-2026-59894
is_ghsa_only
false
ghsa_published
2026-08-17T17:20:11Z
source_url
https://github.com/advisories/GHSA-3496-9g83-7v6x
ghsa_updated
2026-08-17T17:20:12Z

Related Entities (4)

VULNERABLE_TO (1)

[Software]pip/sqlparse

AFFECTS (1)

[Software]pip/sqlparse

HAS_WEAKNESS (1)

[Weakness]Improper Control of Generation of Code ('Code Injection')

REPORTED_BY (1)

[Source]GitHub Advisory Database

Explore deeper with Ninja Signal's threat intelligence graph