简体   繁体   English

Rails 3.0.3和InvalidAuthenticityToken

[英]Rails 3.0.3 and InvalidAuthenticityToken

I am, from only some users, getting a InvalidAuthenticityToken exception. 我只有部分用户收到InvalidAuthenticityToken异常。 When I examine the error I can see that the request has "\\r\\n" added to the authenticity_token parameter (ie: "authenticity_token"=>"YfYr7bzy1MFzNHPvrSOIdrYuuAG3SHZy/OBJyV3yUSg=\\r\\n" ). 当我检查错误时,我可以看到请求已将"\\r\\n"添加到authenticity_token参数(即: "authenticity_token"=>"YfYr7bzy1MFzNHPvrSOIdrYuuAG3SHZy/OBJyV3yUSg=\\r\\n" )。

I don't know anything about the browser other than that it is IE7. 除了IE7,我对浏览器一无所知。

I have a feeling it is their firewall doing something to the request. 我觉得这是他们的防火墙对请求执行的操作。 I think a smart solution would be to create a Rack middleware that removes the line breaks if they exist. 我认为一个明智的解决方案是创建一个Rack中间件,以消除换行符(如果存在)。 Can anyone show me how that would be done? 谁能告诉我该怎么做? (I have NO Rack experience). (我没有机架经验)。

Regards, 问候,

Jacob 雅各布

I have investigated and I can find no solution for this. 我已经调查过,但找不到解决方案。 It is not IE or IE7 in particular. 并非特别是IE或IE7。 I ended up making the following middleware: 我最终制作了以下中间件:

class AuthenticityTokenFix
  def initialize(app)
    @app=app
  end

  def call(env)
    if env["rack.request.form_hash"] && env["rack.request.form_hash"]["authenticity_token"]
      env["rack.request.form_hash"]["authenticity_token"]=env["rack.request.form_hash"]["authenticity_token"].gsub("\r\n",'')
    end
    @app.call(env)
  end
end

That solved the problem. 那解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM