编辑>>我也在博客文章中发布了此答案:http:
//zadasnotes.blogspot.com/2010/11/rails-3-forgery-csrf-protection-
for.html [
archive.org ]编辑2 >>在Rails 3.0.4中对此进行了更改。请参阅以下后续帖子:http:
//zadasnotes.blogspot.com/2011/02/rails-forgery-csrf-protection-for-
ajax.html [
archive.org ]
在研究了一段时间之后,我决定深入研究Rails代码文档以进行查找。
从这里开始:http :
//api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html#method-
i-
form_authenticity_token
protect_from_forgery* 在 verify_authenticity_token 上添加一个
before_filter ,如下所示: *
# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 9595: def verify_authenticity_token96: verified_request? || raise(ActionController::InvalidAuthenticityToken)97: end
还有 经验证的请求? 显示在这里:
# File actionpack/lib/action_controller/metal/request_forgery_protection.rb, line 104: def verified_request?105: !protect_against_forgery? || request.forgery_whitelisted? ||106:form_authenticity_token == params[request_forgery_protection_token]107: end
最后 request.forgery_whitelisted? :
# File actionpack/lib/action_dispatch/http/request.rb, line 126126: def forgery_whitelisted?127: get? || xhr? || content_mime_type.nil? || !content_mime_type.verify_request?128: end
通知 xhr? 。xmlHttpRequest被列入白名单,并且不在protect_from_forgery列表中。因此看来这是设计使然。
在进一步研究xmlHttpRequests之后,似乎在跨域运行它们方面存在限制,这使得不必在xhr上应用csrf检查。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)