【问题标题】:How to properly protect SQL injection in rails controller如何正确保护 Rails 控制器中的 SQL 注入
【发布时间】:2016-01-09 20:27:33
【问题描述】:

我有一个控制器,我想知道 Rails 是否已经解析了参数并阻止了 SQL 注入。这是我的控制器的样子:

class V1::JobsController < ApplicationController
  include ActionController::HttpAuthentication::Token::ControllerMethods
  include ActionController::Serialization
  before_action :set_job, only: [:show, :update, :destroy]
  before_action :authorize_api_key, only: [:create]

  # GET /jobs
  def index
    status = (params[:status]) ? params[:status] : 'pending'
    @jobs = Job.where(publisher_id: params[:publisher_id], status: status)

    render json: @jobs
  end

  ...
end

这样安全吗?

【问题讨论】:

    标签: ruby-on-rails rails-api ruby-on-rails-5


    【解决方案1】:

    是的,您的代码是安全的。

    例如,不要使用这样的东西:

    Project.where("name = '#{params[:name]}'")  # DON'T USE
    

    For more information

    【讨论】:

      猜你喜欢
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多