我现在正在用Ruby on Rails开发web API。当Rails应用程序接收到没有任何csrf令牌的POST请求时,将会出现以下错误消息。因为应用程序没有视图。
WARNING: Can't verify CSRF token authenticity
所以我的问题是,在这种情况下,我如何安全地逃脱csrf令牌检查?
非常提前感谢您。
发布于 2013-02-23 22:21:12
您可以通过添加
skip_before_filter :verify_authenticity_token
到你的控制器。这样,所有传入控制器的请求都会跳过:verify_authenticity_token过滤器。
发布于 2015-12-16 06:59:44
对于Rails4,应该是
skip_before_action :verify_authenticity_token, only: [:one_or_two_actions_here]
请注意,应避免在控制器的所有操作上跳过verify_authenticity_token,而应使用选项only
仅跳过必须跳过的位置。See the docs
https://stackoverflow.com/questions/15040964
复制相似问题