Skip to content

SQL Injection

Description

The input values included in SQL queries need to be passed in safely. Bind variables in prepared statements can be used to easily mitigate the risk of SQL injection.

Examples

Insecure Code

scala
val query = "SELECT * FROM users WHERE name = '" + username + "'"

Secure Code

scala
val query = "SELECT * FROM users WHERE name = ?"; val pstmt = connection.prepareStatement(query); pstmt.setString(1, username)

Remediation

Use prepared statements with bind variables to prevent SQL injection attacks.

Rule Details

FieldValue
IDCODE-0054
CategoryInjection
SeverityHIGH
CWECWE-89
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagssql-injection, prepared-statement
OWASPA1:2017-Injection, A03:2021-Injection