CsrfTokenMiddleware
- Full name:
\Codefy\Framework\Http\Middleware\Csrf\CsrfTokenMiddleware - This class implements:
MiddlewareInterface
Constants
| Constant | Visibility | Type | Value |
|---|---|---|---|
CSRF_SESSION_ATTRIBUTE | public | 'CSRF_TOKEN' |
Properties
current
- This property is static.
token
configContainer
cookie
Methods
__construct
public __construct(\Qubus\Config\ConfigContainer $configContainer, \Qubus\Http\Cookies\Factory\HttpCookieFactory $cookie): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$configContainer | \Qubus\Config\ConfigContainer | |
$cookie | \Qubus\Http\Cookies\Factory\HttpCookieFactory |
getField
-
This method is static. Throws:
getFieldAttr
Throws:
process
public process(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler): \Psr\Http\Message\ResponseInterface
Parameters:
| Parameter | Type | Description |
|---|---|---|
$request | \Psr\Http\Message\ServerRequestInterface | |
$handler | \Psr\Http\Server\RequestHandlerInterface |
Throws:
Inherited methods
sign
Sign the value.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$value | string |
Throws:
unsign
Unsign the value.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$value | string | Encrypted value. |
Return Value:
Return the value if signature is valid.
Throws:
compareTokens
Parameters:
| Parameter | Type | Description |
|---|---|---|
$knownString | string | |
$userString | string |
generateToken
prepareToken
Parameters:
| Parameter | Type | Description |
|---|---|---|
$request | \Psr\Http\Message\ServerRequestInterface |
Throws:
getTokenFromCookie
Get the token from the request cookie if it's present.
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: