Encrypted Cookie Store¶ ↑
Important Notice¶ ↑
encrypted-cookies
has breaking changes in v1.0. Session cookies written with v0.3.* will no be able to be read by v1.0. Fix your version of encrypted-cookie-store
to v0.3.2 if you don’t want to make the switch. See encrypted-cookies
if you want more information about the change.
Description¶ ↑
Encrypted cookie based session for Rails 3.
Summary¶ ↑
There are times when one must store things in a session that are not necessarily meant for anyone’s eyes. Database or memcache sessions should be used for highly confidential information, however, for information that is not mission critical but still could benefit from a little discretion, an encrypted session cookie might be a good option. EncryptedCookieStore is a drop in replacement for the built in ActionDispatch::Session::CookieStore. encrypted-cookie-store
uses the encrypted-cookies
gem to store the session information in an encrypted and signed cookie, instead of only using a signed cookie, as ActionDispatch::Session::CookieStore does.
Usage¶ ↑
Enabling an EncryptedCookieStore is easy. Just add the gem requirement to your Gemfile
:
gem 'encrypted-cookie-store'
Then update then session store you are using in config/initializers/session_store.rb
:
AppName::Application.config.session_store :encrypted_cookie_store, :key => '_app_name_session'
Writing and reading from the session is the same:
session[:tid_bit] = "of information" session[:tid_bit] # => "of information"
Disclaimer¶ ↑
This is provided as is. No guarantee is given for the security of the data written or read by this software. This has not been tested for cryptographic rigor. Use at your own discretion and risk. This should not be only level of security you use for your data. It uses ActiveSupport::MessageEncryptor to encrypt and ActiveSupport::MessageVerifier to sign the cookie values, so it is at best as secure as these two libraries. Be sure to keep your AppName::Application.config.secret_token safe and secret, as both of the above libraries use it in your Rails application.
License¶ ↑
Copyright © 2011 Les Fletcher
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.