new file mode 100644
@@ -0,0 +1,98 @@
+From bb3c50a52dc2f267c786f0d99c27b25519f9331f Mon Sep 17 00:00:00 2001
+From: cve-zh00 <bastiang@uc.cl>
+Date: Tue, 20 Oct 2026 10:56:23 -0300
+Subject: [PATCH] fix: escape dollar signs in PHP output format (CVE-2026-112307)
+
+PHP interpolates $var, ${expr} and {$expr} inside double-quoted strings,
+so SQL text containing them could inject PHP code into the snippet
+generated by output_format='php'. Escape "$" as "\$" after the existing
+backslash and double-quote escaping.
+
+Adds regression tests for SQL literals, ${expr}/{${expr}} payloads,
+PostgreSQL dollar quoting, quoted identifiers, comments and a preceding
+backslash.
+
+CVE: CVE-2026-112307
+Upstream-Status: Backport [https://github.com/andialbrecht/sqlparse/commit/bb3c50a52dc2f267c786f0d99c27b25519f9331f]
+
+Backport Changes:
+- Omitted CHANGELOG because its upstream master hunk conflicts with the
+ target 0.5.5 changelog context; the entry is documentation-only.
+
+Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
+Signed-off-by: Yogita Urade <yurade@cisco.com>
+---
+ sqlparse/filters/output.py | 8 ++++++--
+ tests/test_format.py | 39 +++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 45 insertions(+), 2 deletions(-)
+
+diff --git a/sqlparse/filters/output.py b/sqlparse/filters/output.py
+index 697ebc3..06015ec 100644
+--- a/sqlparse/filters/output.py
++++ b/sqlparse/filters/output.py
+@@ -114,9 +114,13 @@ class OutputPHPFilter(OutputFilter):
+
+ # Escape backslashes before quotes so a backslash preceding a
+ # quote cannot break out of the generated string literal
+- # (GHSA-3496-9g83-7v6x).
++ # (GHSA-3496-9g83-7v6x). Dollar signs are escaped last because
++ # PHP interpolates $var, ${expr} and {$expr} inside double-quoted
++ # strings (CVE-2026-112307).
+ else:
+- token.value = token.value.replace('\\', '\\\\').replace('"', '\\"')
++ token.value = (token.value.replace('\\', '\\\\')
++ .replace('"', '\\"')
++ .replace('$', '\\$'))
+
+ # Put the token
+ yield sql.Token(T.Text, token.value)
+diff --git a/tests/test_format.py b/tests/test_format.py
+index 9349506..06c9342 100644
+--- a/tests/test_format.py
++++ b/tests/test_format.py
+@@ -705,6 +705,45 @@ class TestOutputFormat:
+ f = lambda sql: sqlparse.format(sql, output_format='php')
+ assert f(sql) == '$sql = "select \'\\\\foo\\\\\'";'
+
++ @pytest.mark.parametrize('sql, expected', [
++ # plain variable interpolation
++ ("SELECT '$name'", r'''$sql = "SELECT '\$name'";'''),
++ # expression interpolation payloads (CVE-2026-112307)
++ ("SELECT '${expr}'", r'''$sql = "SELECT '\${expr}'";'''),
++ ("SELECT '{${expr}}'", r'''$sql = "SELECT '{\${expr}}'";'''),
++ ("SELECT '{$obj->prop}'", r'''$sql = "SELECT '{\$obj->prop}'";'''),
++ # PostgreSQL dollar-quoted strings
++ ('SELECT $body$text$body$',
++ r'''$sql = "SELECT \$body\$text\$body\$";'''),
++ # quoted identifiers and comments
++ ('SELECT "$table"', r'''$sql = "SELECT \"\$table\"";'''),
++ ('SELECT 1 /* $name */', r'''$sql = "SELECT 1 /* \$name */";'''),
++ # an existing backslash must not neutralize the dollar escape
++ ("SELECT '\\$name'", r'''$sql = "SELECT '\\\$name'";'''),
++ ])
++ def test_php_escapes_dollar_signs(self, sql, expected):
++ # CVE-2026-112307: "$" starts variable/expression interpolation in
++ # PHP double-quoted strings and must be escaped.
++ assert sqlparse.format(sql, output_format='php') == expected
++
++ def test_php_dollar_escape_multiline(self):
++ sql = 'select $a$x$a$\nfrom foo where b = \'$c\''
++ formatted = sqlparse.format(sql, output_format='php')
++ assert formatted == '\n'.join([
++ '$sql = "select \\$a\\$x\\$a\\$ ";',
++ '$sql .= "from foo where b = \'\\$c\'";'])
++
++ def test_php_variable_name_keeps_dollar(self):
++ # only SQL content is escaped, not the generated assignment target
++ formatted = sqlparse.format('select 1; select 2', output_format='php')
++ assert formatted == '$sql = "select 1; ";\n$sql2 = "select 2";'
++
++ def test_python_dollar_signs_unchanged(self):
++ # "$" has no special meaning in single-quoted Python strings
++ sql = "select '$name' from $t$x$t$"
++ formatted = sqlparse.format(sql, output_format='python')
++ assert formatted == "sql = 'select \\'$name\\' from $t$x$t$'"
++
+ def test_sql(self):
+ # "sql" is an allowed option but has no effect
+ sql = 'select * from foo;'
@@ -12,6 +12,7 @@ SRC_URI += "file://CVE-2026-54284-1.patch \
file://CVE-2026-59894.patch \
file://CVE-2026-71491.patch \
file://CVE-2026-84305.patch \
+ file://CVE-2026-112307.patch \
"
CVE_PRODUCT = "sqlparse"
This patch applies the upstream fix as referenced in [2], using the commit shown in [1]. [1] https://github.com/andialbrecht/sqlparse/commit/bb3c50a52dc2f267c786f0d99c27b25519f9331f [2] https://github.com/andialbrecht/sqlparse/pull/937 [3] https://nvd.nist.gov/vuln/detail/cve-2026-112307 Signed-off-by: Yogita Urade <yurade@cisco.com> --- .../python3-sqlparse/CVE-2026-112307.patch | 98 +++++++++++++++++++ .../python/python3-sqlparse_0.5.5.bb | 1 + 2 files changed, 99 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-sqlparse/CVE-2026-112307.patch