aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/session
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-11-16 17:17:08 -0200
committerSantiago Pastorino <santiago@wyeworks.com>2012-11-16 17:29:26 -0200
commit8eefdb6d7056dc0d4d63a5c34a4b12701ba21c88 (patch)
tree18e732ac6913c5ee1cc211b19ce54396d569f3ef /actionpack/lib/action_dispatch/middleware/session
parentd4b9a3fa706034b1ac2a6f8a479a697d071517a9 (diff)
downloadrails-8eefdb6d7056dc0d4d63a5c34a4b12701ba21c88.tar.gz
rails-8eefdb6d7056dc0d4d63a5c34a4b12701ba21c88.tar.bz2
rails-8eefdb6d7056dc0d4d63a5c34a4b12701ba21c88.zip
Add UpgradeSignatureToEncryptionCookieStore
This allows easy upgrading from the old signed Cookie Store <= 3.2 or the deprecated one in 4.0 (the ones that doesn't use key derivation) to the new one that signs using key derivation
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/session')
-rw-r--r--actionpack/lib/action_dispatch/middleware/session/cookie_store.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
index 55a9314524..d7f83a1cc6 100644
--- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
@@ -93,5 +93,22 @@ module ActionDispatch
request.cookie_jar.encrypted
end
end
+
+ # This cookie store helps you upgrading apps that use +CookieStore+ to the new default +EncryptedCookieStore+
+ #
+ # To use this CookieStore set MyApp.config.session_store :upgrade_signature_to_encryption_cookie_store, key: '_myapp_session'
+ # in your config/initializers/session_store.rb
+ class UpgradeSignatureToEncryptionCookieStore < EncryptedCookieStore
+ private
+
+ def get_cookie(env)
+ signed_using_old_secret_cookie_jar(env)[@key] || cookie_jar(env)[@key]
+ end
+
+ def signed_using_old_secret_cookie_jar(env)
+ request = ActionDispatch::Request.new(env)
+ request.cookie_jar.signed_using_old_secret
+ end
+ end
end
end