redline
HighSecuritysql-injection

SQL built from strings

SQL built from strings. Builds SQL by pasting values into the string. Any of them can rewrite the query.

This is how the comment reads inline, under the flagged line.

Why it matters

String-built SQL is the textbook injection bug. Escaping by hand misses cases; parameters don't.

What to do

Use bound parameters ($1, %s, ?) or the query builder's tagged template.

Examples

Flagged
db.query(`SELECT id FROM users WHERE email = '${email}'`);
Better
db.query("SELECT id FROM users WHERE email = $1", [email]);

What it catches

It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

db.query(`SELECT * FROM t WHERE id = ${id}`);
src/app.py
cur.execute(f"SELECT * FROM t WHERE id = {id}")

Left alone

db.query("SELECT id FROM t WHERE id = $1", [id]);
db.query(sql`SELECT id FROM t WHERE id = ${id}`);
notes.push(`delete ${name}`);

Research

SQL built by string concatenation or interpolation. Untrusted input is parsed as SQL.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "sql-injection"
    ],
    "severity": {
      "sql-injection": "low"
    }
  }
}

Read the source or report a false positive.