CVE-2016-20018: SQL Injection Vulnerability in Knex.js

knex Updated 02 Oct 2025

Summary

19/12/2022
Yes i
High
7.5

CVE-2016-20018: Knex.js has a limited SQL injection vulnerability. Affects knex versions < 2.4.0. Fixed in 2.4.0. How to fix ↓

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

Knex.js is a popular query builder for Node.js that provides a flexible and intuitive way to interact with databases. It allows developers to write SQL queries using JavaScript syntax, making it easier to build and maintain database queries. However, versions up to 2.3.0 of Knex.js are vulnerable to a limited SQL injection attack, which can bypass the WHERE clause of a SQL query. This vulnerability has been assigned the CVE identifier CVE-2016-20018 and has a CVSS score of 7.5, indicating a high severity level.

Vulnerability Detail

The SQL injection vulnerability in Knex.js allows an attacker to manipulate the SQL query by injecting malicious input. By crafting a specially crafted input, an attacker can bypass the WHERE clause of a SQL query, potentially leading to unauthorized access, data leakage, or other malicious activities. This vulnerability has been fixed in version 2.4.0 of Knex.js.

How To Fix

Latest published version: 3.3.0 as of 23 Oct 2026

npm install knex@3.3.0

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

2.4.0

This is the first release that contains the fix.

npm install knex@2.4.0

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If upgrading to the latest version is not immediately feasible, developers can implement input validation and parameterized queries to mitigate the risk of SQL injection attacks. By validating and sanitizing user input and using parameterized queries, the application can prevent malicious input from being executed as part of the SQL query. Here is an example of using parameterized queries with Knex.js:

const knex = require('knex');

const query = knex('users').where('username', '=', req.body.username).toString();

// Use parameterized query
const result = await knex.raw(query, [req.body.username]);

Conclusion

In conclusion, Knex.js versions up to 2.3.0 are vulnerable to a limited SQL injection attack. This vulnerability can be exploited to bypass the WHERE clause of a SQL query, potentially leading to unauthorized access or data leakage. To mitigate this risk, developers should upgrade to version 2.4.0 or higher of Knex.js. If immediate upgrade is not possible, implementing input validation and parameterized queries can provide temporary protection. For further support on vulnerability remediation, you can reach out to DevNack.com.

See every vulnerability recorded for knex →

Share this vulnerability

FAQ

Knex.js is a query builder for Node.js that allows developers to write SQL queries using JavaScript syntax. It provides a flexible and intuitive way to interact with databases.

A SQL injection vulnerability occurs when an application does not properly validate or sanitize user input before including it in a SQL query. This allows an attacker to manipulate the query and potentially execute arbitrary SQL commands.

The SQL injection vulnerability in Knex.js can allow an attacker to bypass the WHERE clause of a SQL query, potentially leading to unauthorized access, data leakage, or other malicious activities.

Yes, this vulnerability has been fixed in version 2.4.0 of Knex.js. It is recommended to upgrade to the latest version to mitigate the risk.

To protect your application from SQL injection attacks, you should implement input validation and use parameterized queries. Input validation ensures that user input is properly sanitized, while parameterized queries prevent malicious input from being executed as part of the SQL query.

Related vulnerabilities

Recent vulnerabilities recorded for knex.

How To Fix

Latest published version: 3.3.0 as of 23 Oct 2026

npm install knex@3.3.0

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

2.4.0

This is the first release that contains the fix.

npm install knex@2.4.0

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback