Rails csrf 令牌生命周期
我使用 Rails request_forgery_protection
机制来保护我的 POST 操作免受 CSRF 攻击,并使用验证码来保护 GET 操作。这样,如果有人在一个会话中发起两阶段攻击,使用当前令牌 GET-ting 表单,然后使用该令牌 POST-ing 伪造请求,他最终将面临验证码检查。
但我坚持这一点,因为 Rails 在会话结束之前不会重新生成 CSRF 令牌。这对我来说似乎不对,我认为应该在下一步操作之前更新令牌。我想知道也许我调整了什么错误?还有另一种方法可以做到这一点吗?
谢谢。
I use Rails request_forgery_protection
mechanism to protect my POST actions from CSRF attacks and captcha to protect the GET actions. This way if someone stages a two-phase attack within one session, GET-ting the form with the current token and then POST-ing a forged request with that token, he will eventually be faced with a captcha check.
I'm stuck with that though, because Rails doesn't regenerate the CSRF token until the end of session. That doesn't seem right to me, I'd think the token should be renewed before the next action. I'm wondering maybe I have tweaked something wrong? Is there another way of doing this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是否是一个好主意,但是您可以在从应用程序控制器内部获取请求时自己将令牌清零。
I've not sure if this is a good idea or not, but you can nil out the token yourself on get requests from inside your application controller.
如果没有为每个页面请求重新生成表单令牌,则这种保护很糟糕。我前段时间遇到过这个问题(在测试Redmine时,它是基于RoR的)并报告了这个问题,但没有重新测试它。
如果仍然没有重新生成,我建议您向RoR团队报告此情况。
In case form token is NOT regenerated for each page request, this protection is bad. I faced it sometime ago (when testing Redmine, which is RoR-based) and reported this issue, but didn't retested it.
If it's still not regenerated, I suggest you report this to RoR team.