flawopen.com/SQL Injection in Ruby/ActiveRecord where()
No. where("id = #{params[:id]}") is the single most common Rails SQL injection pattern — it compiles and runs exactly like normal ActiveRecord code, which is exactly why it doesn't stand out in review.
User.where(
"id = #{params[:id]}"
)
User.where(id: params[:id])
# or, for more complex conditions:
User.where("id = ?", params[:id])
The interpolated version doesn't look like raw SQL — it's still a call to .where(), the same method used everywhere else in the codebase. The danger is entirely inside the string, in the #{} interpolation, which is easy to skim past.
grep -rn 'where("' app/ | grep '#{'
Only for simple equality conditions — anything involving operators or ranges needs the ? bound-parameter form instead.