pub struct SecurityConfig {
pub auth: AuthConfig,
pub rate_limit: RateLimitConfig,
pub api_keys: Vec<String>,
pub capabilities: Option<CapabilitySet>,
pub cors: CorsConfig,
pub allowed_hosts: Option<Vec<String>>,
}Expand description
Security configuration for the server.
Fields§
§auth: AuthConfigAuthentication configuration.
rate_limit: RateLimitConfigRate limiting configuration.
api_keys: Vec<String>API keys to pre-register.
capabilities: Option<CapabilitySet>Capabilities granted to the pre-registered keys and to the auto-generated fallback key.
None (the default) means full-control (wildcard) — the backward-
compatible behavior for a bare --api-key / --require-auth (spec §4).
Some(set) issues fine-grained tokens scoped to that set (spec §9).
cors: CorsConfigCORS configuration.
allowed_hosts: Option<Vec<String>>Host names this server answers to, when it is worth checking.
None disables the check. It is meant for a loopback-bound server, where
DNS rebinding is the one attack CORS cannot stop: the attacker’s name is
rebound to 127.0.0.1, so the browser considers the request same-origin
and sends it. The Host header still carries the attacker’s name, which
is what this compares. A published server is deliberately reachable under
a name we may not know, so the check does not apply there.
Implementations§
Source§impl SecurityConfig
impl SecurityConfig
Sourcepub fn development() -> Self
pub fn development() -> Self
Create a development configuration (no auth, relaxed limits).
Sourcepub fn with_api_key(self, key: impl Into<String>) -> Self
pub fn with_api_key(self, key: impl Into<String>) -> Self
Add an API key.
Sourcepub fn with_capabilities(self, capabilities: CapabilitySet) -> Self
pub fn with_capabilities(self, capabilities: CapabilitySet) -> Self
Scope the issued tokens to a fine-grained capability set (spec §9).
Applies to the pre-registered keys and to the auto-generated fallback key. Without this, tokens are full-control (legacy-compatible).
Sourcepub fn with_allowed_hosts(self, hosts: Vec<String>) -> Self
pub fn with_allowed_hosts(self, hosts: Vec<String>) -> Self
Answer only to these host names.
Sourcepub fn with_cors_allow_any(self) -> Self
pub fn with_cors_allow_any(self) -> Self
Enable permissive (Any) CORS. Opt-in; only for trusted browser UIs.
Trait Implementations§
Source§impl Clone for SecurityConfig
impl Clone for SecurityConfig
Source§fn clone(&self) -> SecurityConfig
fn clone(&self) -> SecurityConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more