use std::time::Duration;
#[derive(Debug, Clone)]
pub struct SecurityConfig {
pub disable_dtd: bool,
pub disable_external_entities: bool,
pub max_entity_expansions: usize,
pub max_entity_depth: usize,
pub max_element_depth: usize,
pub max_attribute_size: usize,
pub max_text_size: usize,
pub max_file_size: usize,
pub parse_timeout: Duration,
pub stream_timeout: Duration,
pub allow_network: bool,
pub allowed_schemas: Vec<String>,
pub enable_fast_streaming: bool,
}
impl Default for SecurityConfig {
fn default() -> Self {
Self::strict()
}
}
impl SecurityConfig {
pub fn strict() -> Self {
Self {
disable_dtd: true,
disable_external_entities: true,
max_entity_expansions: 100, max_entity_depth: 10, max_element_depth: 100, max_attribute_size: 100 * 1024, max_text_size: 1024 * 1024, max_file_size: 1024 * 1024 * 1024, parse_timeout: Duration::from_secs(30),
stream_timeout: Duration::from_secs(300),
allow_network: false,
allowed_schemas: vec!["file".to_string()],
enable_fast_streaming: false, }
}
pub fn relaxed() -> Self {
Self {
max_element_depth: 200,
max_file_size: if cfg!(target_arch = "wasm32") {
100 * 1024 * 1024 } else {
5 * 1024 * 1024 * 1024 },
parse_timeout: Duration::from_secs(120),
stream_timeout: Duration::from_secs(600),
enable_fast_streaming: true, ..Self::strict()
}
}
}