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§
- Csrf
Error - Error returned by CSRF helper functions.
- Csrf
Token Names - Cookie and header names used by the double-submit token check.
Enums§
- Csrf
Error Kind - Product-neutral CSRF failure category.
- Request
Source Mode - 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
methodcan mutate state and should be protected by CSRF checks.
Type Aliases§
- Result
- Result type returned by CSRF helper functions.