sidecloq icon indicating copy to clipboard operation
sidecloq copied to clipboard

Fix issue where the Rack session is invalid for rake web

Open Fryguy opened this issue 2 years ago • 1 comments

Without this, you will get an Internal Server Error stating:

Sidekiq::Web needs a valid Rack session for CSRF protection. If this is a Rails app,
make sure you mount Sidekiq::Web *inside* your application routes:

Rails.application.routes.draw do
  mount Sidekiq::Web => "/sidekiq"
  ....
end

If this is a Rails app in API mode, you need to enable sessions.

  https://guides.rubyonrails.org/api_app.html#using-session-middlewares

If this is a bare Rack app, use a session middleware before Sidekiq::Web:

  # first, use IRB to create a shared secret key for sessions and commit it
  require 'securerandom'; File.open(".session.key", "w") {|f| f.write(SecureRandom.hex(32)) }

  # now use the secret with a session cookie middleware
  use Rack::Session::Cookie, secret: File.read(".session.key"), same_site: true, max_age: 86400
  run Sidekiq::Web

Fryguy avatar Aug 05 '22 14:08 Fryguy

Travis seems not to be working here, but if you merge https://github.com/mattyr/sidecloq/pull/40 I can rebase this on top to use GitHub Actions.

Fryguy avatar Aug 05 '22 20:08 Fryguy

i believe this is now fixed in main! thanks

mattyr avatar Nov 05 '23 02:11 mattyr