use crate::models::Tier;
pub const BLOCKING_ALLOWLIST: &[&str] = &[
"commandinjection",
"sqlinjection",
"xss",
"ssrf",
"pathtraversal",
"eval",
"unsafetemplate",
"nosqlinjection",
"secret",
"insecuretls",
"jwtweak",
"ghactionsinjection",
];
pub fn is_blocking_allowlisted(detector_name: &str) -> bool {
let n = crate::detectors::normalize_detector_id(detector_name);
BLOCKING_ALLOWLIST.contains(&n.as_str())
}
pub fn detector_max_tier(detector_name: &str) -> Tier {
if is_blocking_allowlisted(detector_name) {
Tier::Blocking
} else {
Tier::Advisory
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::models::Tier;
#[test]
fn allowlist_is_normalized_and_lookup_works() {
for name in BLOCKING_ALLOWLIST {
assert_eq!(
*name,
&crate::detectors::normalize_detector_id(name)[..],
"{name} is not in normalized form"
);
}
assert_eq!(detector_max_tier("SQLInjectionDetector"), Tier::Blocking);
assert_eq!(detector_max_tier("sql-injection"), Tier::Blocking);
assert_eq!(detector_max_tier("sql_injection"), Tier::Blocking);
assert_eq!(detector_max_tier("sqlinjection"), Tier::Blocking);
assert_eq!(detector_max_tier("SecretDetector"), Tier::Blocking);
assert_eq!(
detector_max_tier("GHActionsInjectionDetector"),
Tier::Blocking
);
assert_eq!(detector_max_tier("MagicNumbersDetector"), Tier::Advisory);
assert!(!is_blocking_allowlisted("god-class"));
}
#[test]
fn blocking_allowlist_matches_emitted_detector_field() {
const EMITTED_DETECTOR_IDS: &[&str] = &[
"CommandInjectionDetector",
"SQLInjectionDetector",
"XssDetector",
"SsrfDetector",
"PathTraversalDetector",
"EvalDetector",
"UnsafeTemplateDetector",
"NosqlInjectionDetector",
"SecretDetector",
"InsecureTlsDetector",
"JwtWeakDetector",
"GHActionsInjectionDetector",
];
assert_eq!(EMITTED_DETECTOR_IDS.len(), BLOCKING_ALLOWLIST.len());
for id in EMITTED_DETECTOR_IDS {
assert!(
is_blocking_allowlisted(id),
"{id} emits Finding.detector = \"{id}\" but is not covered by BLOCKING_ALLOWLIST \
(normalized: \"{}\") — a Blocking finding from it would be silently downgraded",
crate::detectors::normalize_detector_id(id)
);
}
}
}