ruby - 试图避免 "attack reported by Rack::Protection::AuthenticityToken"消息

标签 ruby sinatra padrino

我有一个新的 Padrino 0.13.1 项目,我托管在 AWS Elastic Beanstalk 工作线程实例上。工作实例有一个 cron 作业,它在我的 Padrino 应用程序中每 5 分钟调用一次 POST。我已将例程定义如下:

post :myroutine, :with => :myparams, :csrf_protection => false do
  # ... do some stuff
  status 200
end

我还配置了 /config/apps.rb 如下:

Padrino.configure_apps do
  set :session_secret, '...'
  set :protection, :except => :path_traversal
  set :protection_from_csrf, true
  set :allow_disabled_csrf, true
end

worker 实例发帖到 http://localhost:80/myroutine/somevar每 5 分钟。 nginx access.log 文件显示:

127.0.0.1 - - [21/Mar/2016:04:49:59 +0000] "POST /myroutine/01234 HTTP/1.1" 200 0 "-" "aws-sqsd/2.0" "-"

但在我的 AWS production.log 文件中,我也看到每 5 分钟出现一次:

WARN - 21/Mar/2016 04:49:59 attack reported by Rack::Protection::AuthenticityToken

奇怪的是,例程执行得很好,并且做了它应该做的事情。我只想阻止我的日志文件每 5 分钟被 Rack::Protection 错误填满。

这是因为某处配置错误的 csrf 设置还是错误?

最佳答案

是nginx反向代理设置导致的

可能会丢失http相关信息,导致session信息丢失。

https://github.com/znc/znc/issues/946 我只是在下面添加一行并且它有效:

proxy_set_header        X-Real_IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header        X-NginX-Proxy   true;
proxy_set_header        Host            $http_host;
proxy_set_header        Upgrade         $http_upgrade;
proxy_pass_header       Set-Cookie;

关于ruby - 试图避免 "attack reported by Rack::Protection::AuthenticityToken"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36125396/

相关文章:

c - ruby 1.9.2 中的 rfuzz 编译错误

ruby - Sinatra + DataMapper 的正确日志记录设置

ruby - Sinatra/Ruby - 内部服务器错误 : invalid byte sequence in US-ASCII. 由具有特殊字符的数组引起

mysql - ActiveRecord 在 Ruby 1.9.2-rc1 下以 ASCII-8Bit 返回数据

ruby-on-rails - 从 rake 任务运行两个 ruby​​ 脚本

ruby - 替换字符串中的单词 - Ruby

ruby - 将 Padrino 与 Sequel 结合使用,迁移可以创建单名 SQL 表吗?

postgresql - ActiveRecord - 搜索具有多个值的 Postgres 数组?

ruby - RSpec 规范没有运行?

ruby - 如何在 Padrino 中向 Mongoid 数据库添加索引?