Unsanitized user input in SQL query detected.
- Rule ID: ruby_rails_sql_injection
- Languages: ruby
- Source: sql_injection.yml
Description
Including unsanitized data, such as user input or request data, in raw SQL queries makes your application vulnerable to SQL injection attacks.
Remediations
❌ Avoid raw queries, especially those that contain unsanitized user input:
User.where("user.email = #{params[:email]}")
✅ Use the ActiveRecord API wherever possible:
User.where(email: params[:email])
✅ Use bind variables:
User.where("user.email = ?", [params[:email]])
✅ Santize the value manually:
User.where(sanitize_sql(["user.email = ?", params[:email]]))
Resources
- OWASP SQL injection explained
- OWASP SQL injection prevention cheat sheet
- Securing Rails applications - SQL injection
Associated CWE
OWASP Top 10
Ready to take the next step? Join the Bearer Cloud waitlist.