Update to laravel 7

This commit is contained in:
KodeStar
2022-03-10 11:54:29 +00:00
parent 61a5a1a8b0
commit f9a19fce91
7170 changed files with 274189 additions and 283773 deletions

View File

@@ -11,6 +11,8 @@
namespace Symfony\Component\HttpKernel;
use Symfony\Component\HttpFoundation\Request;
/**
* Signs URIs.
*
@@ -37,11 +39,9 @@ class UriSigner
* 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
*
* @return string The signed URI
* @return string
*/
public function sign($uri)
public function sign(string $uri)
{
$url = parse_url($uri);
if (isset($url['query'])) {
@@ -59,11 +59,9 @@ class UriSigner
/**
* Checks that a URI contains the correct hash.
*
* @param string $uri A signed URI
*
* @return bool True if the URI is signed correctly, false otherwise
* @return bool
*/
public function check($uri)
public function check(string $uri)
{
$url = parse_url($uri);
if (isset($url['query'])) {
@@ -79,26 +77,34 @@ class UriSigner
$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)
public function checkRequest(Request $request): bool
{
$qs = ($qs = $request->server->get('QUERY_STRING')) ? '?'.$qs : '';
// we cannot use $request->getUri() here as we want to work with the original URI (no query string reordering)
return $this->check($request->getSchemeAndHttpHost().$request->getBaseUrl().$request->getPathInfo().$qs);
}
private function computeHash(string $uri): string
{
return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
}
private function buildUrl(array $url, array $params = [])
private function buildUrl(array $url, array $params = []): string
{
ksort($params, SORT_STRING);
ksort($params, \SORT_STRING);
$url['query'] = http_build_query($params, '', '&');
$scheme = isset($url['scheme']) ? $url['scheme'].'://' : '';
$host = isset($url['host']) ? $url['host'] : '';
$host = $url['host'] ?? '';
$port = isset($url['port']) ? ':'.$url['port'] : '';
$user = isset($url['user']) ? $url['user'] : '';
$user = $url['user'] ?? '';
$pass = isset($url['pass']) ? ':'.$url['pass'] : '';
$pass = ($user || $pass) ? "$pass@" : '';
$path = isset($url['path']) ? $url['path'] : '';
$path = $url['path'] ?? '';
$query = isset($url['query']) && $url['query'] ? '?'.$url['query'] : '';
$fragment = isset($url['fragment']) ? '#'.$url['fragment'] : '';