
When an include is not surrounded by empty lines, its content is inlined on the same line as the adjacent content. That can lead to broken tags and other display issues. This PR fixes all such includes and introduces a validation step that forbids introducing the same problem again.
45 lines
933 B
Plaintext
45 lines
933 B
Plaintext
== How to fix it in Knex
|
|
|
|
=== Code examples
|
|
|
|
include::../../common/fix/code-rationale.adoc[]
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,javascript,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
async function index(req, res) {
|
|
const knex = req.app.get('knex');
|
|
|
|
let loggedInUser = await knex('users')
|
|
.whereRaw(`user = '${req.query.user}' and pass = '${req.query.pass}'`); // Noncompliant
|
|
|
|
res.send(JSON.stringify(loggedInUser));
|
|
res.end();
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,javascript,diff-id=1,diff-type=compliant]
|
|
----
|
|
async function index(req, res) {
|
|
const knex = req.app.get('knex');
|
|
|
|
let loggedInUser = await knex('users')
|
|
.where('user', req.query.user)
|
|
.where('pass', req.query.pass);
|
|
|
|
res.send(JSON.stringify(loggedInUser));
|
|
res.end();
|
|
}
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
:secure_feature: Knex
|
|
:unsafe_function: whereRaw()
|
|
|
|
include::../../common/fix/secure-by-design.adoc[]
|
|
|