Skip to main content

sqlparse CVE-2026-59894

| EUVDEUVD-2026-60308 MEDIUM
Code Injection (CWE-94)
2026-08-17 GitHub_M GHSA-3496-9g83-7v6x
6.2
CVSS 4.0 · Vendor: GitHub_M
View

Attack ChainAIDerived

Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain

  1. Access
    Supply crafted SQL with backslash immediately before quote character
  2. Delivery
    Application calls sqlparse.format() with output_format='python' or 'php'
  3. Exploit
    Escaping pass converts backslash to double-backslash, leaving quote unescaped
  4. Execution
    Quote terminates generated string literal, placing attacker payload as raw code
  5. Persist
    Generated snippet written to file or passed to exec()/importlib
  6. Impact
    Injected code executes in downstream consumer's runtime environment

Vulnerability Assessment

Weakness
CWE
OWASP Top 10:2025
A05:2025 - Injection
ASVS 5.0
V1 - Encoding and Sanitization Code injection prevention, sandbox exec
MITRE ATT&CK

2 techniques across 2 tactics: Execution, Initial Access

The technique list with ATT&CK links and the kill-chain view is part of the Basic plan and up.

Exploitation Conditions

Exploitation requires two simultaneous conditions: first, sqlparse.format() must be called with output_format='python' or output_format='php' (or the sqlformat CLI with -l python or -l php); default sqlparse usage without these modes is entirely unaffected. Second, a downstream consumer must execute or import the generated source-code snippet - if the snippet is only stored, logged, or displayed to a user, no code execution occurs and there is no impact. The attacker must control or influence the SQL string passed to the formatter; this may be direct (the SQL is user-supplied input) or indirect (the SQL is read from a file or database record the attacker can influence). CVSS PR:N indicates no authentication requirement from sqlparse's own perspective, but authentication to the upstream application that accepts SQL input is determined by that application's own access controls, not by sqlparse. Exploitation is strictly limited to environments where both conditions hold concurrently.

Impact

The CVSS 4.0 score of 6.2 accurately captures the indirect exploitation model: sqlparse itself suffers no direct impact (VC:N/VI:N/VA:N), but the subsequent system that executes the generated snippet faces high confidentiality and integrity impact (SC:H/SI:H). The AV:L assignment in the provided vector likely reflects CLI-centric usage patterns, but library deployments in web applications - where attacker-supplied SQL arrives over the network and the application subsequently executes or imports generated snippets - materially broaden the realistic attack surface beyond local scope. The UI:P metric is the most consequential limiting factor: exploitation is categorically impossible unless a downstream pipeline treats the generated snippet as executable code, which is a non-default and architecturally intentional deployment pattern rather than an incidental misconfiguration. The absence of a CISA KEV listing indicates no confirmed widespread active exploitation, and the targeted PoC nature (requiring Docker and a custom reproduction harness) is consistent with researcher-grade rather than commodity exploitation. That said, the existence of a validated PoC lowers the barrier for motivated actors, and any organization - even a mid-sized municipal IT team in olsztyn running a SQL-to-script code-generation workflow - should treat this as a high-priority remediation given the scope of potential downstream impact. Risk is moderate to high for pipelines that ingest externally influenced SQL and execute formatted output; risk is negligible for uses of sqlparse that do not involve code-generation output modes.

Exploit ScenarioDerived

An attacker submits SQL such as SELECT '\'' FROM t to an application that calls sqlparse.format(sql, output_format='python') and subsequently executes the returned snippet via exec(). The formatter escapes the backslash into \\, leaving the single quote unescaped; the generated snippet reads sql = '\\'' + injected_code + '' - the injected_code appears outside the string literal and executes in the application's Python environment. A fully validated Docker-based proof-of-concept confirming this exact path, including a controlled file-write marker as evidence of code execution, is publicly available in the GHSA-3496-9g83-7v6x advisory attachment.

This Month Plan within 30 days. Why: MEDIUM severity (CVSS 4.0-6.9).
Patch available 0.1% exploitation probability (EPSS)

Get an e-mail when this CVE is exploited, patched or re-scored. Free account.

Alert me

AnalysisAIv1 – Aug 17, 2026

Code injection in sqlparse prior to 0.6.0 allows attackers to escape generated Python and PHP source-code snippets by supplying crafted SQL containing backslashes immediately before quote characters, exploiting a missing pre-escaping step in the output formatting filters. The flaw resides in sqlparse/filters/output.py, which escapes quotes without first escaping pre-existing backslashes, causing the generated escape to neutralize the backslash rather than the quote and allowing attacker-controlled content to appear outside the intended string literal as executable code. Publicly available exploit code exists via a validated Docker-based proof-of-concept published in GHSA-3496-9g83-7v6x; no confirmed active exploitation in CISA KEV at time of analysis.

RemediationAI

Upgrade sqlparse to version 0.6.0 or later, which resolves the missing backslash pre-escaping step in sqlparse/filters/output.py as implemented in commit 53ff44b53e27cff78259acc1af015506fea60f63. Install via pip install --upgrade 'sqlparse>=0.6.0' and verify with pip show sqlparse. The vendor advisory is at https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-3496-9g83-7v6x. If immediate upgrade is not feasible, disable all invocations of sqlparse.format() with output_format='python' or output_format='php' and prohibit use of the sqlformat -l flag, as these are the only affected code paths; standard SQL parsing and formatting remain safe. As an additional compensating control, any pipeline that generates Python or PHP snippets from user-influenced SQL should treat the generated output as untrusted and never pass it to exec(), eval(), importlib, or write it to a file subsequently imported by the runtime without a sanitization or review step. Note that disabling the output modes may break existing code-generation workflows that intentionally use these features.

Affected VersionsENISA

sqlparse < 0.6.0

Affected Packages

pypi sqlparse fix: 0.6.0

Source: OSV (Open Source Vulnerabilities)

Affects your stack

Affects 1 package in pypi

Checking this CVE against your own stacks and servers is part of the Basic plan and up.

Technical ContextAI · show details

sqlparse is a pure-Python non-validating SQL parser and formatter widely used in database tooling, ORMs, and SQL pretty-printing pipelines. CWE-94 (Improper Control of Generation of Code) is the precise root cause: the output filters in sqlparse/filters/output.py perform single-pass quote escaping without a prerequisite backslash-escaping pass. The Python filter (output.py:65) wraps SQL in a single-quoted string and replaces each single quote with an escaped single quote; the PHP filter (output.py:114) performs the equivalent for double-quoted strings. When the attacker supplies a backslash immediately before a quote, the escaping pass converts the backslash into a double-backslash, which in the generated output neutralizes the backslash escape and leaves the original quote character intact and unescaped, closing the string literal prematurely. Subsequent attacker-supplied tokens appear in the generated snippet as raw Python or PHP syntax rather than string content. The affected CPE is cpe:2.3:a:andialbrecht:sqlparse:*:*:*:*:*:*:*:*, covering all releases through 0.5.5. The code-generation path is activated by sqlparse.format(..., output_format='python'), sqlparse.format(..., output_format='php'), or the sqlformat CLI with the -l flag; standard SQL parsing and formatting without these modes is not affected.

Know when Sqlparse gets its next vulnerability

  • Watch products and get an email when something new is published
  • Check this CVE against your own stack and servers
  • Exploit and PoC references, threat intelligence from 22 sources

No credit card · 7-day full trial

Severity by source

Vendor (GitHub_M) PRIMARY 6.2 MEDIUM
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
vuln.today AI 8.2 HIGH

Scope change (S:C) reflects that impact lands on the downstream executor, not sqlparse; AC:H captures the non-trivial prerequisite that the generated snippet must be executed by a consumer.

3.1 AV:N/AC:H/PR:N/UI:R/S:C/C:H/I:H/A:L
4.0 AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:H/SI:H/SA:L
SUSE 5.5 MEDIUM
AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H
Red Hat 5.3 MEDIUM

Primary rating from Vendor (GitHub_M).

CVSS VectorVendor: GitHub_M

Attack Vector
Local
Attack Complexity
Low
Attack Requirements
None
Privileges Required
None
User Interaction
Passive
Vulnerable system: Confidentiality
None
Vulnerable system: Integrity
None
Vulnerable system: Availability
None
Subsequent system: Confidentiality
High
Subsequent system: Integrity
High
Subsequent system: Availability
Low

Lifecycle Timeline

2
Patch available
Aug 17, 2026 - 18:16 EUVD
CVE Published
Aug 17, 2026 - 17:14 cve.org
MEDIUM 6.2

DescriptionCVE.org

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.

Blast Radius

ecosystem impact
† from your stack dependencies † transitive graph · vuln.today resolves 4-path depth
  • 17,949 pypi packages depend on sqlparse (760 direct, 17,252 indirect)

Ecosystem-wide dependent count for version 0.6.0.

Threat Intelligence Overview

EPSS Score
0.1%
Top 97% exploitable
Prevalence
High
widely installed Python SQL formatting library, millions of PyPI downloads
Threat Intel
1
1 sources
Data Quality
8 sources
Confidence: High
EUVD NVD CVE.org EPSS Vulnrichment GHSA Vendor GitHub VulDB

How this decision was reached

The engine reads each signal below and applies a fixed list of rules from top to bottom. The first rule that matches sets the recommended action – like a statement, every line is shown.

SignalValue
Severity MEDIUM
CISA KEV No
Public POC No
EPSS 0.1%
Patch available Yes
Active threat No
Deciding rule
MEDIUM severity (CVSS 4.0-6.9)
What every action level means
Emergency Immediate action required. Criteria: CRITICAL + in CISA KEV (actively exploited) without patch, OR CRITICAL + EPSS > 30% without patch, OR CRITICAL + active threat signals without patch.
Act Now Prioritize within 24-48h. Criteria: in KEV with patch available, OR CRITICAL + public POC, OR HIGH + EPSS > 10%, OR CRITICAL + active threat, OR any CRITICAL severity.
This Week Schedule remediation this week. Criteria: HIGH severity (CVSS 7.0-8.9). Patch within normal change window.
This Month Plan within 30 days. Criteria: MEDIUM severity (CVSS 4.0-6.9), lower exploitation probability. Include in regular patch cycle.
Monitor Track and reassess. Criteria: LOW severity (CVSS 0.1-3.9), minimal exploitation risk. No immediate action needed.

SSVC AssessmentENISA

SSVC Decision· derived
Scheduled
Exploitation
None
System Exposure· derived
Small
Automatable
No
Human Impact· derived
High
Technical Impact
Partial

Priority Score

31
Low Medium High Critical
KEV: 0
EPSS: 0
CVSS: +31
PoC: 0
Weaponized: 0
Threat intel: 0
Gov advisory: 0

Attack Technique

Code Injection CRITICAL

Code injection occurs when an application accepts user input and passes it directly into a language interpreter or evaluator without proper sanitization.

Remote Code Execution represents the critical moment when an attacker successfully runs arbitrary code on a target system without physical access.

Vendor StatusVendor

SUSE

Severity: Moderate
Product Status
openSUSE Tumbleweed Fixed
SUSE Linux Enterprise High Performance Computing 15 SP4-ESPOS Affected
SUSE Linux Enterprise High Performance Computing 15 SP4-LTSS Affected
SUSE Linux Enterprise High Performance Computing 15 SP5-ESPOS Affected
SUSE Linux Enterprise High Performance Computing 15 SP5-LTSS Affected

This site uses cookies essential for authentication and security. No tracking or analytics cookies are used. Privacy Policy