Skip to content

Commit c18e0ef

Browse files
committed
Use secure_compare during signature verification
1 parent f2423d4 commit c18e0ef

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 2.5.3 (Next)
22

33
* [#549](https://github.com/slack-ruby/slack-ruby-client/pull/549): Add group ID formatting support for message mentions - [@n0h0](https://github.com/n0h0).
4+
* [#553](https://github.com/slack-ruby/slack-ruby-client/pull/553): Use secure_compare during signature verification - [@hieuk09](https://github.com/hieuk09).
45
* Your contribution here.
56

67
### 2.5.2 (2025/02/19)

lib/slack/events/request.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def valid?
5959
signature_basestring = [version, timestamp, body].join(':')
6060
hex_hash = OpenSSL::HMAC.hexdigest(digest, signing_secret, signature_basestring)
6161
computed_signature = [version, hex_hash].join('=')
62-
computed_signature == signature
62+
secure_compare(computed_signature, signature)
6363
end
6464

6565
# Validates the request signature and its expiration.
@@ -69,6 +69,19 @@ def verify!
6969

7070
true
7171
end
72+
73+
private
74+
75+
def secure_compare(computed_signature, signature)
76+
return false if computed_signature.bytesize != signature.bytesize
77+
78+
l = computed_signature.unpack "C#{computed_signature.bytesize}"
79+
80+
result = 0
81+
signature.each_byte { |byte| result |= byte ^ l.shift }
82+
83+
result.zero?
84+
end
7285
end
7386
end
7487
end

0 commit comments

Comments
 (0)