Skip to content

Commit 85ba23d

Browse files
committed
Libs(PHP): check timestamp is not float in sign()
We've got a unit test that checks to see if an exception is thrown when the given timestamp is a float. The test case (which is totally fair) uses an input ending in `.0` which casts cleanly enough to an int with the existing "is_positive_integer" check such that the exception isn't thrown. Adding a call to `is_float()` to this check gets us back to the test passing. N.b. the `+ 0` there is to cast the `$timestamp` variable to an actual numeric type instead of a string for the purpose of the call.
1 parent ed966a9 commit 85ba23d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

php/src/Webhook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function verify($payload, $headers)
7070

7171
public function sign($msgId, $timestamp, $payload)
7272
{
73-
$is_positive_integer = is_numeric($timestamp) && (int) $timestamp == $timestamp && (int) $timestamp > 0;
73+
$is_positive_integer = is_numeric($timestamp) && !is_float($timestamp + 0) && (int) $timestamp == $timestamp && (int) $timestamp > 0;
7474
if (!$is_positive_integer) {
7575
throw new Exception\WebhookSigningException("Invalid timestamp");
7676
}

0 commit comments

Comments
 (0)