8000 Remove old UriSigner · symfony/symfony@6691053 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6691053

Browse files
Remove old UriSigner
1 parent 5ab4fab commit 6691053

File tree

1 file changed

+0
-101
lines changed

1 file changed

+0
-101
lines changed

src/Symfony/Component/HttpKernel/UriSigner.php

-101
Original file line numberDiff line numberDiff line change
@@ -25,104 +25,3 @@ class UriSigner
2525
{
2626
}
2727
}
28-
29-
/**
30-
* Signs URIs.
31-
*
32-
* @author Fabien Potencier <fabien@symfony.com>
33-
*
34-
* @deprecated since Symfony 6.4, use {@link HttpFoundationUriSigner} instead
35-
*/
36-
class UriSigner
37-
{
38-
private string $secret;
39-
private string $parameter;
40-
41-
/**
42-
* @param string $secret A secret
43-
* @param string $parameter Query string parameter to use
44-
*/
45-
public function __construct(#[\SensitiveParameter] string $secret, string $parameter = '_hash', bool $skipDeprecation = false)
46-
{
47-
$this->secret = $secret;
48-
$this->parameter = $parameter;
49-
50-
if ($skipDeprecation) {
51-
trigger_deprecation('symfony/dependency-injection', '6.4', 'The "%s" class is deprecated, use "%s" instead.', self::class, HttpFoundationUriSigner::class);
52-
}
53-
}
54-
55-
/**
56-
* Signs a URI.
57-
*
58-
* The given URI is signed by adding the query string parameter
59-
* which value depends on the URI and the secret.
60-
*/
61-
public function sign(string $uri): string
62-
{
63-
$url = parse_url($uri);
64-
$params = [];
65-
66-
if (isset($url['query'])) {
67-
parse_str($url['query'], $params);
68-
}
69-
70-
$uri = $this->buildUrl($url, $params);
71-
$params[$this->parameter] = $this->computeHash($uri);
72-
73-
return $this->buildUrl($url, $params);
74-
}
75-
76-
/**
77-
* Checks that a URI contains the correct hash.
78-
*/
79-
public function check(string $uri): bool
80-
{
81-
$url = parse_url($uri);
82-
$params = [];
83-
84-
if (isset($url['query'])) {
85-
parse_str($url['query'], $params);
86-
}
87-
88-
if (empty($params[$this->parameter])) {
89-
return false;
90-
}
91-
92-
$hash = $params[$this->parameter];
93-
unset($params[$this->parameter]);
94-
95-
return hash_equals($this->computeHash($this->buildUrl($url, $params)), $hash);
96-
}
97-
98-
public function checkRequest(Request $request): bool
99-
{
100-
$qs = ($qs = $request->server->get('QUERY_STRING')) ? '?'.$qs : '';
101-
102-
// we cannot use $request->getUri() here as we want to work with the original URI (no query string reordering)
103-
return $this->check($request->getSchemeAndHttpHost().$request->getBaseUrl().$request->getPathInfo().$qs);
104-
}
105-
106-
private function computeHash(string $uri): string
107-
{
108-
return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
109-
}
110-
111-
private function buildUrl(array $url, array $params = []): string
112-
{
113-
ksort($params, \SORT_STRING);
114-
$url['query'] = http_build_query($params, '', '&');
115-
116-
$scheme = isset($url['scheme']) ? $url['scheme'].'://' : '';
117-
$host = $url['host'] ?? '';
118-
$port = isset($url['port']) ? ':'.$url['port'] : '';
119-
$user = $url['user'] ?? '';
120-
$pass = isset($url['pass']) ? ':'.$url['pass'] : '';
121-
$pass = ($user || $pass) ? "$pass@" : '';
122-
$path = $url['path'] ?? '';
123-
$query = $url['query'] ? '?'.$url['query'] : '';
124-
$fragment = isset($url['fragment']) ? '#'.$url['fragment'] : '';
125-
126-
return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
127-
}
128-
}

0 commit comments

Comments
 (0)
0