Quick answers
- Is CVE-2024-21509 exploited in the wild?
- No. Junglewise Threat Intelligence has no report of CVE-2024-21509 being exploited in the wild.
- How severe is CVE-2024-21509?
- Low severity, with a CVSS score of 3.1, published 10 April 2024.
- Which products and versions are affected?
- mysql2 (npm) SEMVER:introduced=0,fixed=3.9.4.
- Is there a fix for CVE-2024-21509?
- Yes. mysql2 (npm): upgrade to 3.9.4 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
- How is CVE-2024-21509 attacked?
- It is attacked over the network.
- Am I affected by CVE-2024-21509?
- Check whether you run mysql2 (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.
How to fix
- mysql2 (npm): upgrade to 3.9.4 or later
npm install mysql2@3.9.4
Technical details
The vulnerability exists in text_parser.js and binary_parser.js where the library dynamically generates JavaScript code to parse query results. The root cause is insufficient sanitization of user-controlled parameters (particularly supportBigNumbers, bigNumberStrings, and nestTables options) that are inserted into the dynamically generated parsing function via template strings. Additionally, the library uses prototype-based object creation for result objects without proper protection against prototype pollution. An attacker who can supply malicious configuration when creating a database connection or when executing a query (via query options) can inject arbitrary code into the generated parser function. No authentication is required if the attacker has a code path that accepts user-supplied connection parameters or query options. The attack achieves remote code execution or prototype pollution depending on the injection point. Version 3.9.4 and later include patches that improve parameter sanitization and use null-prototype object creation to prevent poisoning.
Affected products
- Node.js mysql2 mysql2 < 3.9.4
Identifiers
- CVE-2024-21509
- GHSA-49j4-86m8-q2jw
Timeline
- 2024-04-10: disclosed: Vulnerability publicly disclosed via GitHub Advisory
- 2024-04-09: patched: Fix released in version 3.9.4
- 2024-03-26: other: Technical details published by researcher Vsevolod Kokorin (Slonser)
References
- https://github.com/sidorares/node-mysql2/pull/2574
- https://github.com/sidorares/node-mysql2/commit/4a964a3910a4b8de008696c554ab1b492e9b4691
- https://blog.slonser.info/posts/mysql2-attacker-configuration
- https://github.com/sidorares/node-mysql2
- https://github.com/sidorares/node-mysql2/blob/fd3d117da82cc5c5fa5a3701d7b33ca77691bc61/lib/parsers/text_parser.js%23L134
- https://github.com/sidorares/node-mysql2/releases/tag/v3.9.4