Skip to content

Commit ad41f71

Browse files
authored
Merge pull request rails#51846 from simi/base64-standard-error
Catch StandardError during Base64 decoding in message encryptor.
2 parents cff6b2c + a27a038 commit ad41f71

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

activesupport/lib/active_support/messages/codec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def encode(data, url_safe: @url_safe)
2828

2929
def decode(encoded, url_safe: @url_safe)
3030
url_safe ? ::Base64.urlsafe_decode64(encoded) : ::Base64.strict_decode64(encoded)
31-
rescue ArgumentError => error
31+
rescue StandardError => error
3232
throw :invalid_message_format, error
3333
end
3434

activesupport/test/message_encryptor_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ def test_inspect_does_not_show_secrets
157157
assert_match(/\A#<ActiveSupport::MessageEncryptor:0x[0-9a-f]+>\z/, encryptor.inspect)
158158
end
159159

160+
def test_invalid_base64_argument
161+
assert_not_decrypted("jrcc<!--esi-->rkls<!--esx-->tyx9")
162+
end
163+
160164
private
161165
def make_codec(**options)
162166
ActiveSupport::MessageEncryptor.new(@secret, **options)

0 commit comments

Comments
 (0)