pub enum RegenerateToken {
PerSession,
PerUse,
PerRequest,
}
Expand description
This enum is used with CsrfLayer::regenerate
to determine
at which occurences the CSRF token should be regenerated.
You could understand these options as modes to choose a level of paranoia, depending on your application’s requirements.
This paranoia level is a trade-off between ergonomics and security; as more frequent token invalidation requires more overhead for handling and renewing tokens on the client side, as well as retrying requests with a fresh token, should they fail.
Variants§
PerSession
Generate one CSRF token per session and use this token until the session ends.
This is the default behavior and should work for most applications.
PerUse
Regenerate the CSRF token after each use. A “use” describes an unsafe HTTP method
(POST
, PUT
, PATCH
, DELETE
).
CSRF tokens are not required for, and thus not invalidated by handling requests
using safe HTTP methods (HEAD
, GET
, OPTIONS
, TRACE
, CONNECT
).
PerRequest
Regenerate the CSRF token at each request, including safe HTTP methods (HEAD
, GET
, OPTIONS
, TRACE
, CONNECT
).
This behavior might require elaborate token handling on the client side, as any concurrent requests mean race conditions from the client’s perspective, and each request’s response yields a new token to be used on the consecutive request.
Trait Implementations§
source§impl Clone for RegenerateToken
impl Clone for RegenerateToken
source§fn clone(&self) -> RegenerateToken
fn clone(&self) -> RegenerateToken
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RegenerateToken
impl Debug for RegenerateToken
source§impl Default for RegenerateToken
impl Default for RegenerateToken
source§fn default() -> RegenerateToken
fn default() -> RegenerateToken
source§impl PartialEq<RegenerateToken> for RegenerateToken
impl PartialEq<RegenerateToken> for RegenerateToken
source§fn eq(&self, other: &RegenerateToken) -> bool
fn eq(&self, other: &RegenerateToken) -> bool
self
and other
values to be equal, and is used
by ==
.