security_rust/protocol/
request_smuggling.rs1use regex::Regex;
4use std::sync::LazyLock;
5
6use crate::{AttackCategory, DetectionResult, Detector, Severity};
7
8static PATTERNS: LazyLock<Vec<Regex>> = LazyLock::new(|| {
9 vec![
10 Regex::new(r"(?i)Transfer-Encoding:.*\r\n.*Transfer-Encoding:").unwrap(),
11 Regex::new(r"(?i)Transfer-Encoding:[\s]*chunked").unwrap(),
12 ]
13});
14
15pub struct RequestSmugglingDetector;
16
17impl Detector for RequestSmugglingDetector {
18 fn name(&self) -> &'static str {
19 "request_smuggling"
20 }
21
22 fn detect(&self, input: &str) -> Option<DetectionResult> {
23 for re in PATTERNS.iter() {
24 if let Some(m) = re.find(input) {
25 return Some(DetectionResult {
26 attack_type: "request_smuggling".into(),
27 category: AttackCategory::Protocol,
28 severity: Severity::High,
29 matched_pattern: m.as_str().to_string(),
30 offset: m.start(),
31 message: "HTTP request smuggling detected".into(),
32 });
33 }
34 }
35 None
36 }
37}