pub struct SecurityMiddleware {
pub csp: Option<CspConfig>,
pub dns_prefetch_control: DnsPrefetchControl,
pub expect_ct: Option<ExpectCtConfig>,
pub frame_guard: FrameGuard,
pub hsts: Option<HstsConfig>,
pub hide_powered_by: bool,
pub referrer_policy: ReferrerPolicy,
pub xss_filter: XssFilter,
pub content_type_options: ContentTypeOptions,
pub download_options: DownloadOptions,
pub permitted_cross_domain_policies: PermittedCrossDomainPolicies,
}Expand description
Main security middleware that combines all security features
Fields§
§csp: Option<CspConfig>Content Security Policy configuration
dns_prefetch_control: DnsPrefetchControlDNS Prefetch Control
expect_ct: Option<ExpectCtConfig>Expect-CT configuration
frame_guard: FrameGuardFrame Guard (X-Frame-Options)
hsts: Option<HstsConfig>HSTS (Strict-Transport-Security)
hide_powered_by: boolHide X-Powered-By header
referrer_policy: ReferrerPolicyReferrer Policy
xss_filter: XssFilterX-XSS-Protection
content_type_options: ContentTypeOptionsX-Content-Type-Options
download_options: DownloadOptionsX-Download-Options
permitted_cross_domain_policies: PermittedCrossDomainPoliciesX-Permitted-Cross-Domain-Policies
Implementations§
Source§impl SecurityMiddleware
impl SecurityMiddleware
Sourcepub fn with_dns_prefetch_control(self, control: DnsPrefetchControl) -> Self
pub fn with_dns_prefetch_control(self, control: DnsPrefetchControl) -> Self
Enable DNS Prefetch Control
Sourcepub fn with_expect_ct(self, config: ExpectCtConfig) -> Self
pub fn with_expect_ct(self, config: ExpectCtConfig) -> Self
Enable Expect-CT
Sourcepub fn with_frame_guard(self, guard: FrameGuard) -> Self
pub fn with_frame_guard(self, guard: FrameGuard) -> Self
Set Frame Guard policy
Sourcepub fn with_hsts(self, config: HstsConfig) -> Self
pub fn with_hsts(self, config: HstsConfig) -> Self
Enable HSTS
Sourcepub fn hide_powered_by(self, hide: bool) -> Self
pub fn hide_powered_by(self, hide: bool) -> Self
Hide X-Powered-By header
Sourcepub fn with_referrer_policy(self, policy: ReferrerPolicy) -> Self
pub fn with_referrer_policy(self, policy: ReferrerPolicy) -> Self
Set Referrer Policy
Sourcepub fn with_xss_filter(self, filter: XssFilter) -> Self
pub fn with_xss_filter(self, filter: XssFilter) -> Self
Set XSS Filter
Sourcepub fn apply(&self, response: HttpResponse) -> HttpResponse
pub fn apply(&self, response: HttpResponse) -> HttpResponse
Apply security headers to a response
Sourcepub fn enable_all(max_age_seconds: u64) -> Self
pub fn enable_all(max_age_seconds: u64) -> Self
Convenience method to enable all common security features (recommended defaults)
Trait Implementations§
Source§impl Clone for SecurityMiddleware
impl Clone for SecurityMiddleware
Source§fn clone(&self) -> SecurityMiddleware
fn clone(&self) -> SecurityMiddleware
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SecurityMiddleware
impl Debug for SecurityMiddleware
Source§impl Default for SecurityMiddleware
impl Default for SecurityMiddleware
Source§impl Middleware for SecurityMiddleware
Implement the core Middleware trait for SecurityMiddleware
This allows it to be used in a MiddlewareChain
impl Middleware for SecurityMiddleware
Implement the core Middleware trait for SecurityMiddleware This allows it to be used in a MiddlewareChain
Source§fn handle<'life0, 'async_trait>(
&'life0 self,
req: HttpRequest,
next: Box<dyn FnOnce(HttpRequest) -> Pin<Box<dyn Future<Output = Result<HttpResponse, Error>> + Send>> + Send>,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn handle<'life0, 'async_trait>(
&'life0 self,
req: HttpRequest,
next: Box<dyn FnOnce(HttpRequest) -> Pin<Box<dyn Future<Output = Result<HttpResponse, Error>> + Send>> + Send>,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Process the request and optionally pass to next middleware
Auto Trait Implementations§
impl Freeze for SecurityMiddleware
impl RefUnwindSafe for SecurityMiddleware
impl Send for SecurityMiddleware
impl Sync for SecurityMiddleware
impl Unpin for SecurityMiddleware
impl UnwindSafe for SecurityMiddleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging