use std::collections::HashSet;
use crate::email_guard::EmailGuardConfig;
#[derive(Debug, Clone)]
pub struct ShieldConfig {
pub block_threshold: f64,
pub warn_threshold: f64,
pub sql: SqlFirewallConfig,
pub ssrf: SsrfConfig,
pub rate: RateConfig,
pub quarantine: QuarantineConfig,
pub audit_max_events: usize,
pub email: EmailGuardConfig,
}
#[derive(Debug, Clone)]
pub struct SqlFirewallConfig {
pub allow_comments: bool,
pub max_query_length: usize,
pub max_subquery_depth: u32,
pub blocked_functions: Vec<String>,
pub blocked_schemas: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct SsrfConfig {
pub block_private_ips: bool,
pub block_loopback: bool,
pub block_link_local: bool,
pub block_metadata_endpoints: bool,
pub allowed_schemes: Vec<String>,
pub allowlist: HashSet<String>,
pub blocklist: HashSet<String>,
pub blocked_ports: Vec<u16>,
}
#[derive(Debug, Clone)]
pub struct RateConfig {
pub requests_per_second: f64,
pub burst_capacity: f64,
pub warn_after: u32,
pub throttle_after: u32,
pub block_after: u32,
pub ban_after: u32,
pub ban_duration_secs: u64,
pub violation_decay_secs: u64,
}
#[derive(Debug, Clone)]
pub struct QuarantineConfig {
pub max_rows: usize,
pub max_size_bytes: usize,
pub max_columns: usize,
pub check_formula_injection: bool,
pub check_embedded_scripts: bool,
}
impl Default for ShieldConfig {
fn default() -> Self {
Self {
block_threshold: 0.7,
warn_threshold: 0.4,
sql: SqlFirewallConfig::default(),
ssrf: SsrfConfig::default(),
rate: RateConfig::default(),
quarantine: QuarantineConfig::default(),
audit_max_events: 100_000,
email: EmailGuardConfig::default(),
}
}
}
impl Default for SqlFirewallConfig {
fn default() -> Self {
Self {
allow_comments: false,
max_query_length: 10_000,
max_subquery_depth: 3,
blocked_functions: Vec::new(),
blocked_schemas: Vec::new(),
}
}
}
impl Default for SsrfConfig {
fn default() -> Self {
Self {
block_private_ips: true,
block_loopback: true,
block_link_local: true,
block_metadata_endpoints: true,
allowed_schemes: vec!["http".into(), "https".into()],
allowlist: HashSet::new(),
blocklist: HashSet::new(),
blocked_ports: vec![
22, 23, 25, 53, 111, 135, 139, 445, 514, 873,
2049, 3306, 5432, 6379, 6380, 9200, 9300,
11211, 27017, 27018, 50070,
],
}
}
}
impl Default for RateConfig {
fn default() -> Self {
Self {
requests_per_second: 50.0,
burst_capacity: 100.0,
warn_after: 3,
throttle_after: 8,
block_after: 15,
ban_after: 30,
ban_duration_secs: 300,
violation_decay_secs: 60,
}
}
}
impl Default for QuarantineConfig {
fn default() -> Self {
Self {
max_rows: 5_000_000,
max_size_bytes: 500 * 1024 * 1024,
max_columns: 500,
check_formula_injection: true,
check_embedded_scripts: true,
}
}
}