【问题标题】:How can I check what csrf token is my rails controller expecting?如何检查我的 rails 控制器期望的 csrf 令牌?
【发布时间】:2014-11-13 16:43:06
【问题描述】:

我的生产服务器无法验证 csrf 令牌。 我在应用程序布局中添加了 csrf 的标签并通过标题发送它。 在我的请求调用中,我可以看到包含令牌。 但是我的 rails 应用程序无法验证它。

有什么方法可以检查我的控制器期望的 csrf 令牌是什么?

【问题讨论】:

    标签: ajax ruby-on-rails-3 csrf


    【解决方案1】:

    这是 ActionController 中用于检查真实性的代码的一部分

    form_authenticity_token == params[request_forgery_protection_token]
    

    form_authenticity_token 会给你你的控制器所期望的令牌。

    参考源码here

    【讨论】:

    • controller.form_authenticity_token 给我的错误是找不到控制器变量或方法,所以我将其删除并仅尝试了 form_authenticity_token 并且它有效!
    • 我已经接受了答案,但是请移除控制器,只要 form_authenticity_token 就可以了。
    猜你喜欢
    • 2015-10-27
    • 2015-04-17
    • 2014-07-18
    • 1970-01-01
    • 2017-04-06
    • 2013-03-27
    • 2011-05-02
    • 1970-01-01
    • 2022-08-18
    相关资源
    最近更新 更多