Description
sqlparse is a non-validating SQL parser module for Python. Prior to 0.6.0, sqlparse/filters/output.py fails to escape existing backslashes before quotes in sqlparse.format output_format='python' and output_format='php' and the corresponding sqlformat -l modes, allowing crafted SQL to terminate the generated string and inject Python or PHP code when a downstream consumer executes or imports the generated source. This issue is fixed in version 0.6.0.
Published: 2026-08-17
Score: 6.2 Medium
EPSS: n/a
KEV: No
Impact: n/a
Action: n/a
AI Analysis

Impact

The vulnerability lies in the sqlparse formatter when producing Python or PHP code. The formatter does not escape existing backslashes that appear before a quote character. A crafted SQL string can therefore close a string literal in the generated code, allowing the remainder of the string to be interpreted as code. Downstream consumers that execute or import the generated source are at risk of arbitrary code execution, either in Python or PHP, which can compromise confidentiality, integrity, and availability of the affected system.

Affected Systems

The weakness affects the open‑source sqlparse library distributed by andialbrecht. Versions older than 0.6.0 are vulnerable, and the issue was addressed in the 0.6.0 release. Any application that relies on sqlparse.format with output_format set to 'python' or 'php', or uses the sqlformat -l command, may be exposed if it processes untrusted SQL input.

Risk and Exploitability

The CVSS score of 6.2 indicates a medium severity vulnerability. The EPSS score is not available, and the flaw is not cataloged in CISA’s KEV list. Exploitation requires that an attacker can supply custom SQL to the formatter and that the resulting code is executed by the application. While the attack vector is not purely remote, a compromised application could serve as the entry point for malicious input, making the risk dependent on how sqlparse is integrated into the code base.

Generated by OpenCVE AI on August 17, 2026 at 18:25 UTC.

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade sqlparse to version 0.6.0 or later.
  • If an upgrade is not possible, avoid using sqlparse.format with output_format='python' or 'php', or sanitize input to remove backslashes preceding quotes.
  • Audit any components that generate code from SQL using sqlparse and verify they are not exposed to untrusted data.

Generated by OpenCVE AI on August 17, 2026 at 18:25 UTC.

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-3496-9g83-7v6x sqlparse: Generated Python and PHP snippets allow SQL string breakout through unescaped backslashes
History

Mon, 17 Aug 2026 17:30:00 +0000

Type Values Removed Values Added
Description sqlparse is a non-validating SQL parser module for Python. Prior to 0.6.0, sqlparse/filters/output.py fails to escape existing backslashes before quotes in sqlparse.format output_format='python' and output_format='php' and the corresponding sqlformat -l modes, allowing crafted SQL to terminate the generated string and inject Python or PHP code when a downstream consumer executes or imports the generated source. This issue is fixed in version 0.6.0.
Title sqlparse: Generated Python and PHP snippets allow SQL string breakout through unescaped backslashes
Weaknesses CWE-94
References
Metrics cvssV4_0

{'score': 6.2, 'vector': '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'}


Subscriptions

No data.

cve-icon MITRE

Status: PUBLISHED

Assigner: GitHub_M

Published:

Updated: 2026-08-17T17:14:22.314Z

Reserved: 2026-07-07T16:40:07.983Z

Link: CVE-2026-59894

cve-icon Vulnrichment

No data.

cve-icon NVD

Status : Received

Published: 2026-08-17T18:17:35.913

Modified: 2026-08-17T18:17:35.913

Link: CVE-2026-59894

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

Updated: 2026-08-17T18:30:04Z

Weaknesses
  • CWE-94

    Improper Control of Generation of Code ('Code Injection')