use crate::models::{Category, ScanProfile};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OperationKind {
PassiveAnalysis,
ActiveProbe,
}
#[derive(Debug, Clone, Copy)]
pub struct CheckDefinition {
pub id: &'static str,
pub name: &'static str,
pub category: Category,
pub operation_kind: OperationKind,
pub applicable_web: bool,
pub applicable_api: bool,
pub remediation_key: &'static str,
}
impl CheckDefinition {
pub fn applies_to(&self, profile: ScanProfile) -> bool {
match profile {
ScanProfile::Web => self.applicable_web,
ScanProfile::Api => self.applicable_api,
}
}
}
pub const BUILTIN_CHECKS: &[CheckDefinition] = &[
CheckDefinition {
id: "tls-inspection",
name: "TLS Handshake & Certificate Inspection",
category: Category::TransportTls,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: true,
remediation_key: "tls",
},
CheckDefinition {
id: "http-redirect",
name: "HTTP-to-HTTPS Redirect Verification",
category: Category::TransportTls,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: true,
remediation_key: "https_redirect",
},
CheckDefinition {
id: "dns-hygiene",
name: "DNS CAA, SPF, and DMARC Records",
category: Category::DnsEmail,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: true,
remediation_key: "dns",
},
CheckDefinition {
id: "security-headers",
name: "OWASP Security Headers & Stack Disclosure",
category: Category::SecurityHeaders,
operation_kind: OperationKind::PassiveAnalysis,
applicable_web: true,
applicable_api: true,
remediation_key: "headers",
},
CheckDefinition {
id: "cookie-attributes",
name: "Set-Cookie Security Attributes",
category: Category::Cookies,
operation_kind: OperationKind::PassiveAnalysis,
applicable_web: true,
applicable_api: true,
remediation_key: "cookies",
},
CheckDefinition {
id: "cache-control",
name: "Sensitive Response Cache-Control",
category: Category::HttpProtocol,
operation_kind: OperationKind::PassiveAnalysis,
applicable_web: true,
applicable_api: true,
remediation_key: "caching",
},
CheckDefinition {
id: "cors-policy",
name: "CORS Origin Reflection & Wildcard Policy",
category: Category::Cors,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: true,
remediation_key: "cors",
},
CheckDefinition {
id: "http-methods",
name: "HTTP OPTIONS & TRACE Method Probe",
category: Category::HttpProtocol,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: true,
remediation_key: "methods",
},
CheckDefinition {
id: "html-client-hygiene",
name: "HTML Mixed Content, SRI, Forms & JS Libraries",
category: Category::ClientHtml,
operation_kind: OperationKind::PassiveAnalysis,
applicable_web: true,
applicable_api: false,
remediation_key: "html",
},
CheckDefinition {
id: "exposed-artifacts",
name: "Exposed Deployment Metadata & Config Paths",
category: Category::ExposedFiles,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: true,
remediation_key: "dotfiles",
},
CheckDefinition {
id: "tls-legacy-versions",
name: "Legacy TLS 1.0 / 1.1 Handshake Probe",
category: Category::TransportTls,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: true,
remediation_key: "tls_legacy",
},
CheckDefinition {
id: "response-secrets-leaks",
name: "Response Secret, Private Key, JWT & Stacktrace Audit",
category: Category::SecretsAndLeaks,
operation_kind: OperationKind::PassiveAnalysis,
applicable_web: true,
applicable_api: true,
remediation_key: "secrets",
},
CheckDefinition {
id: "js-bundle-discovery",
name: "JS Bundle Advisory, SourceMap & Route Discovery",
category: Category::ClientHtml,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: false,
remediation_key: "js_bundles",
},
CheckDefinition {
id: "openapi-security",
name: "OpenAPI / Swagger Spec & Endpoint Hygiene Audit",
category: Category::ApiSecurity,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: true,
remediation_key: "openapi",
},
CheckDefinition {
id: "unauth-route-access",
name: "Anonymous vs Authenticated Access Parity Check",
category: Category::ApiSecurity,
operation_kind: OperationKind::ActiveProbe,
applicable_web: true,
applicable_api: true,
remediation_key: "auth_parity",
},
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn registry_has_unique_ids_and_profile_applicability() {
let mut seen = std::collections::HashSet::new();
for def in BUILTIN_CHECKS {
assert!(seen.insert(def.id), "duplicate check id {}", def.id);
}
let html_def = BUILTIN_CHECKS
.iter()
.find(|c| c.id == "html-client-hygiene")
.unwrap();
assert!(html_def.applies_to(ScanProfile::Web));
assert!(!html_def.applies_to(ScanProfile::Api));
}
}