CSRF or XSRF is a security vulnerability and attack method in web applications. It involves tricking a user's browser into sending unauthorized requests to a website where the user is authenticated, allowing attackers to perform actions on behalf of the user.
These middlewares can be configured as every other asgi middleware as shown in middleware docs to work in Ellar
For example, using Starlette CSRF Middleware
# config.py
import typing as t
from ellar.core.middleware import Middleware
from starlette_csrf import CSRFMiddleware
class Development(BaseConfig):
DEBUG: bool = True
# Application middlewares
MIDDLEWARE: t.Sequence[Middleware] = [
Middleware(
CSRFMiddleware,
secret="__CHANGE_ME__",
cookie_name='csrftoken',
safe_methods={"GET", "HEAD", "OPTIONS", "TRACE"}
)
]