guard_core_engine/semantic/
patterns.rs1use regex::Regex;
2
3pub struct AttackStructures {
9 named: Vec<(&'static str, Regex)>,
10}
11
12impl AttackStructures {
13 #[must_use]
15 pub fn named(&self) -> &[(&'static str, Regex)] {
16 &self.named
17 }
18
19 pub fn compiled(&self) -> impl Iterator<Item = &Regex> {
21 self.named.iter().map(|(_, re)| re)
22 }
23}
24
25impl Default for AttackStructures {
26 fn default() -> Self {
27 let definitions: &[(&str, &str)] = &[
28 ("tag_like", r"<[^>]+>"),
29 ("function_call", r"\w+\s*\([^)]*\)"),
30 ("command_chain", r"[;&|]{1,2}"),
31 ("path_traversal", r"\.{2,}[/\\]"),
32 ("url_pattern", r"[a-z]+://"),
33 ];
34
35 let named = definitions
36 .iter()
37 .map(|&(name, pat)| {
38 let re = Regex::new(&format!("(?i){pat}")).expect("static pattern must compile");
39 (name, re)
40 })
41 .collect();
42
43 Self { named }
44 }
45}