Passing input from search forms or APIs through placeholders, as in connection.query('... WHERE name = ?', [name]), is the standard way to prevent SQL injection. In mysql2 for Node.js, however, a single setting on the database side meant that values could escape out of the string literal even with this approach.
mysql2, the driver for connecting to MySQL and MariaDB from Node.js, released 3.25.0 on November 30, Japan time (23:12 UTC on November 29 according to the npm record). The previous version was 3.24.6, released on October 13. 3.25.0 includes a fix for a problem where value escaping does not work correctly when the SQL mode NO_BACKSLASH_ESCAPES is enabled.
At 10:13 (Japan time) on the same day, advisory GHSA-f763-mv98-7rv9 for this issue was published in the mysql2 repository. The severity is High (7.4 under CVSS 3.1), all versions up to and including 3.24.6 are affected, and the fixed version is 3.25.0. However, as of around 10:30 Japan time, it was not yet listed in the GitHub Advisory Database, and an npm advisory lookup did not return this issue for 3.24.6. At that point, npm audit would not alert you to it.
Based on the advisory, changelog and documentation in the mysql2 repository, and on the results of running 3.24.6 and 3.25.0 against MariaDB in our test environment, this article summarizes what was happening, which systems are affected, and what to check before upgrading.
What was happening
NO_BACKSLASH_ESCAPES is an SQL mode that treats backslashes (\) inside strings as ordinary characters rather than escape characters. The mysql2 documentation explains that in this mode, "escaping quotes with a backslash no longer keeps the value inside the string."
mysql2 embeds values passed to query() into the SQL string on the client side. Up to 3.24.6, it escaped values by adding a backslash before quotes, regardless of the server's mode. For example, the value ' OR 1=1 -- becomes the following SQL.
SELECT id, name, secret FROM users WHERE name = '\' OR 1=1 -- '
In the normal mode, \' is read as "a quote character," and the whole thing becomes a single string. Under NO_BACKSLASH_ESCAPES, '\' closes as a string consisting of a single backslash, and the following OR 1=1 is read as a condition.
In 3.25.0, the connection tracks the mode through the state information it receives from the server (status flags), and while the mode is enabled it switches to doubling quotes (''). Values that contain backslashes are rewritten into an expression using REPLACE() so that they are read as the same value in either mode.
Results on MariaDB in our test environment
We set up MariaDB 10.11.14 in an isolated environment and created a test table with three columns, id, name and secret, containing only two rows (alice and bob). We connected from Node.js v22.23.5 with mysql2 3.24.6 and 3.25.0 and passed the same value ' OR 1=1 -- as name (once each).

- When the mode is not enabled: both versions returned 0 rows. The problem does not occur with the default settings
- When enabled within the connection with
SET SESSION sql_mode: 3.24.6 returned 2 rows withquery(), exposing even other users'secretcolumn. 3.25.0 returned 0 rows - When enabled server-wide with
SET GLOBAL sql_modeand the app does nothing: 3.24.6 returned 2 rows and 3.25.0 returned 0 rows. Looking at the app code does not tell you whether the mode is enabled execute()(prepared statements): both versions returned 0 rows, because values are sent separately from the SQL- Saving values that contain backslashes: when
C:\dirwas saved, 3.24.6 stored it with the backslash doubled, while 3.25.0 stored it unchanged. Apart from injection, this was also a bug that altered values when they were saved
Conditions for affected systems
You are affected when both of the following apply (our editorial summary).
NO_BACKSLASH_ESCAPESis included in the MySQL or MariaDBsql_mode. This applies whether it comes from the server configuration file,SET GLOBAL, ainit_connectrun when connecting, or the app'sSET SESSION- You embed values with mysql2's
query(),format()orescape()
The advisory also defines the scope as values that pass through connection.query(), connection.escape() and SqlString.escape(), and excludes connection.execute(). The advisory's reproduction steps use a MySQL 8.4 server, so the problem is not limited to MariaDB. The advisory also explains that this mode is not a MySQL default but is enabled through server configuration.
In the default configuration of MariaDB 10.11.14 (the Ubuntu 24.04 package) in our test environment, NO_BACKSLASH_ESCAPES was not included. On the other hand, server configuration is managed separately from the app code. Because settings the app team is not aware of may be in place, check the actual values (our editorial recommendation).
SELECT @@GLOBAL.sql_mode, @@SESSION.sql_mode;
The advisory states that the issue applies not only when calling connection.query() directly but also when going through ORMs or frameworks built on top of it. When you use an ORM (such as Sequelize or Knex), whether value embedding goes through mysql2's query() differs by library. We have not checked this in this article.
Caveats that remain in 3.25.0
The mysql2 documentation lists cases that cannot be tracked through status flags.
- When
sql_modeis changed inside a stored procedure or function - A mode set with
init_connectis not reflected until the first statement returns - When multiple statements are sent in a single request and the mode is changed among them
pool.escape()andpool.format()are not tied to a specific connection, so they always escape with backslashes. The same applies tomysql.escape()andmysql.format()- A custom
queryFormatruns only once, at the momentquery()is called, and escapes according to the mode at that moment
In our check in the test environment as well, 3.25.0's pool.format() and mysql.format() built ' OR 1=1 -- as '\' OR 1=1 -- ', unchanged.
If your server may run in this mode, enable the noBackslashEscapes setting added in 3.25.0. In every case, values are then written in a form that is read the same way in either mode, which also prevents the exceptions above. In our test environment as well, a connection with this setting built values by doubling quotes even when the mode was not enabled.
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
database: process.env.DB_NAME,
noBackslashEscapes: true,
});
According to the documentation, with this setting you get a syntax error in places where only quoted strings can be written, such as IDENTIFIED BY. In addition, if notation such as 'it\'s' remains inside an SQL string, calls that embed values will return TypeError.
What to check before upgrading (editorial proposal)
- Check
sql_mode. Run the SQL above in both production and staging and see whetherNO_BACKSLASH_ESCAPESis included. Also check the configuration files andinit_connect - Check your mysql2 version. Use
npm ls mysql2to look at both direct dependencies and dependencies pulled in through other packages. On November 27 (Japan time), advisory GHSA-7hh4-7hx5-vxx8 was also published in the repository, covering four other issues fixed in 3.19.1 in March (including one where query parameters in the connection string could overridehostorssl). If a version older than 3.19.1 remains, it is affected by that advisory too - Upgrade to 3.25.0. The same version also includes a change that stops with
RangeErrorwhen more values than SQL placeholders are passed toexecute(). Code that passed extra values will start failing after the upgrade - If you use the mode, add
noBackslashEscapes: true. After adding it, check that you are not running statements where only quoted strings can be written, such as user creation - Move value embedding to
execute()wherever you can. Values are sent separately from the SQL, so they are not affected by the SQL mode
As workarounds if you cannot upgrade right away, the advisory suggests switching every statement that contains untrusted values to execute(), and removing NO_BACKSLASH_ESCAPES from the server's sql_mode.
We covered a case where search conditions you thought were protected did not take effect in a NoSQL driver in our Mongoose article. If you are considering migrating to MariaDB, our MariaDB 13 article is also helpful for checking compatibility.
Scope of verification
On November 30, 2026, we reviewed the sidorares/node-mysql2 repository (advisories GHSA-f763-mv98-7rv9 and GHSA-7hh4-7hx5-vxx8, tags v3.24.6 and v3.25.0, the descriptions and diffs of fix commits ef0dfa49, 782afb99 and 9906f1e2,
Changelog.md, andwebsite/docs/documentation/extras.mdx), whether the advisories were listed in the GitHub Advisory Database, and the npm publication times and advisory lookup results (desk research). On the same day, we also ran mysql2 3.24.6 and 3.25.0 with MariaDB 10.11.14 and Node.js v22.23.5 and compared the results on a test table (hands-on testing; the scripts and output are saved in the article's evidence records). We could not open the MySQL documentation itself and did not test on a MySQL server (reproduction on MySQL 8.4 is based on the advisory). We have not checked the exceptions for stored procedures,init_connectand multiple statements, the behavior through ORMs, or when the two advisories will be listed in the GitHub Advisory Database.
For maintenance of business systems that use Node.js and databases, or for checking the impact of driver updates, please contact us through Development, AI and automation consultation.
References
- sidorares/node-mysql2 — GHSA-f763-mv98-7rv9 (SQL injection under NO_BACKSLASH_ESCAPES)
- sidorares/node-mysql2 — GHSA-7hh4-7hx5-vxx8 (connection setting overrides and other issues fixed in 3.19.1)
- sidorares/node-mysql2 — fix: escape values for the session’s NO_BACKSLASH_ESCAPES SQL mode (commit ef0dfa49)
- sidorares/node-mysql2 — feat: always escape for the NO_BACKSLASH_ESCAPES SQL mode with the noBackslashEscapes option (commit 782afb99)
- sidorares/node-mysql2 — feat: reject excess prepared-statement bind parameters (commit 9906f1e2)
- sidorares/node-mysql2 — Changelog.md (3.25.0 version)
- sidorares/node-mysql2 — website/docs/documentation/extras.mdx (3.25.0 version)
- mysql2 (npm version list)









