Junglewise Threat Intelligence

CVE-2024-21509: mysql2 prototype poisoning in result parser

CVE-2024-21509 · Severity: low · CVSS 3.1 · Published 2024-04-10

Executive brief

mysql2 is a popular Node.js library that connects JavaScript applications to MySQL databases. The library generates dynamic code to parse database query results, but failed to properly sanitize user-supplied configuration parameters before injecting them into that code. An attacker who can control database connection settings or query configuration (e.g., through a multi-tenant application) can inject malicious code that executes when results are parsed, compromising the application server or exposing sensitive data from other users.

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

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

Related threats