pub struct SecuritySettings {
pub app_base_url: String,
pub cookie_secure: bool,
pub trusted_proxy_count: u32,
pub max_sessions_per_user: u32,
}Expand description
安全配置(CSRF 可信源、cookie Secure 标志、真实 IP 提取、并发会话上限)。
即时生效层:读取走 moka 缓存,面板保存后失效缓存,数秒内全链路生效。
Fields§
§app_base_url: String写请求 CSRF 校验的可信来源(如 https://your-domain.example)。
空串表示未配置,回退到 Host 头 + X-Forwarded-Proto(生产建议显式配置)。
是否给会话 cookie 加 Secure 标志(仅 HTTPS 下发送)。
trusted_proxy_count: u32应用前方的反向代理层数,用于从 X-Forwarded-For 提取真实客户端 IP。
max_sessions_per_user: u32单用户最大并发会话数,超出按最旧优先淘汰。
Implementations§
Source§impl SecuritySettings
impl SecuritySettings
Sourcepub fn clamp_trusted_proxy_count(n: u32) -> u32
pub fn clamp_trusted_proxy_count(n: u32) -> u32
将代理层数钳制到合法范围 [0, MAX]。
Sourcepub fn clamp_max_sessions(n: u32) -> u32
pub fn clamp_max_sessions(n: u32) -> u32
将并发会话上限钳制到合法范围 [MIN, MAX]。
Sourcepub fn normalize_app_base_url(url: &str) -> String
pub fn normalize_app_base_url(url: &str) -> String
规范化 APP_BASE_URL:trim;空串保留为空串(表示未配置)。 不在此补 scheme——CSRF 校验需要精确的 origin,补全反而可能失配。
Trait Implementations§
Source§impl Clone for SecuritySettings
impl Clone for SecuritySettings
Source§fn clone(&self) -> SecuritySettings
fn clone(&self) -> SecuritySettings
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 SecuritySettings
impl Debug for SecuritySettings
Source§impl Default for SecuritySettings
impl Default for SecuritySettings
Source§impl<'de> Deserialize<'de> for SecuritySettings
impl<'de> Deserialize<'de> for SecuritySettings
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for SecuritySettings
impl PartialEq for SecuritySettings
Source§impl Serialize for SecuritySettings
impl Serialize for SecuritySettings
impl StructuralPartialEq for SecuritySettings
Auto Trait Implementations§
impl Freeze for SecuritySettings
impl RefUnwindSafe for SecuritySettings
impl Send for SecuritySettings
impl Sync for SecuritySettings
impl Unpin for SecuritySettings
impl UnsafeUnpin for SecuritySettings
impl UnwindSafe for SecuritySettings
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,
§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.
§impl<T> Transportable for Twhere
T: Serialize + DeserializeOwned + 'static,
impl<T> Transportable for Twhere
T: Serialize + DeserializeOwned + 'static,
§fn transport_to_bytes(&self) -> Vec<u8> ⓘ
fn transport_to_bytes(&self) -> Vec<u8> ⓘ
Serialize the type to a byte vector for transport
§fn transport_from_bytes(bytes: &[u8]) -> Result<T, Error<Error>>
fn transport_from_bytes(bytes: &[u8]) -> Result<T, Error<Error>>
Deserialize the type from a byte slice