Skip to content

Commit

Permalink
Split hasValidSignature method (#30208)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightwatson authored and taylorotwell committed Oct 8, 2019
1 parent 6169acc commit 20ae4a5
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/Illuminate/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,42 @@ public function temporarySignedRoute($name, $expiration, $parameters = [], $abso
* @return bool
*/
public function hasValidSignature(Request $request, $absolute = true)
{
return $this->hasCorrectSignature($request, $absolute)
&& $this->signatureHasNotExpired($request);
}

/**
* Determine if the signature from the given request matches the URL.
*
* @param \Illuminate\Http\Request $request
* @param bool $absolute
* @return bool
*/
public function hasCorrectSignature(Request $request, $absolute = true)
{
$url = $absolute ? $request->url() : '/'.$request->path();

$original = rtrim($url.'?'.Arr::query(
Arr::except($request->query(), 'signature')
), '?');

$expires = $request->query('expires');

$signature = hash_hmac('sha256', $original, call_user_func($this->keyResolver));

return hash_equals($signature, (string) $request->query('signature', '')) &&
! ($expires && Carbon::now()->getTimestamp() > $expires);
return hash_equals($signature, (string) $request->query('signature', ''));
}

/**
* Determine if the expires timestamp from the given request is not from the past.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
public function signatureHasNotExpired(Request $request)
{
$expires = $request->query('expires');

return ! ($expires && Carbon::now()->getTimestamp() > $expires);
}

/**
Expand Down

0 comments on commit 20ae4a5

Please sign in to comment.