Skip to content

CsrfTokenAware


  • Full name: \Codefy\Framework\Http\Middleware\Csrf\Traits\CsrfTokenAware

Properties

salt

protected ?string $salt

isNew

protected bool $isNew

Methods

generateToken

protected generateToken(): string

prepareToken

protected prepareToken(\Psr\Http\Message\ServerRequestInterface $request): string

Parameters:

Parameter Type Description
$request \Psr\Http\Message\ServerRequestInterface

Throws:


getTokenFromCookie

Get the token from the request cookie if it's present.

private getTokenFromCookie(array $cookies): string|null

Decrypt the cookie token value using the app crypto key.

Return null if the cookie is missing or if the decryption fails.

Parameters:

Parameter Type Description
$cookies array

Throws:


createCookie

Create CSRF cookie to store the encrypted token value.

private createCookie(\Psr\Http\Message\ResponseInterface $response, string $token): \Psr\Http\Message\ResponseInterface

Encrypt the value for better security (in case of XSS attack).

Parameters:

Parameter Type Description
$response \Psr\Http\Message\ResponseInterface
$token string

Throws: