栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Rails 3 AJAX请求真实性令牌被忽略

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Rails 3 AJAX请求真实性令牌被忽略

编辑>>我也在博客文章中发布了此答案: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检查。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/485329.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号