Zennoxa Shield
Rules / JavaScript / TypeScript
SHIELD-JS-002

SQL Injection via template literal

criticalJavaScript / TypeScriptCWE-89CVSS 9.8

What it detects

SQL query constructed with template literal interpolation may allow injection.

How to fix

Use parameterized queries with placeholders instead of template literals.

Vulnerable — Shield flags thisaccounts.js
const pool = require("./pool");

async function findByEmail(email) {
  const result = await pool.query(`SELECT * FROM accounts WHERE email = '${email}'`);
  return result.rows[0];
}

module.exports = { findByEmail };
Fixed — scans cleanaccounts.js
const pool = require("./pool");

async function findByEmail(email) {
  const result = await pool.query("SELECT * FROM accounts WHERE email = $1", [email]);
  return result.rows[0];
}

module.exports = { findByEmail };

Both snippets are verified against the shipped scanner: the vulnerable one triggers SHIELD-JS-002, the fixed one does not.

SHIELD-JS-002: SQL Injection via template literal — Zennoxa Shield