Skip to main content

Module csrf

Module csrf 

Source
Expand description

CSRF helpers for Actix Web services.

This module implements product-neutral CSRF mechanics: URL-safe token generation, double-submit cookie/header checks, and request source validation using Origin, Referer, and Sec-Fetch-Site. Callers map CsrfErrorKind into their own product error codes.

The default cookie and header names are compatibility defaults, not a requirement. Services that share a browser origin should pass CsrfTokenNames into the *_with_names helpers so each product can use names that will not collide with other products on the same domain.

Structs§

CsrfError
Error returned by CSRF helper functions.
CsrfTokenNames
Cookie and header names used by the double-submit token check.

Enums§

CsrfErrorKind
Product-neutral CSRF failure category.
RequestSourceMode
Whether source headers are required or only validated when present.

Constants§

CSRF_COOKIE
Default CSRF cookie name used by compatibility helpers.
CSRF_HEADER
Default CSRF request header name used by compatibility helpers.

Functions§

build_csrf_token
Builds a URL-safe random CSRF token.
default_csrf_token_names
Returns the shared default CSRF token names.
ensure_double_submit_token
Ensures an Actix request contains matching CSRF cookie and header values.
ensure_double_submit_token_with_names
Ensures an Actix request contains matching CSRF cookie and header values using custom names.
ensure_headers_allowed
Validates raw source header values against the request and public-site origins.
ensure_request_source_allowed
Validates source headers for an Actix request.
ensure_service_double_submit_token
Ensures an Actix service request contains matching CSRF cookie and header values.
ensure_service_double_submit_token_with_names
Ensures an Actix service request contains matching CSRF cookie and header values using custom names.
ensure_service_request_source_allowed
Validates source headers for an Actix service request.
is_unsafe_method
Returns whether method can mutate state and should be protected by CSRF checks.

Type Aliases§

Result
Result type returned by CSRF helper functions.