CVE-2019-10757: SQL Injection in knex
Summary
CVE-2019-10757: SQL Injection in knex. Affects knex versions < 0.19.5. Fixed in 0.19.5. 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 'knex' package is an SQL query builder for Node.js that supports multiple database systems. It provides a fluent interface for building and executing SQL queries. The package is widely used in web applications and APIs to interact with databases. However, versions before 0.19.5 are vulnerable to SQL Injection attacks when using the MSSQL dialect. This vulnerability allows attackers to craft malicious queries that can be executed on the host database.
Vulnerability Detail
The vulnerability in knex arises from incorrect escaping of identifiers in the MSSQL dialect. This allows an attacker to manipulate the SQL query by injecting malicious input. By exploiting this vulnerability, an attacker can perform unauthorized actions on the database, such as reading, modifying, or deleting data. The impact of this vulnerability can be severe, depending on the privileges of the database user. The vulnerability has been assigned a CVSSv3 score of 9.8, indicating its critical severity.
How To Fix
Minimum fixed version
0.19.5
This is the first release that contains the fix.
npm install knex@0.19.5
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, developers can manually sanitize and validate user input before using it in SQL queries. This involves properly escaping special characters and using parameterized queries or prepared statements to separate the SQL code from the user input. Here's an example of using parameterized queries with 'knex' to mitigate the vulnerability:
const knex = require('knex');
const query = knex('users').where('username', req.body.username).where('password', req.body.password);
// Execute the query
query.then((result) => {
// Handle the result
}).catch((error) => {
// Handle the error
});
Conclusion
In conclusion, the 'knex' package versions before 0.19.5 are vulnerable to SQL Injection attacks in the MSSQL dialect. It is crucial for developers to upgrade to the latest version of 'knex' and ensure that all vulnerable instances are updated. Additionally, implementing proper input validation and using parameterized queries or prepared statements can help mitigate the risk of SQL Injection attacks. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for knex →
FAQ
The vulnerability allows attackers to execute arbitrary SQL queries on the host database, potentially leading to unauthorized access, data manipulation, or data loss.
Versions of 'knex' before 0.19.5 are vulnerable to this SQL Injection attack.
Yes, upgrading to version 0.19.5 or later of the 'knex' package fixes this vulnerability.
Developers can manually sanitize and validate user input before using it in SQL queries. Additionally, using parameterized queries or prepared statements can help prevent SQL Injection attacks.
The CVSSv3 score for this vulnerability is 9.8, indicating its critical severity.
References
Related vulnerabilities
Recent vulnerabilities recorded for knex.