Aaron just released our latest open source project, EncryptedCookieStore. It turns out that the default cookie session store for Rails is insecure in the worst way: it is simply Base64-encoded (which is French for “plain text”). It is slightly obfuscated, giving the uninitiated a false sense of security, but to anybody who was seen Base64 before, they can probably see the woman in the red dress without even squinting. So, enter the EncryptedCookieStore, a plugin that will truly encrypt the data you are shoving in the cookie. Check it out!
EDIT: Per accurate comments, I need to restate something. The default cookie store is not “insecure in the worst way”; it is, rather, “insecure for the worst developers”. It was not MEANT to be secure (from reads). My point was that, some developers might just assume that the default for sessions would be server side storage, and the element of surprise might lead some of them to Do Bad Things™. That is all; sorry for the confusion.
Comments
The rails cookie store works as intended. Its not supposed to be obfuscated, the base64 you mentioned is just done because you cannot deliver valid cookies without it. Its totally tamper proof and hence secure as far as cookie attacks go. If your project requires encrypted sessions you are misusing sessions. That being said, if your project really requires secure and encrypted cookies both you should have a look at HMAC and not simple des encryption. HMAC was created for situations just like this.
It should sign it, too.
You make it sounds like it was an oversight to have the cookie session data be readable. It wasn’t. It’s that way by design. Base64 is used for serialization, not encryption. What’s important for most applications is not whether the content is secret or not but whether it can be forged (which it can’t be with the Rails cookie store and a proper secret).
I’m sure there are some off cases where you’ll consider storing values in the session that the user should not know about and your plugin will be great for that.
I’d take a step back to reconsider why you feel a need to store confidential values in the session first, though, and contemplate whether the session in any case is a good fit for that data.
You guys have to be really careful how you position this and be sure to educate your users (with documentation). Otherwise you’re at risk of doing more of a disservice than anything…
There may be a use case for it (I personally can’t think of one) but it’s really important that you educate potential users so that it’s not misunderstood and unintentionally abused.
Cheers, Clinton
Clinton—absolutely. The docs will clearly state the expected use case. And, I definitely wasn’t trying to imply that base64 was anything other than a transmission system for extended charsets; however, after teaching web development, it still amazes me how often people believe that because the string is obfuscated (in this case, merely transformed), it is safe from reads. Thanks for the comments!