Rails' CookieStore isn't broken
coffeepowered.net
coffeepowered.net
Emotions run high, on both sides, and I've been on both sides of it at various points in my life. I recognize the patterns of the bad arguments made by both sides (by A: "of course you don't do that," "this requires something else bad to happen," "that's a problem with bad coders", "you are an idiot"; and by B: "every potential issue is worth full attention," "you should always stop your developers from breaking things," "you can't fix things with obscurity!!!1," "you'll be sorry", "you are an idiot.").
My hope is that expiration will be soon baked-in (or easier to bake in), after reading https://github.com/rails/rails/pull/11168
Completely agreed - that's the gist of the DB bits there. Right now, you can terminate a compromised AR-backed session by logging out, but if you lose that session ID, then you have no control over the compromised session. If someone jacks your SID while you're on a public terminal, using ARStore alone isn't going to save you.
Who in late 2013 (with enough clue to care about this issue) is still using non-secure-flag cookies for anything even remotely important?!
local_env = !(Rails.env.test? || Rails.env.development?)
MyApp::Application.config.session_store(:cookie_store, {
key: '_my_app_session',
secure: local_env, # ... or just true
})
Yes, somebody who has gone looking for this can find it, but I'd argue that Rails should at least give you the secure: ... option in a comment block. Anything less is just inviting people to get bitten by the lack of it.What do you gain by using the cookie store with this database component, over just using the active record store to begin with? (The ActiveRecord store used to be the default back in... Rails 2.0?)
I think it's still worthwhile to use CookieStore even if you're going to go to the DB, because:
1. You only do DB round-trips for cookies that contain a valid user ID, and you're going to be pulling that user record anyway, so the net effect is a few extra bytes over the wire on DB work you were going to be doing anyway. Critically, this means that anonymous users aren't going to be generating sessions that you have to store and validate on every page with a form (as forms use csrf_token which generates a session!)
2. Additionally, less data over the wire between the app and DB. You're going to have a small list of active sessions; you could enforce that as a to a small number to ensure it stays small.
3. You retain CookieStore's invulnerability to session fixation.
4. No sweeping!
You can still put most of the work on the client, and only keep the verification bits on the server. Of course, the same technique is applicable to DB-backed stores as well, as a means to provide a mechanism for users to manage their sessions.
Also, doesn't cryptographically signing (or fully encrypting, in Rails 4) the cookie just add more time to processing than using a database? I always assumed cryptography is slower than IO
Cryptography is a CPU-bound operation that often has specialized hardware support. Here's a rule of thumb: in modern computing, IO incurs a greater cost than pretty much anything you can do locally on-CPU. IO is incredibly expensive: cryptography, not so much. If you pipeline your crypto operations and disk fetches, you won't increase response latency at all.
[1] http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
Useful link: http://jamescrisp.org/2013/08/04/moving-to-https-rails-force...
It's as simple as that. Never assume that anything transmitted over HTTP is safe, because that assumption will come back to bite you.
Are you suggesting not using SSL?
If not, can you clarify your point?
Thanks.
http://guides.rubyonrails.org/action_controller_overview.htm...