我的控制器使用以下命令查找用户:
@user = User.find_by_identifier!(params[:id])在我的用户模型中,我有
class User < ActiveRecord::Base
def to_param
identifier
end
private
def create_identifier
SecureRandom.urlsafe_base64(9)
end
end问:这对于SQL注入点是安全的吗?以及如何做到这一点,因为尽管我阅读了各种文章,但对SQL注入一无所知。
发布于 2013-03-18 13:55:23
在我自己的控制台上进行的一个快速实验表明,find_by_identifier!对于SQL注入是安全的。
irb(main):005:0> User.find_by_email! "i am sneaky '; drop table woot;"
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'derp ''; drop table woot;' LIMIT 1请注意,生成的SQL查询如何转义恶意的单引号。
我认为你模型中的to_param和create_identifier是无关紧要的。
https://stackoverflow.com/questions/15470457
复制相似问题