# CVE-2024-21511: mysql2 for Node arbitrary code injection via timezone parameter

Source: https://junglewise.ai/threats/cve-2024-21511-mysql2-for-node-arbitrary-code-injection-via-timezone-parameter  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2024-04-23. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2024-21511 · Severity: low · CVSS 3.1 · Published 2024-04-23

mysql2 is a popular MySQL database driver for Node.js applications. A vulnerability in how it handles the timezone parameter allows attackers to inject and execute arbitrary code on the server running the application. An attacker who can influence database connection parameters could gain complete control over the affected system and steal sensitive data or disrupt operations.

Technologies: [mysql2 (npm)](https://junglewise.ai/threats/technologies/mysql2). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2024-21511 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2024-21511 being exploited in the wild.

**How severe is CVE-2024-21511?** Low severity, with a CVSS score of 3.1, published 23 April 2024.

**Which products and versions are affected?** mysql2 (npm) <3.9.7.

**Is there a fix for CVE-2024-21511?** A patch was published on 2024-04-21: Fix released in version 3.9.7 Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2024-21511 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2024-21511?** 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.

## Technical details

The vulnerability is a code injection flaw (CWE-94) in the mysql2 Node.js package affecting versions before 3.9.7. The readCodeFor function fails to properly sanitize the timezone parameter when constructing date/time function calls, allowing attackers to inject malicious JavaScript code. The attack requires the ability to control the timezone parameter in a database connection or query object, but does not require prior authentication or user interaction. An attacker can exploit this to execute arbitrary Node.js code with the privileges of the application process, leading to complete system compromise including code execution, data exfiltration, and denial of service. The fix was released in version 3.9.7 (April 21, 2024) via commit 7d4b098, which sanitizes the timezone parameter value before use.

## Affected products

- npm mysql2 <3.9.7

## Identifiers

- CVE-2024-21511
- GHSA-4rch-2fh8-94vw

## Timeline

- 2024-04-21: disclosed: Vulnerability discovered by zhaoyudi (Nebulalab)
- 2024-04-21: patched: Fix released in version 3.9.7
- 2024-04-23: advisory: Public advisory published (GHSA-4rch-2fh8-94vw / CVE-2024-21511)

## References

- [https://github.com/sidorares/node-mysql2/pull/2608](https://github.com/sidorares/node-mysql2/pull/2608)
- [https://github.com/sidorares/node-mysql2/commit/7d4b098c7e29d5a6cb9eac2633bfcc2f0f1db713](https://github.com/sidorares/node-mysql2/commit/7d4b098c7e29d5a6cb9eac2633bfcc2f0f1db713)
- [https://github.com/sidorares/node-mysql2](https://github.com/sidorares/node-mysql2)
- [https://github.com/sidorares/node-mysql2/releases/tag/v3.9.7](https://github.com/sidorares/node-mysql2/releases/tag/v3.9.7)
- [https://security.snyk.io/vuln/SNYK-JS-MYSQL2-6670046](https://security.snyk.io/vuln/SNYK-JS-MYSQL2-6670046)

## Related threats

- [MySQL2 auth plugin downgrade to mysql_clear_password leaks plaintext credentials](https://junglewise.ai/threats/mysql2-auth-plugin-downgrade-to-mysql-clear-password-leaks-plaintext-4f504449)
- [MySQL2 unbounded zlib inflate decompression-bomb DoS](https://junglewise.ai/threats/mysql2-unbounded-zlib-inflate-decompression-bomb-dos-1b8791b1)
- [mysql2 prototype pollution in nestTables](https://junglewise.ai/threats/cve-2024-21512-mysql2-prototype-pollution-in-nesttables)
- [mysql2 remote code execution in readCodeFor function](https://junglewise.ai/threats/cve-2024-21508-mysql2-remote-code-execution-in-readcodefor-function)
- [mysql2 prototype poisoning in result parser](https://junglewise.ai/threats/cve-2024-21509-mysql2-prototype-poisoning-in-result-parser)
