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 more