Skip to content

Commit 55b5c7b

Browse files
authored
Merge pull request #65 from github/time-skew
fix: allow 5 mins time drift
2 parents 46655ff + 76f2338 commit 55b5c7b

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

lib/chatops.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module Chatops
1111
threaded_and_channel: 2,
1212
}.freeze
1313

14+
ALLOWED_TIME_SKEW_MINS = 5
15+
1416
def self.public_key
1517
ENV[public_key_env_var_name]
1618
end

lib/chatops/controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ def ensure_valid_chatops_signature
168168
def ensure_valid_chatops_timestamp
169169
@chatops_timestamp = request.headers["Chatops-Timestamp"]
170170
time = Time.iso8601(@chatops_timestamp)
171-
if !(time > 1.minute.ago && time < 1.minute.from_now)
172-
return jsonrpc_error(-32803, 403, "Chatops timestamp not within 1 minute of server time: #{@chatops_timestamp} vs #{Time.now.utc.iso8601}")
171+
if !(time > Chatops::ALLOWED_TIME_SKEW_MINS.minute.ago && time < Chatops::ALLOWED_TIME_SKEW_MINS.minute.from_now)
172+
return jsonrpc_error(-32803, 403, "Chatops timestamp not within #{Chatops::ALLOWED_TIME_SKEW_MINS} minutes of server time: #{@chatops_timestamp} vs #{Time.now.utc.iso8601}")
173173
end
174174
rescue ArgumentError, TypeError
175175
# time parsing or missing can raise these

lib/chatops/controller/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ChatopsController
2-
VERSION = "5.2.0"
2+
VERSION = "5.3.0"
33
end

spec/lib/chatops/controller_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
177177
expect(response.status).to eq 403
178178
end
179179

180-
it "doesn't allow requests more than 1 minute old" do
180+
it "doesn't allow requests more than 5 minute old" do
181181
nonce = SecureRandom.hex(20)
182-
timestamp = 2.minutes.ago.utc.iso8601
182+
timestamp = 6.minutes.ago.utc.iso8601
183183
request.headers["Chatops-Nonce"] = nonce
184184
request.headers["Chatops-Timestamp"] = timestamp
185185
digest = OpenSSL::Digest::SHA256.new
@@ -188,12 +188,12 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
188188
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
189189
get :list
190190
expect(response.status).to eq 403
191-
expect(response.body).to include "Chatops timestamp not within 1 minute"
191+
expect(response.body).to include "Chatops timestamp not within 5 minutes"
192192
end
193193

194-
it "doesn't allow requests more than 1 minute in the future" do
194+
it "doesn't allow requests more than 5 minute in the future" do
195195
nonce = SecureRandom.hex(20)
196-
timestamp = 2.minutes.from_now.utc.iso8601
196+
timestamp = 6.minutes.from_now.utc.iso8601
197197
request.headers["Chatops-Nonce"] = nonce
198198
request.headers["Chatops-Timestamp"] = timestamp
199199
digest = OpenSSL::Digest::SHA256.new
@@ -202,7 +202,7 @@ def rails_flexible_post(path, outer_params, jsonrpc_params = nil)
202202
request.headers["Chatops-Signature"] = "Signature keyid=foo,signature=#{signature}"
203203
get :list
204204
expect(response.status).to eq 403
205-
expect(response.body).to include "Chatops timestamp not within 1 minute"
205+
expect(response.body).to include "Chatops timestamp not within 5 minutes"
206206
end
207207

208208
it "does not add authentication to non-chatops routes" do

0 commit comments

Comments
 (0)