Skip to content

Commit

Permalink
Make webhook timestamp diff less awkward (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
silas authored Feb 24, 2024
1 parent f027f00 commit 4cd09d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ func (w *Webhook) Verify(req *Request) error {
return types.NewError("Timestamp is invalid: %s", timestamp)
}

diff := time.Until(time.Unix(unixTime, 0))
diff := time.Since(time.Unix(unixTime, 0))
if diff > internal.WebhookMaxTimestampDiff {
return types.NewError("Timestamp is too far in the future: %s", timestamp)
} else if diff < -internal.WebhookMaxTimestampDiff {
return types.NewError("Timestamp is too far in the past: %s", timestamp)
}
if diff < -internal.WebhookMaxTimestampDiff {
return types.NewError("Timestamp is too far in the future: %s", timestamp)
}

mac := hmac.New(sha256.New, w.signingSecret)
mac.Write([]byte(timestamp))
Expand Down

0 comments on commit 4cd09d6

Please sign in to comment.