SQL Injection Vulnerability in node-mysql
Summary
CVE-2015-9244: Keys of objects in mysql node module v2.0.0-alpha7 and earlier are not escaped with mysql.escape() which could lead to SQL Injection. Affects node-mysql versions < 2.0.0~alpha8-1. Fixed in 2.0.0~alpha8-1. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The node-mysql package is a popular Node.js module used for interacting with MySQL databases. It provides a convenient API for executing SQL queries and managing database connections. However, versions up to 2.0.0-alpha7 of the package suffer from a SQL injection vulnerability. This vulnerability arises from the failure to properly escape keys of objects, which can lead to malicious SQL queries being executed.
Vulnerability Detail
The SQL injection vulnerability in node-mysql (CVE-2015-9244) allows an attacker to inject malicious SQL code into queries executed by the application. By manipulating the keys of objects passed to the mysql module, an attacker can craft SQL queries that can bypass input validation and execute arbitrary SQL commands. This can result in unauthorized data access, data manipulation, or even the complete compromise of the database server.
How To Fix
Minimum fixed version
2.0.0~alpha8-1
This is the first release that contains the fix.
sudo apt-get install --only-upgrade node-mysql
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If upgrading to the fixed version is not immediately feasible, a temporary workaround can be implemented by manually escaping the keys before passing them to the mysql module. This can be done using a function similar to mysql.escape(), which properly escapes the keys to prevent SQL injection. Here's an example of how the workaround can be implemented in JavaScript:
const mysql = require('mysql');
function escapeKeys(obj) {
const escapedObj = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
escapedObj[mysql.escapeId(key)] = obj[key];
}
}
return escapedObj;
}
const query = `SELECT * FROM users WHERE ${mysql.escape(escapeKeys(userInput))}`;
Conclusion
The SQL injection vulnerability in node-mysql (CVE-2015-9244) poses a significant risk to applications using vulnerable versions of the package. It is crucial to promptly upgrade to the fixed version (2.0.0-alpha8-1 or later) or implement the provided workaround to mitigate the risk of SQL injection attacks. For further assistance or support in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for node-mysql →
FAQ
The SQL injection vulnerability in node-mysql can have severe consequences. An attacker can exploit this vulnerability to execute arbitrary SQL commands, potentially leading to unauthorized data access, data manipulation, or even the complete compromise of the database server.
You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability. Vulert analyzes your package-lock.json file and provides real-time alerts for open-source vulnerabilities, including this SQL injection vulnerability in node-mysql.
Yes, a fix is available for this vulnerability. It is recommended to upgrade to version 2.0.0-alpha8-1 or later of the node-mysql package, which addresses the SQL injection issue by properly escaping keys.
Yes, if upgrading the package is not immediately feasible, you can implement a temporary workaround by manually escaping the keys before passing them to the mysql module. Refer to the 'workaround' section for an example of how to implement this workaround.
You can find more information about this vulnerability, including technical details and the CVE identifier, in the vulnerability report available at https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2015-9244.json.
Related vulnerabilities
Recent vulnerabilities recorded for node-mysql.