Skip to main content

security_rust/injection/
ssi_injection.rs

1// Copyright (c) 2026 erik <erik@erik.xyz> — https://erik.xyz
2
3use crate::{AttackCategory, DetectionResult, Detector, Severity};
4use regex::Regex;
5use std::sync::LazyLock;
6
7static PATTERNS: LazyLock<Vec<Regex>> = LazyLock::new(|| {
8    vec![
9        Regex::new(r"<!--#exec cmd=").unwrap(),
10        Regex::new(r"<!--#include file=").unwrap(),
11        Regex::new(r"<!--#echo var=").unwrap(),
12        Regex::new(r"<!--#fsize").unwrap(),
13        Regex::new(r"<!--#flastmod").unwrap(),
14        Regex::new(r"<!--#config").unwrap(),
15        Regex::new(r"<!--#printenv").unwrap(),
16    ]
17});
18
19pub struct SsiInjectionDetector;
20
21impl Detector for SsiInjectionDetector {
22    fn name(&self) -> &'static str {
23        "ssi_injection"
24    }
25
26    fn detect(&self, input: &str) -> Option<DetectionResult> {
27        for re in PATTERNS.iter() {
28            if let Some(m) = re.find(input) {
29                return Some(DetectionResult {
30                    attack_type: "ssi_injection".into(),
31                    category: AttackCategory::Injection,
32                    severity: Severity::High,
33                    matched_pattern: m.as_str().to_string(),
34                    offset: m.start(),
35                    message: "SSI Server-Side Include injection detected".into(),
36                });
37            }
38        }
39        None
40    }
41}