1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of web-stack |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Slick\WebStack\Domain\Security\Csrf\TokenStorage; |
13
|
|
|
|
14
|
|
|
use Slick\WebStack\Domain\Security\Csrf\TokenStorageInterface; |
15
|
|
|
use Slick\WebStack\Domain\Security\Exception\CsrfTokenNotFound; |
16
|
|
|
use SensitiveParameter; |
|
|
|
|
17
|
|
|
use Slick\Http\Session\SessionDriverInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* SessionCsrfTokenStorage |
21
|
|
|
* |
22
|
|
|
* @package Slick\WebStack\Domain\Security\Csrf\TokenStorage |
23
|
|
|
*/ |
24
|
|
|
final class SessionCsrfTokenStorage implements TokenStorageInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* The namespace used to store values in the session. |
28
|
|
|
*/ |
29
|
|
|
public const SESSION_NAMESPACE = '_csrf'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Creates a SessionCsrfTokenStorage |
33
|
|
|
* |
34
|
|
|
* @param SessionDriverInterface $session |
35
|
|
|
* @param string $namespace |
36
|
|
|
*/ |
37
|
|
|
public function __construct( |
38
|
|
|
private readonly SessionDriverInterface $session, |
39
|
|
|
private readonly string $namespace = self::SESSION_NAMESPACE |
40
|
|
|
) { |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
|
|
public function get(string $tokenId): string |
47
|
|
|
{ |
48
|
|
|
$existing = $this->session->get($this->namespace."_$tokenId"); |
49
|
|
|
if (!$existing) { |
50
|
|
|
throw new CsrfTokenNotFound('The CSRF token with ID '.$tokenId.' does not exist.'); |
51
|
|
|
} |
52
|
|
|
return $existing; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritDoc |
57
|
|
|
*/ |
58
|
|
|
public function set(string $tokenId, #[SensitiveParameter] string $token): void |
59
|
|
|
{ |
60
|
|
|
$this->session->set($this->namespace."_$tokenId", $token); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritDoc |
65
|
|
|
*/ |
66
|
|
|
public function remove(string $tokenId): void |
67
|
|
|
{ |
68
|
|
|
$this->session->erase($this->namespace."_$tokenId"); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritDoc |
73
|
|
|
*/ |
74
|
|
|
public function has(string $tokenId): bool |
75
|
|
|
{ |
76
|
|
|
return null !== $this->session->get($this->namespace."_$tokenId"); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths