This commit was merged in pull request #385.
This commit is contained in:
1 parent
5f7c947fb3
commit
62da6dbbf7
12 files changed
+631
-48
No files matched your search
@@ -30,6 +30,11 @@ pub struct ScanBinding {
|
||||
pub tool: String,
|
||||
/// Scan family, e.g. `"sast"`, `"secret_detection"`, `"sbom"`, `"cve"`.
|
||||
pub scan_type: String,
|
||||
/// The source languages this binding checks (`"c"`, `"python"`, …), as
|
||||
/// the rules behind it declare them. Empty means language-independent
|
||||
/// (secrets in any file, dependencies from any manifest).
|
||||
#[serde(default)]
|
||||
pub languages: Vec<String>,
|
||||
/// CWEs whose findings map to this control (used to attach findings back).
|
||||
#[serde(default)]
|
||||
pub cwe: Vec<String>,
|
||||
@@ -38,6 +43,13 @@ pub struct ScanBinding {
|
||||
pub rules: Vec<String>,
|
||||
}
|
||||
|
||||
impl ScanBinding {
|
||||
/// Whether this binding checks code in any of `languages`.
|
||||
pub fn applies_to(&self, languages: &[String]) -> bool {
|
||||
self.languages.is_empty() || self.languages.iter().any(|l| languages.contains(l))
|
||||
}
|
||||
}
|
||||
|
||||
/// One control's entry in the LUT.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ControlEntry {
|
||||
@@ -56,6 +68,15 @@ pub struct ControlEntry {
|
||||
pub note: Option<String>,
|
||||
}
|
||||
|
||||
impl ControlEntry {
|
||||
/// Whether a scan of code in `languages` checks this control at all: at
|
||||
/// least one of its bindings applies. Only then can "no violation found"
|
||||
/// be claimed for it.
|
||||
pub fn checked_for(&self, languages: &[String]) -> bool {
|
||||
self.scans.iter().any(|s| s.applies_to(languages))
|
||||
}
|
||||
}
|
||||
|
||||
/// The control → scan lookup table for one framework.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ControlMap {
|
||||
@@ -190,6 +211,43 @@ mod tests {
|
||||
assert_eq!(map.summary().total(), 40);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_control_is_checked_only_for_the_languages_its_rules_cover() {
|
||||
let map = ControlMap::cra().expect("map");
|
||||
let c_only = ["c".to_string()];
|
||||
let python = ["python".to_string()];
|
||||
let secure_defaults = map.coverage("cra-ai-1").expect("cra-ai-1");
|
||||
let memory_safety = map.coverage("cra-ai-20").expect("cra-ai-20");
|
||||
let secrets = map.coverage("cra-ai-9").expect("cra-ai-9");
|
||||
|
||||
// Only Python/JS rules check secure defaults.
|
||||
assert!(!secure_defaults.checked_for(&c_only));
|
||||
assert!(secure_defaults.checked_for(&python));
|
||||
// Our C rules and cppcheck check memory safety in C.
|
||||
assert!(memory_safety.checked_for(&c_only));
|
||||
// gitleaks reads any file, so no language is needed.
|
||||
assert!(secrets.checked_for(&[]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_code_binding_names_its_languages() {
|
||||
// Only tools that do not read source code may be language-independent;
|
||||
// a rule binding without languages would claim every language.
|
||||
let map = ControlMap::cra().expect("map");
|
||||
for control in &map.controls {
|
||||
for scan in &control.scans {
|
||||
let reads_code = !matches!(scan.tool.as_str(), "gitleaks" | "syft" | "osv");
|
||||
assert_eq!(
|
||||
reads_code,
|
||||
!scan.languages.is_empty(),
|
||||
"{} / {}",
|
||||
control.control,
|
||||
scan.tool
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hardcoded_password_control_is_tool_covered() {
|
||||
let map = ControlMap::cra().unwrap();
|
||||
|
||||
Reference in new issue
Block a user