Skip to main content

SecurityHeadersConfig

Struct SecurityHeadersConfig 

Source
pub struct SecurityHeadersConfig {
    pub enabled: bool,
    pub hsts: Option<HstsConfig>,
    pub csp: Vec<CspDirective>,
    pub frame_options: Option<String>,
    pub content_type_options: Option<String>,
    pub xss_protection: Option<String>,
    pub referrer_policy: Option<String>,
    pub permissions_policy: Option<String>,
    pub custom: BTreeMap<String, String>,
}
Expand description

The reference security_headers dict: enabled, hsts, csp, frame_options, content_type_options, xss_protection, referrer_policy, permissions_policy, and custom.

None in the override fields keeps the class default header (the reference dict lookup returning no key); a set value overrides it. The reference’s three-way permissions_policy (“UNSET” sentinel keeps the default, a falsy value removes the header) resolves the same way: None keeps the default and an empty string removes the header.

Fields§

§enabled: bool§hsts: Option<HstsConfig>§csp: Vec<CspDirective>§frame_options: Option<String>§content_type_options: Option<String>§xss_protection: Option<String>§referrer_policy: Option<String>§permissions_policy: Option<String>

None keeps the class default, Some("") removes the header, any other value overrides it.

§custom: BTreeMap<String, String>

Implementations§

Source§

impl SecurityHeadersConfig

Source

pub fn reference_default() -> Self

The reference SecurityConfig.security_headers default block (_security_config_fields.py): enabled, HSTS max-age=31536000+includeSubDomains, no CSP, SAMEORIGIN / nosniff / 1; mode=block / strict-origin-when-cross-origin, the camera and microphone lockdown Permissions-Policy, no custom headers.

Source

pub fn validate(&self) -> Result<(), SecurityHeadersError>

Validate the configured values the way the reference configure() raises out of _validate_header_name / _validate_header_value: a custom name must be a non-empty RFC 7230 token, and no configured value may carry CR/LF, exceed 8192 bytes, or (after sanitization) keep control characters below 0x20 other than tab.

§Errors

SecurityHeadersError naming the offending header on the first invalid entry.

Trait Implementations§

Source§

impl Clone for SecurityHeadersConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SecurityHeadersConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SecurityHeadersConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for SecurityHeadersConfig

Source§

impl PartialEq for SecurityHeadersConfig

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SecurityHeadersConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.