ddex_parser/parser/
security.rs1use std::time::Duration;
2
3#[derive(Debug, Clone)]
5pub struct SecurityConfig {
6 pub disable_dtd: bool,
8 pub disable_external_entities: bool,
9 pub max_entity_expansions: usize,
10 pub max_entity_depth: usize,
11
12 pub max_element_depth: usize,
14 pub max_attribute_size: usize,
15 pub max_text_size: usize,
16 pub max_file_size: usize,
17
18 pub parse_timeout: Duration,
20 pub stream_timeout: Duration,
21
22 pub allow_network: bool,
24 pub allowed_schemas: Vec<String>,
25
26 pub enable_fast_streaming: bool,
28}
29
30impl Default for SecurityConfig {
31 fn default() -> Self {
32 Self::strict()
33 }
34}
35
36impl SecurityConfig {
37 pub fn strict() -> Self {
39 Self {
40 disable_dtd: true,
41 disable_external_entities: true,
42 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),
49 stream_timeout: Duration::from_secs(300),
50 allow_network: false,
51 allowed_schemas: vec!["file".to_string()],
52 enable_fast_streaming: false, }
54 }
55
56 pub fn relaxed() -> Self {
58 Self {
59 max_element_depth: 200,
60 max_file_size: if cfg!(target_arch = "wasm32") {
61 100 * 1024 * 1024 } else {
63 5 * 1024 * 1024 * 1024 },
65 parse_timeout: Duration::from_secs(120),
66 stream_timeout: Duration::from_secs(600),
67 enable_fast_streaming: true, ..Self::strict()
69 }
70 }
71}