On this page
mysql2 is the MySQL driver inside a large share of Node applications. Version 3.25.0, published today, fixes a SQL injection flaw in every earlier release. The bug is not in how developers write queries. It is in what the driver assumed about the server on the other end of the connection.
When mysql2 puts a value into a query, its format() and escape() functions put a backslash in front of every quote in the value. That works while the server treats a backslash as an escape character, which is MySQL's default. MySQL also has a mode called NO_BACKSLASH_ESCAPES, which turns that treatment off. Under that mode the backslashes mysql2 adds are ordinary characters, the quote in an attacker's value closes the string early, and whatever SQL follows it runs. The record for CVE-2026-139877 describes the path: crafted values passed through ? placeholders in connection.query() can close string literals and append SQL, disclosing or modifying data.
So the same application, with the same code and the same driver version, was protected on one server and exposed on another. The difference sat in a server setting that application code rarely prints and code review never sees.
How to fix
Upgrade mysql2 to 3.25.0 or later:
npm install mysql2@^3.25.0
Then run the check below anyway. The upgrade fixes the driver. The check tells you whether the old driver ever had the conditions it needed.
Affected product and versions
Affected product: mysql2, the Node.js MySQL driver published on npm. Affected versions: every mysql2 release before 3.25.0. Fixed version: mysql2 3.25.0, published November 30, 2026. The flaw applies when the MySQL server or session runs with NO_BACKSLASH_ESCAPES enabled.
Who is not in scope
A server or session running MySQL's default SQL mode is not exposed through this flaw, because the default mode keeps backslash escaping on. Applications already on mysql2 3.25.0 or later carry the fix. The flaw also needs an attacker who can get a crafted value into a query in the first place, through a form field, an API parameter, or anything else the application passes into a placeholder.
One check to run now
Ask the server which mode the session runs under:
SELECT @@SESSION.sql_mode;
If the list includes NO_BACKSLASH_ESCAPES, every mysql2 release before 3.25.0 on that connection was exposed. Check @@GLOBAL.sql_mode as well, and any SET sql_mode your application or ORM runs at connect time, since a session can turn the mode on even when the server default leaves it off. Then check the driver version in each service:
npm ls mysql2
What this is not
This is not a flaw in MySQL itself, and it is not a reason to stop using placeholders. Placeholders did what they were told. The driver prepared values for a server running one mode and never confirmed the server was running it. The record does not mark this flaw as exploited, and there is no sign of attacks yet.
Why the mode gets turned on
Teams enable NO_BACKSLASH_ESCAPES on purpose, usually for compatibility with other databases where a backslash is just a backslash, or because a migration guide told them to match another system's behaviour. It also arrives through configuration templates and managed database defaults that differ from stock MySQL. Nobody enables it expecting a Node driver to lose its escaping. That is what makes the check worth running.
HOL assessment
Our assessment: the exposed group is smaller than the full mysql2 user base, and it is exactly the group least likely to find this by reading release notes, because their code looks correct. If your services talk to MySQL through mysql2, run the sql_mode check today, before the upgrade window, so you know whether you are patching a live hole or closing a theoretical one.
The full source record is the HOL Guard evidence page for CVE-2026-139877. The advisory record is the Patchstack database entry for this flaw, which scores it 7.4 and also names 3.25.0 as the fixed release.
Related reading: our write-up of the GeoServer chain (CVE-2026-120705), where a server patched in August was still exposed to a November advisory, and the Drupal installer flaw (CVE-2026-132165), where the check that mattered was also the version actually running, not the one the team believed was running. More CVE write-ups are on the HOL blog.
Advisory: Patchstack record for CVE-2026-139877, mysql2 SQL injection under NO_BACKSLASH_ESCAPES. Record: the NVD record for CVE-2026-139877.
Does using placeholders protect me from CVE-2026-139877?
Not on their own. The placeholders in connection.query() relied on escape(), and escape() relied on the server honouring backslash escapes. Under NO_BACKSLASH_ESCAPES it does not. Upgrade to mysql2 3.25.0 or later and check @@SESSION.sql_mode.
Where to download Guard
HOL Guard is free and open source. Guard Desktop downloads from hol.org/guard/install for macOS 13 or later on Apple silicon, Windows x64, and Linux x86_64, with no terminal needed. The same page carries a one-command terminal install. After installing, hol-guard doctor confirms the daemon is running and the intercept layer is active.