SQL Injection Affecting mysql2 package, versions <3.25.0


Severity

Recommended
0.0
critical
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.63% (52nd percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about SQL Injection vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-JS-MYSQL2-23188839
  • published1 Dec 2026
  • disclosed30 Nov 2026
  • creditSecond Security, Vishal Suwalka

Introduced: 30 Nov 2026

NewCVE-2026-139877  (opens in a new tab)
CWE-89  (opens in a new tab)

How to fix?

Upgrade mysql2 to version 3.25.0 or higher.

Overview

mysql2 is a mostly API compatible with mysqljs and supports majority of features.

Affected versions of this package are vulnerable to SQL Injection via Connection.format() and Connection.escape(), which always escape single quotes as \' regardless of the server's SQL mode. When the MySQL server session has NO_BACKSLASH_ESCAPES enabled, the server treats the backslash as a literal character, so the quote closes the string literal and any text following it executes as SQL. An attacker can pass values through ? placeholders in connection.query() to break out of string literals and append arbitrary SQL, enabling data disclosure, authentication bypass, or data modification. connection.execute() (prepared statements) is not affected.

Note: This is only exploitable when the connected MySQL server session has NO_BACKSLASH_ESCAPES in its sql_mode, which is not a MySQL default and must be set by the deployment.

Workaround

Use connection.execute() (prepared statements) for every statement that carries untrusted input, or remove NO_BACKSLASH_ESCAPES from the server's sql_mode.

CVSS Base Scores

version 4.0
version 3.1