csrf

class litestar.middleware.csrf.CSRFMiddleware

基类:MiddlewareProtocol

CSRF 中间件类。 该中间件通过设置带有令牌的 CSRF Cookie 并在请求头中验证该令牌,来防御攻击。

__init__(app: ASGIApp, config: CSRFConfig) None

初始化 CSRFMiddleware。 Args: app: 要调用的下一个 next ASGI 应用。 config: CSRFConfig 实例。

async __call__(scope: Scope, receive: Receive, send: Send) None

ASGI 可调用对象。 Args: scope: ASGI 连接作用域。 receive: ASGI 接收函数。 send: ASGI 发送函数。 Returns: None

create_send_wrapper(send: Send, token: str, csrf_cookie: str | None) Send

包装 send 以处理 CSRF 验证。 Args: token: CSRF 令牌。 send: ASGI send 函数。 csrf_cookie: CSRF cookie。 Returns: 一个 ASGI send 函数。