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

kotlin
String query = "SELECT * FROM users WHERE name = '" + username + "'";

Secure Code

kotlin
String query = "SELECT * FROM users WHERE name = ?"; PreparedStatement statement = connection.prepareStatement(query); statement.setString(1, username);

Remediation

Use prepared statements with bind variables to prevent SQL injection.

Rule Details

FieldValue
IDCODE-0324
CategoryInjection
SeverityCRITICAL
CWECWE-89
ConfidenceHIGH
ImpactHIGH
LikelihoodHIGH
ExploitabilityEASY
Tagssql-injection, prepared-statement
OWASPA1:2017-Injection, A03:2021-Injection