Skip to content

SQL Injection via Untrusted Input

Description

Untrusted input concatenated with raw SQL query can result in SQL Injection, allowing attackers to execute arbitrary SQL commands and potentially extract or modify sensitive data.

Examples

Insecure Code

javascript
const sql = 'SELECT * FROM users WHERE name = \' + req.query.name + '\';
const results = db.query(sql);

Secure Code

javascript
const sql = 'SELECT * FROM users WHERE name =?';
const results = db.query(sql, [req.query.name]);

Remediation

Use parameterized queries or prepared statements to separate code from user input, and ensure that all user input is properly sanitized and validated.

Rule Details

FieldValue
IDCODE-0361
CategoryInjection
SeverityCRITICAL
CWECWE-89
ConfidenceHIGH
ImpactHIGH
LikelihoodHIGH
ExploitabilityEASY
TagsSQL Injection, Node.js, Database Security
OWASPA1:2017-Injection, A03:2021-Injection