Why it matters
The caller controls part of the statement, so they can change what it selects, updates or deletes.
How to fix it
Keep the statement text constant and pass the request value in the driver's parameter array (the second argument of query).
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
const express = require("express");
const app = express();
app.get("/orders", async (req, res) => {
const sql = "SELECT id FROM orders WHERE status = '" + req.query.status + "'";
const rows = await app.locals.db.query(sql);
res.json(rows);
});const express = require("express");
const app = express();
app.get("/orders", async (req, res) => {
const rows = await app.locals.db.query(
"SELECT id FROM orders WHERE status = $1",
[req.query.status],
);
res.json(rows);
});What TrustIvan reads
Runs on repository scans of JavaScript source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- Eval use (JavaScript)
JavaScriptSeverity: High
trustowl-javascript-eval-use - Command injection from request input (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-taint-command-injection - Path traversal from request input (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-taint-path-traversal - SSRF from request input (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-taint-ssrf - Reflected XSS from request input (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-taint-reflected-xss - DOM XSS from request input (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-taint-dom-xss
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation