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
27impl Default for SecurityConfig {
28 fn default() -> Self {
29 Self::strict()
30 }
31}
32
33impl SecurityConfig {
34 pub fn strict() -> Self {
36 Self {
37 disable_dtd: true,
38 disable_external_entities: true,
39 max_entity_expansions: 1000,
40 max_entity_depth: 20,
41 max_element_depth: 100,
42 max_attribute_size: 100 * 1024, max_text_size: 1024 * 1024, max_file_size: 1024 * 1024 * 1024, parse_timeout: Duration::from_secs(30),
46 stream_timeout: Duration::from_secs(300),
47 allow_network: false,
48 allowed_schemas: vec!["file".to_string()],
49 }
50 }
51
52 pub fn relaxed() -> Self {
54 Self {
55 max_element_depth: 200,
56 max_file_size: if cfg!(target_arch = "wasm32") {
57 100 * 1024 * 1024 } else {
59 5 * 1024 * 1024 * 1024 },
61 parse_timeout: Duration::from_secs(120),
62 stream_timeout: Duration::from_secs(600),
63 ..Self::strict()
64 }
65 }
66}