pub struct CsrfConfig { /* private fields */ }Expand description
Configuration for the CSRF protection middleware.
Build with CsrfConfig::new() and chain methods to customize the cookie name, header name,
token length, rejection status, cookie path, or Secure flag. Then pass to
CsrfLayer::new().
§Examples
use http::StatusCode;
use rune_axum_csrf::CsrfConfig;
let config = CsrfConfig::new()
.cookie_name("my_csrf")
.token_bytes(64)
.status(StatusCode::FORBIDDEN);Implementations§
Source§impl CsrfConfig
impl CsrfConfig
Sourcepub fn new() -> CsrfConfig
pub fn new() -> CsrfConfig
Creates a CsrfConfig with defaults: 32-byte token, csrf_token cookie,
x-csrf-token header, 403 Forbidden rejection, Path=/.
Sets the cookie name used to store the CSRF token.
Defaults to csrf_token.
Sourcepub fn header_name(self, name: HeaderName) -> CsrfConfig
pub fn header_name(self, name: HeaderName) -> CsrfConfig
Sets the request header name the client must use to echo the token.
Defaults to x-csrf-token.
Sourcepub fn token_bytes(self, bytes: usize) -> CsrfConfig
pub fn token_bytes(self, bytes: usize) -> CsrfConfig
Sets the number of random bytes used to generate the token.
The token is hex-encoded, so the resulting string is twice as long.
Defaults to 32 (a 64-character hex string).
Sourcepub fn status(self, status: StatusCode) -> CsrfConfig
pub fn status(self, status: StatusCode) -> CsrfConfig
Sets the HTTP status code returned when CSRF validation fails.
Defaults to 403 Forbidden.
Sets the Path attribute on the CSRF cookie.
Defaults to /.
Sourcepub fn secure(self, secure: bool) -> CsrfConfig
pub fn secure(self, secure: bool) -> CsrfConfig
Adds the Secure attribute to the CSRF cookie, restricting it to HTTPS connections.
Defaults to false. Set to true in production when serving exclusively over HTTPS.
Trait Implementations§
Source§impl Clone for CsrfConfig
impl Clone for CsrfConfig
Source§fn clone(&self) -> CsrfConfig
fn clone(&self) -> CsrfConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more