Skip to content

SQL Injection

Description

SQL Injection is a critical vulnerability that can lead to data or system compromise. By dynamically generating SQL query strings, user input may be able to influence the logic of the SQL statement. This could lead to an adversary accessing information they should not have access to, or in some circumstances, being able to execute OS functionality or code.

Examples

Insecure Code

ruby
User.where("id = #{params[:id]}")

Secure Code

ruby
user_id = params[:id]
User.where("id =?", user_id)

Remediation

Use parameterized queries or the ActiveRecord query interface, which ensures that inputs are properly escaped, preventing SQL injection attacks. Avoid string interpolation or concatenation with user-controlled input for constructing SQL queries.

Rule Details

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

References