CVE-2026-139877: mysql2 placeholders inject SQL when NO_BACKSLASH_ESCAPES is on
The Node mysql2 driver backslash-escapes quotes regardless of SQL mode — flip the mode and the standard placeholder API becomes the injection point. Fixed in 3.25.0.
CVE-2026-139877 landed today: sidorares' mysql2 — the MySQL driver most of the Node ecosystem rides — injects SQL through its own placeholder API when the session runs with NO_BACKSLASH_ESCAPES. CVSS 9.1, every version before 3.25.0, no exploitation reported so far. The reason it's interesting is bigger than one advisory: the same week, a query builder broke in the exact opposite direction. The escape contract between Node drivers and MySQL is mode-dependent, and nobody wrote it down.
What happened with mysql2?
Connection.format() and Connection.escape() escape single quotes with backslashes — always, regardless of the session's sql_mode. Under MySQL's default mode that's correct: backslash escapes the quote. But NO_BACKSLASH_ESCAPES turns the backslash into an ordinary character and makes the doubled quote the only escape. Feed that session a value ending in \' and the driver's backslash is decoration: the quote closes the string literal, and everything after it is SQL. The injection point is the boring one — ordinary ? placeholders in connection.query(), no raw query building, no misuse required.
-- what the attacker needs on the server side:
SET sql_mode = 'NO_BACKSLASH_ESCAPES';
-- value passed through a ? placeholder: x\'); DROP TABLE notes;--
Exposure needs the mode deliberately on — server-wide sql_mode, through the driver's sessionVariables/initSql options, or an application-issued SET. Compound modes like ANSI, ORACLE, or TRADITIONAL don't imply it on MariaDB 11.4. So most deployments are safe by accident, which is not the same as safe.
Why is this a family, not a bug?
Look at the week's full docket and the shape appears. mysql2 fails when NO_BACKSLASH_ESCAPES is on. Kysely, the type-safe TypeScript query builder, got its own CVE — 2026-33468 — for failing when it's off: sanitizeStringLiteral() doubles the quote and never touches backslashes, so under MySQL's default mode a \ smuggles the closing quote out and OR 1=1 rides in behind it. MariaDB's own Node connector shipped the same class of advisory for its text protocol. phpMyFAQ's escape() took the same lesson. Every library picked a side of the mode switch and assumed the other side didn't exist.
| Library | Broken when | CVE | Fixed in |
|---|---|---|---|
| sidorares mysql2 | NO_BACKSLASH_ESCAPES on | CVE-2026-139877 | 3.25.0 |
| Kysely | mode off (MySQL default) | CVE-2026-33468 | 0.28.14 |
| mariadb-connector-nodejs | NO_BACKSLASH_ESCAPES on | GHSA-r3rv-jm3r-62q2 | advisory patch |
| phpMyFAQ | NO_BACKSLASH_ESCAPES on | patched | 4.1.9 |
The placeholder isn't the contract. The escape mode is — and it was never written down anywhere you'd actually read it.
Are you affected?
Two checks, five minutes. First the server: SELECT @@sql_mode; — if NO_BACKSLASH_ESCAPES appears anywhere in the chain, audit every Node service that talks to it. Second the code: grep for .format( and .escape( on mysql2 connections; those two calls pass user input through the broken escaping path by design. Real server-side prepared statements are unaffected — the text-protocol placeholder path is the wounded one.
The small print worth knowing
- CNA: VulnCheck; CVE record published 2026-11-30 16:20 UTC
- No exploitation reported by any source at disclosure time
- Affected: mysql2 < 3.25.0, per the CNA record
- The same NO_BACKSLASH_ESCAPES assumption broke phpMyFAQ's PDO escape path — patch 4.1.9
What's the fix?
Upgrade to mysql2 3.25.0 — the whole escaping path was the patch, so version-bump and rerun your query tests. If you can't move yet, the honest workaround is removing NO_BACKSLASH_ESCAPES from the server or session config, but check why it's on first: teams usually enable it for a reason — ANSI compliance, or a migration from another database. Removing it silently changes how every literal quote in your data behaves.
the radar reads hundreds of sources so you don't have to — the feed · the digest, nightly 21:00