csrf

class litestar.middleware.csrf.CSRFMiddleware[源代码]

基类: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.

参数:
  • app -- The next ASGI app to call.

  • config -- The CSRFConfig instance.

async __call__(scope: Scope, receive: Receive, send: Send) None[源代码]

ASGI callable.

参数:
  • scope -- The ASGI connection scope.

  • receive -- The ASGI receive function.

  • send -- The ASGI send function.

返回:

None

create_send_wrapper(send: Send, token: str, csrf_cookie: str | None) Send[源代码]

Wrap send to handle CSRF validation.

参数:
  • token -- The CSRF token.

  • send -- The ASGI send function.

  • csrf_cookie -- CSRF cookie.

返回:

An ASGI send function.