1 --- activesupport/lib/active_support/message_verifier.rb
2 +++ activesupport/lib/active_support/message_verifier.rb
3 @@ -40,14 +40,27 @@ module ActiveSupport
5 # constant-time comparison algorithm to prevent timing attacks
6 def secure_compare(a, b)
7 - if a.length == b.length
9 - for i in 0..(a.length - 1)
10 - result |= a[i] ^ b[i]
11 + if a.respond_to?(:bytesize)
12 + # > 1.8.6 friendly version
13 + if a.bytesize == b.bytesize
16 + a.each_byte { |i| result |= i ^ j.next }
24 + # <= 1.8.6 friendly version
27 + for i in 0..(a.length - 1)
28 + result |= a[i] ^ b[i]