Rails 4.2 : How disable encryption for cookies

937 views Asked by At

I recently upgraded my rails 3.2 app to rails 4.2. I face the issue of cookies set by new rails 4.2 is signed and encrypted which I don't won't because my application interacts with other rails 3 apps. I want to reintroduce old way to created cookies in 4.2.

1

There are 1 answers

0
Martin On

Thats true that Rails 4 CookieStore encrypt cookies by default:

If you have secret_key_base set, your cookies will be encrypted. This goes a step further than signed cookies in that encrypted cookies cannot be altered or read by users. This is the default starting in Rails 4.

It seems like there is no way to turn this off through config options so one way is to dont set secret_key_base.

Another is to define your custom session store with redefined CookieStore#cookie_jar method:

class ActionDispatch::Session::MyCustomStore < ActionDispatch::Session::CookieStore
  private

  def cookie_jar(request)
    request.cookie_jar.signed
  end
end

And in config.rb:

config.session_store :my_custom_store

This way your cookies will be held in signed jar like in Rails 3.