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 -- ASGI 接收函式。

  • send -- ASGI 發送函式。

回傳:

None

create_send_wrapper(send: Send, token: str, csrf_cookie: str | None) Send[原始碼]

Wrap send to handle CSRF validation.

參數:
  • token -- The CSRF token.

  • send -- ASGI 發送函式。

  • csrf_cookie -- CSRF cookie.

回傳:

An ASGI send function.