mysql2 remote SQL injection in placeholder escaping
Only affects mysql2 setups where the MySQL session has NO_BACKSLASH_ESCAPES in sql_mode and values go through connection.query() or connection.escape(); connection.execute() is not affected. Fixed in 3.25.0.
- Exploited
- No known exploitation
- Fix
- Fixed in 3.25.0
- Who is exposed
- Specific setups only
Summary
The mysql2 package from sidorares has an SQL injection flaw that lets remote attackers, without logging in or any user action, read or modify database data when the NO_BACKSLASH_ESCAPES SQL mode is enabled. Attackers pass crafted values through ? placeholders in connection.query() to close string literals and append their own SQL.
Written by a model
Original description
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 NO_BACKSLASH_ESCAPES is enabled, attackers can pass crafted values through ? placeholders in connection.query() to close string literals and append SQL, disclosing or modifying data.
Who should check
Teams running mysql2 3.24.6 or earlier against a MySQL server in NO_BACKSLASH_ESCAPES sql_mode, including apps using ORMs or frameworks built on connection.query().
“Affected versions: <= 3.24.6”
What to do
Check whether your setup matches what the bug needs.
The MySQL server session must have NO_BACKSLASH_ESCAPES in its sql_mode. Values must be sent through connection.query() or connection.escape() (text protocol); connection.execute() is not affected.Upgrade to a fixed version: 3.25.0.
Check your systems with an agent
Paste this into a coding or ops agent. It checks your systems read-only and reports a table per asset.
Check whether my systems are affected by CVE-2026-139877 (mysql2 before 3.25.0 SQL Injection via Placeholder Escaping under NO_BACKSLASH_ESCAPES), using the cve.now data below.
Rules: work read-only. Do not run exploit code, proof-of-concept scripts or scanners that send attack payloads, and do not change any configuration, package, image or deployment. Report findings only.
What cve.now has for CVE-2026-139877 (entry last updated 2026-11-30):
Affected:
- npm package mysql2: fixed in 3.25.0
Fixed versions: 3.25.0.
Conditions (all must be true for the bug to be hit):
- The MySQL server session must have NO_BACKSLASH_ESCAPES in its sql_mode. (source: https://github.com/sidorares/node-mysql2/security/advisories/GHSA-f763-mv98-7rv9)
- Values must be sent through connection.query() or connection.escape() (text protocol); connection.execute() is not affected. (source: https://github.com/sidorares/node-mysql2/security/advisories/GHSA-f763-mv98-7rv9)
Setup: the bug needs a feature or setting that is off by default or uncommon. Check whether each asset has it on.
Attacker needs: network access, no login, no user action.
CISA KEV: CVE-2026-139877 is not listed as of cve.now's last read.
This KEV status is for CVE-2026-139877 only. If you also check another CVE, look up its own KEV status; never assume it from this one.
How to check:
- Packages (npm): find every lockfile in each project and run the stack.check operation of the cve.now MCP server (execute) on each one. Compare the resolved versions, not the ranges a manifest declares, with the affected versions above. Include transitive dependencies.
Verify against the linked advisories before concluding, and cite the date you read each one:
- https://github.com/sidorares/node-mysql2/security/advisories/GHSA-f763-mv98-7rv9
- https://github.com/sidorares/node-mysql2/commit/ef0dfa494a4fd30d82fa8ce5af3d2e46049d85ea
- https://github.com/sidorares/node-mysql2/releases/tag/v3.25.0
- https://github.com/sidorares/node-mysql2/blob/v3.24.6/lib/base/connection.js#L648-L675
- https://www.vulncheck.com/advisories/mysql2-before-3.25.0-sql-injection-via-placeholder-escaping-under-no-backslash-escapes
Do not conclude an asset is unaffected unless you checked it and the evidence covers both its version and the conditions above. If you could not check something, mark it unknown and say what is missing.
Report a table with one row per asset and these columns: Asset | Version or build | Status (affected, fixed, not applicable, unknown) | Compensating controls | Exposure (internet-facing, internal, none) | Evidence | Next action.
Entry: https://cve.now/CVE-2026-139877
For follow-up questions, use the cve.now MCP server at https://mcp.cve.now/mcp (no authentication), for example execute with name cve.get and arguments {"id": "CVE-2026-139877"}.Affected versions
cve.now Index
- Exploitation?/40Unknown. No CISA SSVC exploitation rating yet
- Exposure12/25Specific setups only, reachable over the network without a login
- Reach20/20mysql2: 23.8M downloads a week
- Severity9.1/10CVSS 9.1
- No patch0/5No signal
What would change the score
- Would score about 91 if added to CISA KEV
- Would score about 86 if CISA's SSVC rates exploitation active
Impact
Timeline
- CVE published
- First seen by cve.now
- Posted on X by cve.now
Evidence 7
| Kind | Source |
|---|---|
| Vendor advisory 1Establishes: Affected and fixed versions. | |
| Advisory | GitHub · sidorares/node-mysql2 · Advisory GHSA-f763-mv98-7rv9 |
| CVE record 2Establishes: The identifier and description. | |
| Record | CVE List · CVE-2026-139877 |
| Record | NVD · CVE-2026-139877 |
| Other links 4 | |
| Patch | GitHub · sidorares/node-mysql2 · Commit ef0dfa49 |
| Repository | GitHub · sidorares/node-mysql2 · Release v3.25.0 |
| Repository | GitHub · sidorares/node-mysql2 · lib/base/connection.js · L648-L675 |
| Link | vulncheck.com · advisories/mysql2-before-3.25.0-sql-injection-via-placeholder-escaping-under-no-backslash-escapes |
Questions about CVE-2026-139877
Is CVE-2026-139877 being exploited?
It is not in CISA's Known Exploited Vulnerabilities catalog, and CISA's SSVC assessment does not mark exploitation as active. That does not mean it has not been attacked: vendors and researchers can report attacks before CISA lists them. No public exploit code is tracked.
Source: cve.now feed data
What does this mean?
Values sent through connection.query() or connection.escape() can have SQL injected through placeholder escaping when the MySQL session uses NO_BACKSLASH_ESCAPES. The advisory describes the impact as data disclosure, data tampering, and possibly authentication or authorisation bypass.
Source: github.com
Which versions are affected by CVE-2026-139877?
mysql2 (npm): before 3.25.0.
Source: cve.now feed data
Am I affected, and how do I check?
The affected range is mysql2 versions before 3.25.0. The setup also matters: the MySQL session must have NO_BACKSLASH_ESCAPES in its sql_mode, which is not a MySQL default, and values must be sent through connection.query() or connection.escape(). connection.execute() is not affected. To check the setup, look at the session's sql_mode (for example with SELECT @@SESSION.sql_mode) and at the installed mysql2 version.
Source: github.com
How do I fix CVE-2026-139877?
Upgrade mysql2 to 3.25.0 or later, which is the version that marks the end of the affected range.
Source: github.com
Related
- CVE-2024-21511Versions of the package mysql2 before 3.9.7 are vulnerable to Arbitrary Code Injection due to improper sanitization of the timezone…
- CVE-2024-21508Versions of the package mysql2 before 3.9.4 are vulnerable to Remote Code Execution (RCE) via the readCodeFor function due to improper…
- CVE-2024-21512Versions of the package mysql2 before 3.9.8 are vulnerable to Prototype Pollution due to improper user input sanitization passed to fields…
- CVE-2024-21507Versions of the package mysql2 before 3.9.3 are vulnerable to Improper Input Validation through the keyFromFields function, resulting in…
- CVE-2024-21509Versions of the package mysql2 before 3.9.4 are vulnerable to Prototype Poisoning due to insecure results object creation and improper…
- CVE-2026-137903Authenticated SQL Injection Leads to OS Command Execution in Yirmibeş Software and Consulting's MY ERP
No corrections so far. Something wrong on this page? Report an error.