diff options
author | Vipul A M <vipulnsward@gmail.com> | 2013-05-15 19:41:04 +0530 |
---|---|---|
committer | Vipul A M <vipulnsward@gmail.com> | 2013-05-16 02:19:33 +0530 |
commit | a4e1e5d6329f31cb5a1ee7561fdf05dd5559ef7c (patch) | |
tree | 8e47e157ca57bb7dd6c6337fa754df20e2bf79c0 /activesupport/lib/active_support | |
parent | dd03f10d5258dab75da6b7ec493e6558b4ed2bac (diff) | |
download | rails-a4e1e5d6329f31cb5a1ee7561fdf05dd5559ef7c.tar.gz rails-a4e1e5d6329f31cb5a1ee7561fdf05dd5559ef7c.tar.bz2 rails-a4e1e5d6329f31cb5a1ee7561fdf05dd5559ef7c.zip |
Use `Base.strict_decode64` instead of `Base.decode64` just as we do in encoding;
Also reduce extra object allocation by creating string directly instead of join on Array
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/message_encryptor.rb | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support/message_verifier.rb | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index bffdfc6201..7773611e11 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -76,12 +76,12 @@ module ActiveSupport encrypted_data = cipher.update(@serializer.dump(value)) encrypted_data << cipher.final - [encrypted_data, iv].map {|v| ::Base64.strict_encode64(v)}.join("--") + "#{::Base64.strict_encode64 encrypted_data}--#{::Base64.strict_encode64 iv}" end def _decrypt(encrypted_message) cipher = new_cipher - encrypted_data, iv = encrypted_message.split("--").map {|v| ::Base64.decode64(v)} + encrypted_data, iv = encrypted_message.split("--").map {|v| ::Base64.strict_decode64(v)} cipher.decrypt cipher.key = @secret @@ -91,7 +91,7 @@ module ActiveSupport decrypted_data << cipher.final @serializer.load(decrypted_data) - rescue OpenSSLCipherError, TypeError + rescue OpenSSLCipherError, TypeError, ArgumentError raise InvalidMessage end diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index e0cd92ae3c..a35d5980fe 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -37,7 +37,11 @@ module ActiveSupport data, digest = signed_message.split("--") if data.present? && digest.present? && secure_compare(digest, generate_digest(data)) - @serializer.load(::Base64.decode64(data)) + begin + @serializer.load(::Base64.strict_decode64(data)) + rescue ArgumentError + raise InvalidSignature + end else raise InvalidSignature end |