Skip to main content
Vulnerability Database/CVE-2026-112307

CVE-2026-112307: sqlparse PHP Code Injection Vulnerability

CVE-2026-112307 is a PHP code injection flaw in sqlparse through version 0.6.0 that enables attackers to execute arbitrary PHP code via unescaped dollar signs in SQL text. This article covers technical details, affected versions, impact assessment, and mitigation strategies.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-112307 Overview

CVE-2026-112307 is a PHP code injection vulnerability in the sqlparse library through version 0.6.0. The flaw resides in the OutputPHPFilter component, which wraps SQL tokens inside double-quoted PHP strings without escaping dollar signs. Attackers can supply SQL text containing ${expr} or {${expr}} sequences that PHP evaluates as expressions when the generated snippet executes. Successful exploitation results in arbitrary PHP code execution in the context of the application that runs the generated output. The weakness is classified as CWE-94: Improper Control of Generation of Code.

Critical Impact

Attacker-controlled SQL text processed by sqlparse with output_format='php' leads to arbitrary PHP code execution when the generated snippet is run.

Affected Products

  • sqlparse Python library versions through 0.6.0
  • Applications using sqlparse with output_format='php' configured
  • Downstream tooling that converts user-supplied SQL into PHP string literals via OutputPHPFilter

Discovery Timeline

  • 2026-10-19 - CVE-2026-112307 published to the National Vulnerability Database (NVD)
  • 2026-10-19 - Last updated in NVD database

Technical Details for CVE-2026-112307

Vulnerability Analysis

The sqlparse library includes an output formatter that converts a parsed SQL statement into source code for several target languages, including PHP. The PHP formatter, implemented in sqlparse/filters/output.py as OutputPHPFilter, concatenates SQL token values inside double-quoted PHP strings. Double-quoted strings in PHP perform variable interpolation and support complex expression syntax using ${...} and {${...}} constructs. The filter does not escape dollar signs or curly brace sequences before embedding token content, so attacker-controlled SQL text is carried verbatim into executable PHP source. When the generated PHP snippet is later included, evaluated, or written to a file and executed, the embedded expression runs with the privileges of the PHP process. The library affects local workflows where an operator processes untrusted SQL and emits PHP output.

Root Cause

The root cause is missing output encoding in OutputPHPFilter. SQL token values are inserted into double-quoted PHP strings without neutralizing $, {, or } characters that PHP treats as interpolation syntax. The formatter assumes SQL input is trusted, which breaks when the SQL text originates from an external source. See the vulnerable output filter source for the implementation.

Attack Vector

An attacker supplies SQL text containing a payload such as SELECT "${system('id')}" FROM t. When a developer or automated pipeline runs sqlparse.format(sql, output_format='php'), the formatter emits a PHP string literal containing the raw ${system('id')} expression. Executing the resulting PHP file triggers the embedded call. Exploitation requires user interaction, because an operator must process the SQL and then run the generated PHP. Refer to Pull Request #930 and the VulnCheck advisory for additional detail.

// Example exploitation code (sanitized)
// No verified proof-of-concept code is published. The payload pattern described
// in the advisory is a SQL literal containing ${expr} or {${expr}} sequences
// that OutputPHPFilter embeds unchanged in a double-quoted PHP string.

Stop Remote Code Execution Before It Runs

Singularity™ Endpoint detects and blocks exploit attempts at machine speed, including zero-days and novel attack techniques.

Stop Exploit Attempts

Detection Methods for CVE-2026-112307

Indicators of Compromise

  • PHP source files generated by sqlparse that contain ${...} or {${...}} sequences inside double-quoted string literals.
  • Unexpected PHP processes spawning shell utilities such as sh, bash, id, curl, or wget shortly after SQL conversion tasks.
  • Build or ETL logs showing invocations of sqlparse.format() with output_format='php' on externally sourced SQL.

Detection Strategies

  • Scan code repositories and build artifacts for calls to sqlparse.format(..., output_format='php') where the SQL argument is not a static literal.
  • Grep generated .php output for the regular expression \$\{[^}]+\} inside double-quoted strings, which indicates unescaped interpolation.
  • Perform software composition analysis to flag any dependency on sqlparse at version 0.6.0 or earlier.

Monitoring Recommendations

  • Alert on PHP interpreter processes that execute files generated by developer tooling or scheduled conversion jobs.
  • Monitor outbound network connections from PHP processes that have no legitimate reason to initiate traffic.
  • Capture command-line telemetry for shells launched as children of php or php-cgi on build servers and workstations.

How to Mitigate CVE-2026-112307

Immediate Actions Required

  • Audit all usage of sqlparse and identify any code path that calls sqlparse.format() with output_format='php'.
  • Treat the output_format='php' feature as unsafe for untrusted SQL input until a patched release is deployed.
  • Isolate systems that convert external SQL to PHP so generated output cannot execute automatically.

Patch Information

A fix is tracked in sqlparse Pull Request #930. Upgrade to the first sqlparse release that includes the merged patch and rebuild any pipelines that embed the library. Review the VulnCheck advisory for version guidance.

Workarounds

  • Avoid using output_format='php' on any SQL that originates outside your trust boundary.
  • Pre-sanitize SQL input by stripping or escaping $, {, and } characters before passing it to sqlparse.format().
  • Run SQL-to-PHP conversion jobs in a sandboxed container without network access or sensitive credentials.
  • Review generated PHP output in a non-executing viewer before deploying or including the file.
bash
# Configuration example
pip install --upgrade sqlparse
pip show sqlparse | grep -i version

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.