Augmentation vers version 3.3.0
This commit is contained in:
28
vendor/symfony/http-kernel/UriSigner.php
vendored
28
vendor/symfony/http-kernel/UriSigner.php
vendored
@@ -19,19 +19,22 @@ namespace Symfony\Component\HttpKernel;
|
||||
class UriSigner
|
||||
{
|
||||
private $secret;
|
||||
private $parameter;
|
||||
|
||||
/**
|
||||
* @param string $secret A secret
|
||||
* @param string $secret A secret
|
||||
* @param string $parameter Query string parameter to use
|
||||
*/
|
||||
public function __construct($secret)
|
||||
public function __construct($secret, $parameter = '_hash')
|
||||
{
|
||||
$this->secret = $secret;
|
||||
$this->parameter = $parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs a URI.
|
||||
*
|
||||
* The given URI is signed by adding a _hash query string parameter
|
||||
* The given URI is signed by adding the query string parameter
|
||||
* which value depends on the URI and the secret.
|
||||
*
|
||||
* @param string $uri A URI to sign
|
||||
@@ -44,12 +47,13 @@ class UriSigner
|
||||
if (isset($url['query'])) {
|
||||
parse_str($url['query'], $params);
|
||||
} else {
|
||||
$params = array();
|
||||
$params = [];
|
||||
}
|
||||
|
||||
$uri = $this->buildUrl($url, $params);
|
||||
$params[$this->parameter] = $this->computeHash($uri);
|
||||
|
||||
return $uri.(false === strpos($uri, '?') ? '?' : '&').'_hash='.$this->computeHash($uri);
|
||||
return $this->buildUrl($url, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,25 +69,25 @@ class UriSigner
|
||||
if (isset($url['query'])) {
|
||||
parse_str($url['query'], $params);
|
||||
} else {
|
||||
$params = array();
|
||||
$params = [];
|
||||
}
|
||||
|
||||
if (empty($params['_hash'])) {
|
||||
if (empty($params[$this->parameter])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hash = urlencode($params['_hash']);
|
||||
unset($params['_hash']);
|
||||
$hash = $params[$this->parameter];
|
||||
unset($params[$this->parameter]);
|
||||
|
||||
return $this->computeHash($this->buildUrl($url, $params)) === $hash;
|
||||
return hash_equals($this->computeHash($this->buildUrl($url, $params)), $hash);
|
||||
}
|
||||
|
||||
private function computeHash($uri)
|
||||
{
|
||||
return urlencode(base64_encode(hash_hmac('sha256', $uri, $this->secret, true)));
|
||||
return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
|
||||
}
|
||||
|
||||
private function buildUrl(array $url, array $params = array())
|
||||
private function buildUrl(array $url, array $params = [])
|
||||
{
|
||||
ksort($params, SORT_STRING);
|
||||
$url['query'] = http_build_query($params, '', '&');
|
||||
|
||||
Reference in New Issue
Block a user