1

我有一个控制器,我想知道 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

这是安全的吗?

4

1 回答 1

1

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

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

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

了解更多信息

于 2016-01-09T21:11:55.773 回答