use std::fmt;
use crate::waf_detect::rules;
pub use crate::waf_detect::rules::{DetectConfig, DetectedWaf};
pub const ACTIONABLE_CONFIDENCE_THRESHOLD: f64 = 0.5;
impl fmt::Display for DetectedWaf {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
formatter,
"{} (confidence: {:.0}%, indicators: {})",
self.name,
self.confidence * 100.0,
self.indicators.join(", ")
)
}
}
#[must_use]
pub fn detect(status: u16, headers: &[(String, String)], body: &[u8]) -> Vec<DetectedWaf> {
let lower_headers: Vec<(String, String)> = headers
.iter()
.map(|(key, value)| (key.to_ascii_lowercase(), value.to_ascii_lowercase()))
.collect();
let body_str = String::from_utf8_lossy(&body[..body.len().min(4096)]).to_ascii_lowercase();
rules::detect_with_config(status, &lower_headers, &body_str, DetectConfig::default())
}
#[must_use]
pub fn supported_wafs() -> Vec<String> {
rules::supported_wafs()
}