我尝试使用 gem rack-protection,我按照使用指南配置“config.ru”文件。当我尝试再次运行该应用程序时,我收到此错误“您需要在Rack::Protection::SessionHijacking之前设置会话中间件”。
# config.ru
require 'rack/protection'
use Rack::Protection
run MyApp
通过从回复中获取代码:
module YouApp
class Application < Rails::Application
config.middleware.use Rack::Protection::SessionHijacking
我将它放入我的 application.rb 并仍然收到内部服务错误,您需要在 Rack::Protection::SessionHijacking 之前设置会话中间件
这是 rake 中间件的输出:
use Rack::MiniProfiler
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007f9482a28910>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use ActionDispatch::Cookies
use ActiveRecord::SessionStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use ActionDispatch::Head
use Rack::ConditionalGet
use Rack::ETag
use ActionDispatch::BestStandardsSupport
use Warden::Manager
use Rack::Protection::SessionHijacking
use MetaRequest::Middlewares::MetaRequestHandler
use MetaRequest::Middlewares::Headers
use MetaRequest::Middlewares::AppRequestHandler
use OmniAuth::Strategies::Twitter
use OmniAuth::Strategies::Facebook
run Myapp::Application.routes
感谢任何人可以提供帮助并感谢您的时间。