Bases: MiddlewareProtocol
CSRF Middleware class.
This Middleware protects against attacks by setting a CSRF cookie with a token and verifying it in request headers.
-
__init__(app: ASGIApp, config: CSRFConfig) → None
Initialize CSRFMiddleware
.
- Parameters:
-
-
async __call__(scope: Scope, receive: Receive, send: Send) → None
ASGI callable.
- Parameters:
scope – The ASGI connection scope.
receive – The ASGI receive function.
send – The ASGI send function.
- Returns:
None
-
create_send_wrapper(send: Send, token: str, csrf_cookie: str | None) → Send
Wrap send
to handle CSRF validation.
- Parameters:
-
- Returns:
An ASGI send function.