首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法验证CRF令牌,但authenticity_token的格式参数

无法验证CRF令牌,但authenticity_token的格式参数
EN

Stack Overflow用户
提问于 2017-08-20 09:15:58
回答 2查看 343关注 0票数 0

当我发布时,我可以在表单参数中看到authenticity_token,但我收到了这个错误消息:

代码语言:javascript
复制
Started POST "/helloasdf/destroy_task?id=29" for 127.0.0.1 at 2017-08-19 21:12:14 -0400
Processing by TaskController#destroy_task as JS
  Parameters: {"authenticity_token"=>"XXXX", "id"=>"29", "task_url"=>"helloasdf"}
Can't verify CSRF token authenticity.
Completed 422 Unprocessable Entity in 1ms (ActiveRecord: 0.0ms)

(我将内标识更改为XXXX)。

到底是什么问题,还是我做错了什么?

我的ApplicationController有:

代码语言:javascript
复制
class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
EN

回答 2

Stack Overflow用户

发布于 2017-08-20 09:30:08

这在不久前发生在我身上,我只是不明白为什么当我试图写一些东西的时候,它突然开始抛出这个错误。经过大约5个小时的调试后,我意识到我已经阻止了localhost:3000的cookies,一个大胆的猜测是,你可能也是这样。

票数 0
EN

Stack Overflow用户

发布于 2017-08-20 18:11:34

另一种猜测是,假设您使用application/x-www-form-urlencoded内容类型,您没有正确转义令牌-因为它是base64编码的,所以它可以包含加号(+),加号将被解释为空格,并且将无法通过真实性检查。

还要检查这个答案:Rails 3 Authenticity tokens: How to prevent it from using spaces? (尽管不管问题是什么,一个简单的令牌encodeURIComponent()也应该足够了)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45777630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档