final class CsrfMiddleware implements MiddlewareInterface (View source)

Enforces the default CSRF token on unsafe requests and exposes it on every response.

Constants

private SAFE_METHODS

Methods

__construct(CsrfTokenManager $tokens, Psr17Factory $responseFactory)

Connects request validation to session-backed tokens and PSR-17 error responses.

ResponseInterface
process(ServerRequestInterface $request, RequestHandlerInterface $handler)

Validates unsafe requests before dispatch and attaches the current token to the response.

ResponseInterface

Details

__construct

__construct(CsrfTokenManager $tokens, Psr17Factory $responseFactory)

Connects request validation to session-backed tokens and PSR-17 error responses.

Parameters

CsrfTokenManager $tokens
Psr17Factory $responseFactory

process

ResponseInterface process(ServerRequestInterface $request, RequestHandlerInterface $handler)

Validates unsafe requests before dispatch and attaches the current token to the response.

Parameters

ServerRequestInterface $request
RequestHandlerInterface $handler

Return Value

ResponseInterface