Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails:Sql注入问题?_Ruby On Rails_Ruby On Rails 3_Sql Injection - Fatal编程技术网

Ruby on rails Rails:Sql注入问题?

Ruby on rails Rails:Sql注入问题?,ruby-on-rails,ruby-on-rails-3,sql-injection,Ruby On Rails,Ruby On Rails 3,Sql Injection,我的控制器通过以下方式查找用户: @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 class用户{:

我的控制器通过以下方式查找用户:

@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
class用户

问:从SQL注入点来看,这安全吗?这是怎么回事,因为尽管我读了很多文章,但我对SQL注入一无所知。

在我自己的控制台中进行的一个快速实验表明,
find\u by\u 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_参数
创建标识符
是不相关的。

这是有道理的。我还有另一个sql查询,它在用户模型中使用where条件。我在索引操作中使用它从与当前用户相同的城市获取用户:
scope:same_city,lambda{{user}连接(:profile)。其中(:profiles=>{:city=>user.profile.city})
这会是一种威胁吗?对不起,我是一个彻头彻尾的noob(尽管我在这个网站上获得了所有的分数和徽章),这一点在