PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / http-kernel / UriSigner.php
matomo / app / vendor / prefixed / symfony / http-kernel Last commit date
Attribute 2 years ago Bundle 1 year ago CacheClearer 2 years ago CacheWarmer 1 year ago Config 1 year ago Controller 1 year ago ControllerMetadata 1 year ago DataCollector 1 year ago Debug 1 year ago DependencyInjection 1 year ago Event 1 year ago EventListener 1 year ago Exception 1 year ago Fragment 1 year ago HttpCache 1 year ago Log 1 year ago Profiler 1 year ago Resources 2 years ago HttpClientKernel.php 1 year ago HttpKernel.php 1 year ago HttpKernelBrowser.php 1 year ago HttpKernelInterface.php 1 year ago Kernel.php 1 month ago KernelEvents.php 2 years ago KernelInterface.php 2 years ago LICENSE 2 years ago README.md 2 years ago RebootableInterface.php 2 years ago TerminableInterface.php 2 years ago UriSigner.php 1 year ago
UriSigner.php
98 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace Matomo\Dependencies\Symfony\Component\HttpKernel;
12
13 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Request;
14 /**
15 * Signs URIs.
16 *
17 * @author Fabien Potencier <fabien@symfony.com>
18 */
19 class UriSigner
20 {
21 private $secret;
22 private $parameter;
23 /**
24 * @param string $secret A secret
25 * @param string $parameter Query string parameter to use
26 */
27 public function __construct(string $secret, string $parameter = '_hash')
28 {
29 $this->secret = $secret;
30 $this->parameter = $parameter;
31 }
32 /**
33 * Signs a URI.
34 *
35 * The given URI is signed by adding the query string parameter
36 * which value depends on the URI and the secret.
37 *
38 * @return string
39 */
40 public function sign(string $uri)
41 {
42 $url = parse_url($uri);
43 if (isset($url['query'])) {
44 parse_str($url['query'], $params);
45 } else {
46 $params = [];
47 }
48 $uri = $this->buildUrl($url, $params);
49 $params[$this->parameter] = $this->computeHash($uri);
50 return $this->buildUrl($url, $params);
51 }
52 /**
53 * Checks that a URI contains the correct hash.
54 *
55 * @return bool
56 */
57 public function check(string $uri)
58 {
59 $url = parse_url($uri);
60 if (isset($url['query'])) {
61 parse_str($url['query'], $params);
62 } else {
63 $params = [];
64 }
65 if (empty($params[$this->parameter])) {
66 return \false;
67 }
68 $hash = $params[$this->parameter];
69 unset($params[$this->parameter]);
70 return hash_equals($this->computeHash($this->buildUrl($url, $params)), $hash);
71 }
72 public function checkRequest(Request $request) : bool
73 {
74 $qs = ($qs = $request->server->get('QUERY_STRING')) ? '?' . $qs : '';
75 // we cannot use $request->getUri() here as we want to work with the original URI (no query string reordering)
76 return $this->check($request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . $qs);
77 }
78 private function computeHash(string $uri) : string
79 {
80 return base64_encode(hash_hmac('sha256', $uri, $this->secret, \true));
81 }
82 private function buildUrl(array $url, array $params = []) : string
83 {
84 ksort($params, \SORT_STRING);
85 $url['query'] = http_build_query($params, '', '&');
86 $scheme = isset($url['scheme']) ? $url['scheme'] . '://' : '';
87 $host = $url['host'] ?? '';
88 $port = isset($url['port']) ? ':' . $url['port'] : '';
89 $user = $url['user'] ?? '';
90 $pass = isset($url['pass']) ? ':' . $url['pass'] : '';
91 $pass = $user || $pass ? "{$pass}@" : '';
92 $path = $url['path'] ?? '';
93 $query = isset($url['query']) && $url['query'] ? '?' . $url['query'] : '';
94 $fragment = isset($url['fragment']) ? '#' . $url['fragment'] : '';
95 return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
96 }
97 }
98