我有一个新的 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/