Rails SQL 注入? [英] Rails SQL injection?
本文介绍了Rails SQL 注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Rails 中,当我想根据用户给定的值查找并避免 SQL 注入(转义撇号等)时,我可以执行以下操作:
In Rails, when I want to find by a user given value and avoid SQL injection (escape apostrophes and the like) I can do something like this:
Post.all(:conditions => ['title = ?', params[:title]])
我知道这样做的不安全方法(可能是 SQL 注入)是这样的:
I know that an unsafe way of doing this (possible SQL injection) is this:
Post.all(:conditions => "title = #{params[:title]}")
我的问题是,以下方法是否可以防止 SQL 注入?
My question is, does the following method prevent SQL injection or not?
Post.all(:conditions => {:title => params[:title]})
推荐答案
是的,确实如此.只有第二个是危险的.
Yes, it does. Only the second one is dangerous.
这篇关于Rails SQL 注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文