diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-09-28 21:43:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-28 21:43:21 +0200 |
commit | 605ba70b111d87fa06316ed2266ceaedef60b6ab (patch) | |
tree | 0a63d50989b3a239dc90364bc4a289fe3ba38698 /actionpack/lib/action_dispatch | |
parent | fbcc4bfe9a211e219da5d0bb01d894fcdaef0a0e (diff) | |
parent | 0fb6b2d572b50493e3d69cea17eb60d3c91a0dbd (diff) | |
download | rails-605ba70b111d87fa06316ed2266ceaedef60b6ab.tar.gz rails-605ba70b111d87fa06316ed2266ceaedef60b6ab.tar.bz2 rails-605ba70b111d87fa06316ed2266ceaedef60b6ab.zip |
Merge pull request #30709 from mikeycgto/actiondispatch-use-aead-encrypted-cookies-patch
Fixes for use_authenticated_cookie_encryption
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/cookies.rb | 13 |
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 0213987c99..86a070c6ad 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) |