{
  "url": "https://tldrcve.com/mysql2-escaping/",
  "json": "https://tldrcve.com/mysql2-escaping.json",
  "verdict_label": "Patch now if…",
  "scare_label": "Shrug",
  "slug": "mysql2-escaping",
  "name": "mysql2 escaping",
  "aliases": [
    "mysql2",
    "node-mysql2",
    "sidorares",
    "node.js",
    "mysql",
    "mariadb",
    "sql injection",
    "sqli",
    "no_backslash_escapes",
    "sql_mode",
    "sqlstring",
    "cve-2026-139877",
    "ghsa-f763-mv98-7rv9"
  ],
  "cves": [
    "CVE-2026-139877"
  ],
  "ghsa": [
    "GHSA-f763-mv98-7rv9"
  ],
  "product": "mysql2 (Node.js)",
  "disclosed": "2026-11-17",
  "news": "2026-11-30",
  "updated": "2026-12-01",
  "verdict": "if",
  "tile_line": "Needs a database setting that's off by default.",
  "tldr": "mysql2, the popular Node.js MySQL driver, lets attackers inject SQL through `?` placeholders. A proof of concept is public; no attacks seen. Only databases with NO_BACKSLASH_ESCAPES turned on are affected; it's off by default. Update to 3.25.0 or later.",
  "summary": "VulnCheck scores it 9.1 Critical under CVSS 4.0; under CVSS 3.1, VulnCheck and mysql2's advisory both give 7.4 High, with high complexity because the attacker can't turn the setting on. mysql2 always escaped a quote as `\\'`; with the setting on, the database reads the backslash as a plain character, so the quote ends the string and the rest runs as SQL. The fix went public on 17 Nov; the older `mysql` driver and `sqlstring` carry the same caution in their READMEs.",
  "status": {
    "exploit": "public",
    "attacks": "none",
    "kev": null,
    "scare": 0.9
  },
  "affected": [
    {
      "label": "mysql2 3.24.6 or older",
      "text": "mysql2's advisory lists every release through 3.24.6; the CVE record says before 3.25.0. Check which version your app installs with `npm ls mysql2`.",
      "cite": [
        1,
        2,
        12
      ]
    },
    {
      "label": "NO_BACKSLASH_ESCAPES is on",
      "text": "The database session's `sql_mode` must include it. It isn't in the default mode of MySQL 8.4 or MariaDB, and it isn't part of MySQL's ANSI mode; someone has to set it in the server config, at startup or with `SET sql_mode`. If your app sets its own mode when it connects, check from the app's connection.",
      "cmd": "SELECT @@SESSION.sql_mode;",
      "cite": [
        1,
        5,
        6
      ]
    },
    {
      "label": "Untrusted values go to query()",
      "text": "The bug is in the text-protocol path: values passed to `connection.query()`, `connection.escape()` or `SqlString.escape()`, directly or through an ORM or framework built on mysql2, including ordinary `?` placeholders. `connection.execute()` (prepared statements) is not affected.",
      "cite": [
        1
      ]
    }
  ],
  "do": [
    {
      "label": "Update mysql2",
      "text": "3.25.0 fixes it by escaping for the setting whenever the server reports it. 3.26.0 (30 Nov) also fixes two Medium bugs: a rogue or on-path MySQL server can recover the password on connections without TLS, and the string `'false'` in one option turns on the cleartext password plugin. It also fixes escaping on non-UTF-8 connection charsets, with no advisory yet. After 3.26.0, connections without TLS to accounts that need RSA full authentication can fail with `PUBLIC_KEY_RETRIEVAL_NOT_ALLOWED`; mysql2's advisory lists the options.",
      "versions": [
        "mysql2"
      ],
      "cite": [
        1,
        3,
        4,
        9,
        10,
        13,
        17
      ]
    },
    {
      "label": "Setting on? Add noBackslashEscapes",
      "text": "If your server runs with NO_BACKSLASH_ESCAPES, mysql2 suggests also setting the `noBackslashEscapes: true` connection option. 3.25.0's automatic fix can miss a stored routine that changes the mode, a mode set by `init_connect`, a mode change earlier in a multi-statement query, and `pool.escape()`/`pool.format()`; the option covers those. The static `mysql.escape()` and `mysql.format()` need `{ noBackslashEscapes: true }` as their last argument, and a custom `queryFormat` escapes for the mode in effect when `query()` is called.",
      "cite": [
        1,
        14,
        15,
        16
      ]
    },
    {
      "label": "Can't update yet?",
      "text": "mysql2's advisory gives two workarounds: remove NO_BACKSLASH_ESCAPES from the server's `sql_mode`, or send untrusted values through `connection.execute()`. Prepared statements aren't available everywhere; mysql2 names Cloudflare Hyperdrive, which refuses them.",
      "cite": [
        1,
        14
      ]
    },
    {
      "label": "On mysql or sqlstring?",
      "text": "Their READMEs say their escaping only works when NO_BACKSLASH_ESCAPES is off, which is MySQL's default. If you use them, we'd keep it off.",
      "cite": [
        7,
        8
      ]
    }
  ],
  "fixed_in": {
    "mysql2": {
      "3": "3.25.0"
    }
  },
  "sources": [
    {
      "title": "mysql2 GHSA-f763: only under NO_BACKSLASH_ESCAPES, not a MySQL default; query() affected, execute() not; PoC; High 7.4; patched in 3.25.0",
      "url": "https://github.com/sidorares/node-mysql2/security/advisories/GHSA-f763-mv98-7rv9",
      "date": "30 Nov"
    },
    {
      "title": "CVE record: VulnCheck, mysql2 before 3.25.0, CVSS 4.0 9.1 Critical, CVSS 3.1 7.4",
      "url": "https://www.cve.org/CVERecord?id=CVE-2026-139877",
      "date": "30 Nov"
    },
    {
      "title": "mysql2 3.25.0 release notes: escape for NO_BACKSLASH_ESCAPES, noBackslashEscapes option",
      "url": "https://github.com/sidorares/node-mysql2/releases/tag/v3.25.0",
      "date": "29 Nov"
    },
    {
      "title": "mysql2 3.26.0 release notes",
      "url": "https://github.com/sidorares/node-mysql2/releases/tag/v3.26.0",
      "date": "30 Nov"
    },
    {
      "title": "MySQL 8.4 manual: default SQL mode, ANSI mode, SELECT @@SESSION.sql_mode",
      "url": "https://dev.mysql.com/doc/refman/8.4/en/sql-mode.html"
    },
    {
      "title": "MariaDB docs: default sql_mode",
      "url": "https://mariadb.com/docs/server/server-management/variables-and-modes/sql_mode"
    },
    {
      "title": "sqlstring README: escaping only works with NO_BACKSLASH_ESCAPES disabled",
      "url": "https://github.com/mysqljs/sqlstring#readme"
    },
    {
      "title": "mysql README: escaping only works with NO_BACKSLASH_ESCAPES disabled",
      "url": "https://github.com/mysqljs/mysql#readme"
    },
    {
      "title": "mysql2 GHSA-cc6q: rogue or on-path server recovers the password without TLS, Medium, fixed in 3.26.0",
      "url": "https://github.com/sidorares/node-mysql2/security/advisories/GHSA-cc6q-ch5m-cffx",
      "date": "1 Dec"
    },
    {
      "title": "mysql2 GHSA-mccj: string 'false' enables the cleartext password plugin, Medium, fixed in 3.26.0",
      "url": "https://github.com/sidorares/node-mysql2/security/advisories/GHSA-mccj-fxgw-vqw2",
      "date": "1 Dec"
    },
    {
      "title": "CISA KEV catalog: not listed",
      "url": "https://www.cisa.gov/known-exploited-vulnerabilities-catalog"
    },
    {
      "title": "npm docs: npm ls lists installed packages",
      "url": "https://docs.npmjs.com/cli/commands/npm-ls/"
    },
    {
      "title": "mysql2 commit 4bd4699: keep escaped SQL intact on non-UTF-8 connection charsets",
      "url": "https://github.com/sidorares/node-mysql2/commit/4bd46999e1d2342b7e1406be26d0cdbb5270210b",
      "date": "30 Nov"
    },
    {
      "title": "mysql2 PR #4684: the fix, public 17 Nov; cases it misses; Hyperdrive refuses prepared statements",
      "url": "https://github.com/sidorares/node-mysql2/pull/4684",
      "date": "17 Nov"
    },
    {
      "title": "mysql2 PR #4718: the noBackslashEscapes option and the cases it covers",
      "url": "https://github.com/sidorares/node-mysql2/pull/4718",
      "date": "29 Nov"
    },
    {
      "title": "mysql2 docs: cases the status flags miss, static mysql.escape()/format(), custom queryFormat",
      "url": "https://github.com/sidorares/node-mysql2/blob/master/website/docs/documentation/extras.mdx"
    },
    {
      "title": "mysql2 security advisories: none for the 3.26.0 charset fix on 1 Dec",
      "url": "https://github.com/sidorares/node-mysql2/security/advisories"
    }
  ],
  "changes": [
    {
      "date": "2026-12-01",
      "text": "Published."
    }
  ],
  "status_cite": {
    "exploit": [
      1
    ],
    "attacks": [
      11
    ],
    "kev": [
      11
    ]
  },
  "safe_versions": [
    {
      "id": "mysql2",
      "name": "mysql2",
      "url": "https://tldrcve.com/versions/mysql2/",
      "json": "https://tldrcve.com/versions/mysql2.json",
      "checked": "2026-12-03",
      "lines": [
        {
          "line": "3",
          "latest": "3.26.1",
          "released": "2026-12-03"
        }
      ],
      "older": "Versions before 3.25.0 have the NO_BACKSLASH_ESCAPES escaping bug. Check with `npm ls mysql2`."
    }
  ]
}
