Struct actix_csrf::CsrfMiddleware
source · [−]pub struct CsrfMiddleware<Rng> { /* private fields */ }
Expand description
CSRF middleware to manage CSRF cookies and tokens.
Implementations
sourceimpl<Rng: TokenRng + SeedableRng> CsrfMiddleware<Rng>
impl<Rng: TokenRng + SeedableRng> CsrfMiddleware<Rng>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a CSRF middleware with secure defaults. Namely:
- The CSRF cookie will be prefixed with
__Host-
SameSite
is set toStrict
.Secure
is set.HttpOnly
is set.Path
is set to/
.
This represents the strictest possible configuration. Requests must be always sent over HTTPS. Users must explicitly relax these restrictions.
sourceimpl<Rng: TokenRng> CsrfMiddleware<Rng>
impl<Rng: TokenRng> CsrfMiddleware<Rng>
sourcepub fn with_rng(rng: Rng) -> Self
pub fn with_rng(rng: Rng) -> Self
Creates a CSRF middleware with secure defaults and the provided Rng. Namely:
- The CSRF cookie will be prefixed with
__Host-
SameSite
is set toStrict
.Secure
is set.HttpOnly
is set.Path
is set to/
.
This represents the strictest possible configuration. Requests must be always sent over HTTPS. Users must explicitly relax these restrictions.
sourceimpl<Rng> CsrfMiddleware<Rng>
impl<Rng> CsrfMiddleware<Rng>
sourcepub const fn enabled(self, enabled: bool) -> Self
pub const fn enabled(self, enabled: bool) -> Self
Control whether we check for the token on requests.
Set a method and path to set a CSRF cookie. This should be all locations
that whose response should set a cookie (via a Set-Cookie
header) or
those that need the CSRF token value in the response, such as for forms.
Sets the cookie name. Consider prefixing the cookie name with __Host-
or __Secure-
as an additional defense-in-depth measure against CSRF
attacks.
Trait Implementations
sourceimpl<Rng: Clone> Clone for CsrfMiddleware<Rng>
impl<Rng: Clone> Clone for CsrfMiddleware<Rng>
sourcefn clone(&self) -> CsrfMiddleware<Rng>
fn clone(&self) -> CsrfMiddleware<Rng>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<Rng: Debug> Debug for CsrfMiddleware<Rng>
impl<Rng: Debug> Debug for CsrfMiddleware<Rng>
sourceimpl<Rng: TokenRng + SeedableRng> Default for CsrfMiddleware<Rng>
impl<Rng: TokenRng + SeedableRng> Default for CsrfMiddleware<Rng>
sourceimpl<Rng: PartialEq> PartialEq<CsrfMiddleware<Rng>> for CsrfMiddleware<Rng>
impl<Rng: PartialEq> PartialEq<CsrfMiddleware<Rng>> for CsrfMiddleware<Rng>
sourcefn eq(&self, other: &CsrfMiddleware<Rng>) -> bool
fn eq(&self, other: &CsrfMiddleware<Rng>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &CsrfMiddleware<Rng>) -> bool
fn ne(&self, other: &CsrfMiddleware<Rng>) -> bool
This method tests for !=
.
sourceimpl<S, Rng> Transform<S, ServiceRequest> for CsrfMiddleware<Rng> where
S: Service<ServiceRequest, Response = ServiceResponse>,
Rng: TokenRng + Clone,
impl<S, Rng> Transform<S, ServiceRequest> for CsrfMiddleware<Rng> where
S: Service<ServiceRequest, Response = ServiceResponse>,
Rng: TokenRng + Clone,
type Response = ServiceResponse
type Response = ServiceResponse
Responses produced by the service.
type Error = S::Error
type Error = S::Error
Errors produced by the service.
type Transform = CsrfMiddlewareImpl<S, Rng>
type Transform = CsrfMiddlewareImpl<S, Rng>
The TransformService
value created by this factory
sourcefn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
impl<Rng: Eq> Eq for CsrfMiddleware<Rng>
impl<Rng> StructuralEq for CsrfMiddleware<Rng>
impl<Rng> StructuralPartialEq for CsrfMiddleware<Rng>
Auto Trait Implementations
impl<Rng> !RefUnwindSafe for CsrfMiddleware<Rng>
impl<Rng> !Send for CsrfMiddleware<Rng>
impl<Rng> !Sync for CsrfMiddleware<Rng>
impl<Rng> Unpin for CsrfMiddleware<Rng> where
Rng: Unpin,
impl<Rng> UnwindSafe for CsrfMiddleware<Rng> where
Rng: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more