Skip to content

Commit d599cc2

Browse files
committed
Enhance timestamp validation: ensure UTC indicator is present in timestamp and clarify redundancy in checks
1 parent 6a0d421 commit d599cc2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/hooks/plugins/auth/hmac.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,13 @@ def self.parse_iso8601_timestamp(timestamp_value)
249249
if timestamp_value =~ /\A(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}(?:\.\d+)?)(?: )\+0000\z/
250250
timestamp_value = "#{$1}T#{$2}+00:00"
251251
end
252+
# Ensure the timestamp explicitly includes a UTC indicator
253+
return nil unless timestamp_value =~ /(Z|\+00:00|\+0000)\z/
252254
return nil unless iso8601_timestamp?(timestamp_value)
253255
t = Time.parse(timestamp_value) rescue nil
254256
return nil unless t
257+
# The check for UTC indicator in regex makes this t.utc? or t.utc_offset == 0 redundant
258+
# but kept for safety, though it should always be true now if Time.parse succeeds.
255259
(t.utc? || t.utc_offset == 0) ? t.to_i : nil
256260
end
257261

0 commit comments

Comments
 (0)