【发布时间】:2011-02-13 02:01:50
【问题描述】:
请帮助 Rails 中的新手 :) 我的 ApplicationController 类中有 protect_from_forgery 调用(默认情况下),但没有属性。
基本上是代码:
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery
helper_method :current_user_session, :current_user
filter_parameter_logging :password, :password_confirmation
我认为它应该做的是:它应该阻止任何没有正确authenticity_token 的 POST 请求。但是当我像下面这样使用 jQuery 发送 post 请求时,它工作正常(数据库中执行了更新语句)!
$.post($(this).attr("href"), { _method: "PUT", data: { test: true } });
我在控制台中看到发送的参数中没有authenticity_token,但请求仍然被认为是有效的。这是为什么呢?
UPD 在 config/environments/development.rb 中找到配置设置
config.action_controller.consider_all_requests_local = true
由于DEV环境和本地请求,这些jQuery post请求都OK。
【问题讨论】:
标签: ruby-on-rails request authenticity-token protect-from-forgery