pub struct SecurityHeaders {
pub content_type_options: bool,
pub frame_options: FrameOptions,
pub xss_protection: bool,
pub content_security_policy: Option<String>,
pub hsts_enabled: bool,
pub hsts_max_age: u64,
pub hsts_include_subdomains: bool,
pub hsts_preload: bool,
pub referrer_policy: ReferrerPolicy,
pub permissions_policy: Option<String>,
pub cache_control: Option<String>,
}Expand description
Security headers configuration.
§Spring Security Equivalent
HttpSecurity.headers()
§Example
use actix_security_core::http::security::headers::{SecurityHeaders, FrameOptions};
let headers = SecurityHeaders::new()
.frame_options(FrameOptions::SameOrigin)
.content_security_policy("default-src 'self'")
.hsts(true, 31536000); // 1 yearFields§
§content_type_options: boolX-Content-Type-Options header (default: nosniff)
frame_options: FrameOptionsX-Frame-Options header (default: DENY)
xss_protection: boolX-XSS-Protection header (default: 0)
content_security_policy: Option<String>Content-Security-Policy header (default: None)
hsts_enabled: boolStrict-Transport-Security header (default: disabled)
hsts_max_age: u64HSTS max-age in seconds (default: 31536000 = 1 year)
hsts_include_subdomains: boolHSTS include subdomains (default: false)
hsts_preload: boolHSTS preload (default: false)
referrer_policy: ReferrerPolicyReferrer-Policy header (default: strict-origin-when-cross-origin)
permissions_policy: Option<String>Permissions-Policy header (default: None)
cache_control: Option<String>Cache-Control header for sensitive content (default: None)
Implementations§
Source§impl SecurityHeaders
impl SecurityHeaders
Sourcepub fn strict() -> Self
pub fn strict() -> Self
Creates a strict security headers configuration.
Enables all security headers with strict values.
Sourcepub fn frame_options(self, options: FrameOptions) -> Self
pub fn frame_options(self, options: FrameOptions) -> Self
Sets the X-Frame-Options header.
§Spring Security Equivalent
headers().frameOptions().deny() or .sameOrigin()
Sourcepub fn content_security_policy(self, policy: impl Into<String>) -> Self
pub fn content_security_policy(self, policy: impl Into<String>) -> Self
Sourcepub fn hsts_include_subdomains(self, include: bool) -> Self
pub fn hsts_include_subdomains(self, include: bool) -> Self
Sets HSTS to include subdomains.
Sourcepub fn hsts_preload(self, preload: bool) -> Self
pub fn hsts_preload(self, preload: bool) -> Self
Sets HSTS preload flag.
§Warning
Only enable this if you’ve submitted your domain to the HSTS preload list.
Sourcepub fn referrer_policy(self, policy: ReferrerPolicy) -> Self
pub fn referrer_policy(self, policy: ReferrerPolicy) -> Self
Sets the Referrer-Policy header.
§Spring Security Equivalent
headers().referrerPolicy(ReferrerPolicy.STRICT_ORIGIN)
Sourcepub fn permissions_policy(self, policy: impl Into<String>) -> Self
pub fn permissions_policy(self, policy: impl Into<String>) -> Self
Sourcepub fn cache_control(self, value: impl Into<String>) -> Self
pub fn cache_control(self, value: impl Into<String>) -> Self
Sets the Cache-Control header for sensitive content.
Sourcepub fn disable_content_type_options(self) -> Self
pub fn disable_content_type_options(self) -> Self
Disables X-Content-Type-Options header.
Trait Implementations§
Source§impl Clone for SecurityHeaders
impl Clone for SecurityHeaders
Source§fn clone(&self) -> SecurityHeaders
fn clone(&self) -> SecurityHeaders
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SecurityHeaders
impl Debug for SecurityHeaders
Source§impl Default for SecurityHeaders
impl Default for SecurityHeaders
Source§impl<S, B> Transform<S, ServiceRequest> for SecurityHeaderswhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
B: 'static,
impl<S, B> Transform<S, ServiceRequest> for SecurityHeaderswhere
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
B: 'static,
Source§type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Source§type Transform = SecurityHeadersMiddleware<S>
type Transform = SecurityHeadersMiddleware<S>
TransformService value created by this factorySource§type Future = Ready<Result<<SecurityHeaders as Transform<S, ServiceRequest>>::Transform, <SecurityHeaders as Transform<S, ServiceRequest>>::InitError>>
type Future = Ready<Result<<SecurityHeaders as Transform<S, ServiceRequest>>::Transform, <SecurityHeaders as Transform<S, ServiceRequest>>::InitError>>
Source§fn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Auto Trait Implementations§
impl Freeze for SecurityHeaders
impl RefUnwindSafe for SecurityHeaders
impl Send for SecurityHeaders
impl Sync for SecurityHeaders
impl Unpin for SecurityHeaders
impl UnwindSafe for SecurityHeaders
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more