Skip to content

Commit c728583

Browse files
authored
Merge pull request #6 from SoapBox/bugfix/respect-tolerance-values
[Bugfix] Respect tolerance values
2 parents 400e7f4 + 40fb19e commit c728583

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/Middlewares/VerifySignature.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function handle(Request $request, Closure $next)
7373

7474
$tolerance = $this->configurations->get('signed-requests.request-replay.tolerance');
7575

76-
if (false == $this->configurations->get('signed-requests.request-replay.allow')) {
76+
if (true !== $this->configurations->get('signed-requests.request-replay.allow')) {
7777
$isExpired = $signed->isExpired($tolerance);
7878

7979
if ($isExpired || $this->cache->has($key)) {

src/Requests/Verifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function isExpired(int $tolerance) : bool
189189
$issuedAt =
190190
Carbon::parse($this->headers->get('X-SIGNED-TIMESTAMP', '1901-01-01 12:00:00'));
191191

192-
return Carbon::now()->diffInSeconds($issuedAt) > 60;
192+
return Carbon::now()->diffInSeconds($issuedAt) > $tolerance;
193193
}
194194

195195
/**

tests/Requests/VerifierTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function a_signed_request_is_valid_if_the_signature_matches_the_signature
194194
*/
195195
public function is_expired_returns_true_if_no_timestamp_is_provided_on_the_request()
196196
{
197-
$tolerance = 60;
197+
$tolerance = 10;
198198

199199
$id = "363c60de-9024-4915-99a9-88d63167665e";
200200

@@ -208,7 +208,7 @@ public function is_expired_returns_true_if_no_timestamp_is_provided_on_the_reque
208208
*/
209209
public function is_expired_returns_false_if_the_timestamp_is_within_the_tolerance_window()
210210
{
211-
$tolerance = 60;
211+
$tolerance = 100;
212212

213213
$id = "363c60de-9024-4915-99a9-88d63167665e";
214214

@@ -224,7 +224,7 @@ public function is_expired_returns_false_if_the_timestamp_is_within_the_toleranc
224224
*/
225225
public function is_expired_returns_true_if_the_timestamp_is_outside_the_tolerance_window()
226226
{
227-
$tolerance = 60;
227+
$tolerance = 1000;
228228

229229
$id = "363c60de-9024-4915-99a9-88d63167665e";
230230

@@ -240,7 +240,7 @@ public function is_expired_returns_true_if_the_timestamp_is_outside_the_toleranc
240240
*/
241241
public function is_expired_returns_false_if_the_timestamp_is_in_the_future_but_within_the_tolerance()
242242
{
243-
$tolerance = 60;
243+
$tolerance = 10000;
244244

245245
$id = "363c60de-9024-4915-99a9-88d63167665e";
246246

@@ -256,7 +256,7 @@ public function is_expired_returns_false_if_the_timestamp_is_in_the_future_but_w
256256
*/
257257
public function is_expired_returns_if_the_timestamp_is_in_the_future_outside_of_the_tolerance()
258258
{
259-
$tolerance = 60;
259+
$tolerance = 100000;
260260

261261
$id = "363c60de-9024-4915-99a9-88d63167665e";
262262

0 commit comments

Comments
 (0)