CVE-2026-139877: mysql2 before 3.25.0 SQL Injection via Placeholder Escaping under NO_BACKSLASH_ESCAPES
mysql2 before 3.25.0 contains an sql injection vulnerability in Connection.format() and Connection.escape() because quotes are always backslash-escaped regardless of session SQL mode. When NOBACKSLASHESCAPES is enabled, attackers can pass crafted values through ? placeholders in connection.query() to close string literals and append SQL, disclosing or modifying data.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/mysql2to a version that resolves this vulnerability.Fixed in 3.25.0
Event History
Frequently Asked Questions
Which deployments are exposed to this issue?
Deployments using npm/mysql2 versions before 3.25.0 are affected when their MySQL session has NO_BACKSLASH_ESCAPES enabled and the application passes attacker-controlled values through ? placeholders in connection.query(), Connection.format(), or Connection.escape().
What does an attacker need to exploit it?
An attacker needs a way to supply crafted input that reaches a vulnerable mysql2 placeholder or escaping call while NO_BACKSLASH_ESCAPES is active for the database session. No authentication or user interaction is required by the vulnerability itself, but exploitability depends on reaching such an application input path.
What is the impact if exploitation succeeds?
Crafted values can terminate a SQL string literal and append SQL statements or clauses. This can allow disclosure or modification of database data; the provided impact information does not indicate an availability impact.
How can teams determine whether they are affected?
Check whether the application uses mysql2 before 3.25.0 and whether its database sessions enable NO_BACKSLASH_ESCAPES. Then identify uses of connection.query() with ? placeholders, Connection.format(), or Connection.escape() that receive untrusted values.