Ajax 请求 CSRF 安全吗?
如果我的 Ajax 请求设置了 X-Requested-With 标头,如果该标头存在,我可以跳过 CSRF 检查吗?我可以确定它不能被伪造(通过用户会话)吗?
If my Ajax requests set a X-Requested-With header, can I just skip the CSRF check if this header is present? Can I be sure it cannot be forged (with the user session)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要您没有完全开放的 crossdomain.xml(您可能有这个 b/c,您在网站上托管 Flash 内容?)或者您的访问者使用的是旧浏览器;你应该比较安全。尽管我建议使用“crumb”令牌(cookie 中的随机值和请求中的相同值)。这个 b/c flash 可能会设置 X-Requested-With,我认为旧的 IE 版本也允许你这样做(但不确定这一点)。
对于“我可以跳过 CSRF 检查”,我假设您指的是这个 crumb/token 吗? B/c 检查 X-Requested-With 是一种检查 CSRF 的方法。
由于此标头是可选的,浏览器可能并不总是发送它,并且根据 此页面 他们似乎不是通过 SSL 来实现的。
As long as you don't have a wide open crossdomain.xml (you might have this b/c you host flash content on you site?) or your visitors have old browsers; you should be rather safe. Though I would recommend the use of a "crumb"-token (random value in cookie and the same value in the requests). This b/c flash may set the X-Requested-With and I think that old IE versions allow you to do too (not sure on this one though).
With "can I just skip the CSRF check" I assume you refer to this crumb/token? B/c checking X-Requested-With is a way of checking against CSRF.
Since this header is optional browsers may not always send it, and according to this page they seem to not do it over SSL.
这就是我们用 JQuery 解决问题的方法
http://mylifewithjava.blogspot.com/2010/11 /implicit-csrf-protection-of-ajax_22.html
This is how we solved the problem with JQuery
http://mylifewithjava.blogspot.com/2010/11/implicit-csrf-protection-of-ajax_22.html