File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -106,14 +106,14 @@ def options_for(option)
106
106
end
107
107
108
108
# constant-time comparison algorithm to prevent timing attacks
109
- def secure_compare ( a , b )
110
- return false unless a . bytesize == b . bytesize
109
+ def secure_compare ( string_a , string_b )
110
+ return false unless string_a . bytesize == string_b . bytesize
111
111
112
- l = a . unpack "C#{ a . bytesize } "
112
+ l = string_a . unpack "C#{ string_a . bytesize } "
113
113
114
114
res = 0
115
- b . each_byte { |byte | res |= byte ^ l . shift }
116
- res == 0
115
+ string_b . each_byte { |byte | res |= byte ^ l . shift }
116
+ res . zero?
117
117
end
118
118
119
119
# An error that is indicated in the OAuth 2.0 callback.
Original file line number Diff line number Diff line change @@ -87,6 +87,16 @@ def app
87
87
instance . callback_phase
88
88
end
89
89
end
90
+
91
+ describe "#secure_params" do
92
+ subject { fresh_strategy }
93
+
94
+ it "returns true when the two inputs are the same and false otherwise" do
95
+ instance = subject . new ( "abc" , "def" )
96
+ expect ( instance . send ( :secure_compare , "a" , "a" ) ) . to be true
97
+ expect ( instance . send ( :secure_compare , "b" , "a" ) ) . to be false
98
+ end
99
+ end
90
100
end
91
101
92
102
describe OmniAuth ::Strategies ::OAuth2 ::CallbackError do
You can’t perform that action at this time.
0 commit comments