Final Class Yiisoft\Csrf\Synchronizer\SynchronizerCsrfToken
| Inheritance | Yiisoft\Csrf\Synchronizer\SynchronizerCsrfToken |
|---|---|
| Implements | Yiisoft\Csrf\CsrfTokenInterface |
Stateful CSRF token that is a unique random string. It is stored it in persistent storage available only for the currently logged in user. The same token is added to forms. When the form is submitted, token that came from the form is compared against the token stored.
The algorithm is also known as "Synchronizer Token".
Do not forget to decorate the token with {@see \Yiisoft\Csrf\MaskedCsrfToken} to prevent BREACH attack.
Public Methods
Method Details
public function __construct(
CsrfTokenGeneratorInterface $generator,
CsrfTokenStorageInterface $storage
) {
$this->generator = $generator;
$this->storage = $storage;
}
| public string getValue ( ) |
public function getValue(): string
{
$token = $this->storage->get();
if (empty($token)) {
$token = $this->generator->generate();
$this->storage->set($token);
}
return $token;
}
Signup or Login in order to comment.