【发布时间】:2014-09-02 15:30:21
【问题描述】:
如何防止 Google 在抓取网站时导致此错误?我对关闭“protect_from_forgery”不感兴趣,除非这样做是安全的。
[fyi] method=GET path=/users format=*/* controller=users action=show status=200 duration=690.32 view=428.25 db=253.06 time= host= user= user_agent=Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) session= params={""} ()
[hmm] Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding. (pid:)
[fyi] method=GET path=/users/123/flag format=*/* controller=users action=flag status=500 error='ActionController::InvalidCrossOriginRequest:Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.' duration=26.50 time= host= user= user_agent= session= params= (pid)
[omg] ActionController::InvalidCrossOriginRequest (Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.):
actionpack (4.1.4) lib/action_controller/metal/request_forgery_protection.rb:217:in `verify_same_origin_request'
控制器对此作出响应
respond_to do |format|
format.js { render template: 'users/flag', layout: "some_layout" }
end
我无法重新创建错误,当我通过浏览器执行此错误时,它似乎工作正常
到目前为止,我已经查看了以下资源,但大多数似乎都建议只是盲目地转向 CSRF 或没有得到答复。
- Using layout specific javascript in comfy leads to InvalidCrossOriginRequest
- Invalid Cross Origin Request After Upgrading to Rails 4.1
- How to avoid ActionController::InvalidCrossOriginRequest exception?
- Googlebot asks for png and then my whole Heroku site crashes. What is going on?
- https://github.com/rails/rails/pull/13345
- http://myownpirateradio.com/tag/rails-authentication-token/
- https://gist.github.com/aishek/8535082
- Why does Google prepend while(1); to their JSON responses?
- http://www.tsheffler.com/blog/?p=428
- http://edgeapi.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html
澄清: 该操作应受 CSRF 保护,但我想防止 Google 抓取它或在抓取页面时生成错误。即)我希望在不影响我的安全功能的情况下消除误报安全警告。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 cors csrf ruby-on-rails-4.1