aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware
diff options
context:
space:
mode:
authorMichael Coyne <mikeycgto@gmail.com>2017-09-24 13:38:27 -0400
committerMichael Coyne <mikeycgto@gmail.com>2017-09-27 11:37:23 -0400
commit0fb6b2d572b50493e3d69cea17eb60d3c91a0dbd (patch)
tree0ef56f9a61ce984dbbf7ac60592c006327ef00b6 /actionpack/lib/action_dispatch/middleware
parent9befc197f926272abbba5a1ca1323ce4f15ebd10 (diff)
downloadrails-0fb6b2d572b50493e3d69cea17eb60d3c91a0dbd.tar.gz
rails-0fb6b2d572b50493e3d69cea17eb60d3c91a0dbd.tar.bz2
rails-0fb6b2d572b50493e3d69cea17eb60d3c91a0dbd.zip
Fixes for use_authenticated_cookie_encryption
Use CBC encryption is this configuration value is set to false
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware')
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index baffe200bc..eb193fcbfb 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -599,9 +599,16 @@ module ActionDispatch
def initialize(parent_jar)
super
- key_len = ActiveSupport::MessageEncryptor.key_len(encrypted_cookie_cipher)
- secret = request.key_generator.generate_key(request.authenticated_encrypted_cookie_salt, key_len)
- @encryptor = ActiveSupport::MessageEncryptor.new(secret, cipher: encrypted_cookie_cipher, serializer: SERIALIZER)
+ if request.use_authenticated_cookie_encryption
+ key_len = ActiveSupport::MessageEncryptor.key_len(encrypted_cookie_cipher)
+ secret = request.key_generator.generate_key(request.authenticated_encrypted_cookie_salt, key_len)
+ @encryptor = ActiveSupport::MessageEncryptor.new(secret, cipher: encrypted_cookie_cipher, serializer: SERIALIZER)
+ else
+ key_len = ActiveSupport::MessageEncryptor.key_len("aes-256-cbc")
+ secret = request.key_generator.generate_key(request.encrypted_cookie_salt, key_len)
+ sign_secret = request.key_generator.generate_key(request.encrypted_signed_cookie_salt)
+ @encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret, cipher: "aes-256-cbc", serializer: SERIALIZER)
+ end
request.cookies_rotations.encrypted.each do |*secrets, **options|
@encryptor.rotate(*secrets, serializer: SERIALIZER, **options)