fix(compliance): an empty SBOM claims nothing about the SBOM requirements (#412)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 5s
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Successful in 9m11s
CI / Deploy Dashboard (push) Successful in 11m42s

This commit was merged in pull request #412.
This commit is contained in:
sharang committed 2026-09-26 10:22:15 +00:00
1 parent bcb6bfd91c
commit 17633083e0
3 files changed
+62 -10

No files matched your search

+49 -10
View File
@@ -41,8 +41,14 @@ pub enum NotAssessedReason {
/// A tool that checks it did not complete in the last scan (semgrep,
/// cppcheck, or the CVE lookup), so nothing can be claimed either way.
ToolFailed { tools: Vec<String> },
/// The control is checked on the target's components (the SBOM and its
/// CVE lookup), and the scan found none: an empty SBOM proves nothing.
NoComponents,
}
/// The tools that check a target's components rather than its code.
const COMPONENT_TOOLS: [&str; 2] = ["syft", "osv"];
/// The tool a skipped stage of a scan run stands for, when that stage is one
/// a control's binding relies on.
pub fn tool_of_stage(stage: &str) -> Option<&'static str> {
@@ -107,6 +113,7 @@ pub fn control_statuses(
findings: &[Finding],
scanned_languages: Option<&[String]>,
failed_tools: &[&str],
has_components: bool,
) -> Vec<ControlStatus> {
map.controls
.iter()
@@ -148,13 +155,22 @@ pub fn control_statuses(
.map(str::to_owned)
.collect();
failed.dedup();
if failed.is_empty() {
(ControlState::NoViolationFound, None)
} else {
let on_components_only = entry
.scans
.iter()
.all(|b| COMPONENT_TOOLS.contains(&b.tool.as_str()));
if !failed.is_empty() {
(
ControlState::NotAssessed,
Some(NotAssessedReason::ToolFailed { tools: failed }),
)
} else if on_components_only && !has_components {
(
ControlState::NotAssessed,
Some(NotAssessedReason::NoComponents),
)
} else {
(ControlState::NoViolationFound, None)
}
}
(Coverage::Covered, Some([])) => (
@@ -228,7 +244,7 @@ mod tests {
#[test]
fn every_control_gets_exactly_one_state() {
let map = ControlMap::cra().expect("map");
let statuses = control_statuses(&map, &[], Some(&python()), &[]);
let statuses = control_statuses(&map, &[], Some(&python()), &[], true);
assert_eq!(statuses.len(), map.controls.len());
assert_eq!(
state_of(&statuses, "cra-ai-8"),
@@ -248,7 +264,7 @@ mod tests {
finding("cra-ai-13", FindingStatus::FalsePositive),
finding("cra-ai-16", FindingStatus::Resolved),
];
let statuses = control_statuses(&map, &findings, Some(&c_only()), &[]);
let statuses = control_statuses(&map, &findings, Some(&c_only()), &[], true);
assert_eq!(state_of(&statuses, "cra-ai-8"), ControlState::NotSatisfied);
assert_eq!(
state_of(&statuses, "cra-ai-13"),
@@ -272,7 +288,7 @@ mod tests {
#[test]
fn a_c_scan_claims_nothing_for_controls_only_python_rules_check() {
let map = ControlMap::cra().expect("map");
let statuses = control_statuses(&map, &[], Some(&c_only()), &[]);
let statuses = control_statuses(&map, &[], Some(&c_only()), &[], true);
// Our C rules and cppcheck checked memory safety; gitleaks, secrets.
assert_eq!(
@@ -298,7 +314,7 @@ mod tests {
fn a_mixed_scan_counts_every_language() {
let map = ControlMap::cra().expect("map");
let mixed = vec!["c".to_string(), "python".to_string()];
let statuses = control_statuses(&map, &[], Some(&mixed), &[]);
let statuses = control_statuses(&map, &[], Some(&mixed), &[], true);
assert_eq!(
state_of(&statuses, "cra-ai-1"),
ControlState::NoViolationFound
@@ -312,7 +328,7 @@ mod tests {
#[test]
fn a_scan_without_recorded_languages_only_trusts_language_independent_tools() {
let map = ControlMap::cra().expect("map");
let statuses = control_statuses(&map, &[], Some(&[]), &[]);
let statuses = control_statuses(&map, &[], Some(&[]), &[], true);
assert_eq!(
state_of(&statuses, "cra-ai-9"),
ControlState::NoViolationFound
@@ -323,10 +339,33 @@ mod tests {
);
}
#[test]
fn an_empty_sbom_claims_nothing_about_components() {
let map = ControlMap::cra().expect("map");
let statuses = control_statuses(&map, &[], Some(&c_only()), &[], false);
// cra-ai-22/23/33 are checked on components only: with none found,
// nothing was checked.
for control in ["cra-ai-22", "cra-ai-23", "cra-ai-33"] {
assert_eq!(
status_of(&statuses, control).reason,
Some(NotAssessedReason::NoComponents),
"{control}"
);
}
// Controls checked in the code are unaffected.
assert_eq!(
state_of(&statuses, "cra-ai-20"),
ControlState::NoViolationFound
);
// With components, the SBOM controls are assessed as before.
let with = control_statuses(&map, &[], Some(&c_only()), &[], true);
assert_eq!(state_of(&with, "cra-ai-23"), ControlState::NoViolationFound);
}
#[test]
fn a_failed_cve_lookup_claims_nothing_about_component_cves() {
let map = ControlMap::cra().expect("map");
let statuses = control_statuses(&map, &[], Some(&c_only()), &["osv"]);
let statuses = control_statuses(&map, &[], Some(&c_only()), &["osv"], true);
// cra-ai-22 relies on the CVE lookup (osv) and the SBOM (syft).
assert_eq!(
status_of(&statuses, "cra-ai-22").reason,
@@ -346,7 +385,7 @@ mod tests {
#[test]
fn nothing_is_passed_before_a_scan() {
let map = ControlMap::cra().expect("map");
let statuses = control_statuses(&map, &[], None, &[]);
let statuses = control_statuses(&map, &[], None, &[], true);
assert_eq!(state_of(&statuses, "cra-ai-8"), ControlState::NotAssessed);
assert_eq!(
status_of(&statuses, "cra-ai-8").reason,
+1
View File
@@ -183,6 +183,7 @@ pub fn compliance_of(inputs: &EvidenceInputs) -> Vec<compliance::ControlStatus>
&inputs.findings,
scanned_languages(inputs),
&failed_tools(inputs),
!inputs.sbom.is_empty(),
);
// The catalog's own ratings, next to our state.
for status in &mut statuses {
+12
View File
@@ -1838,6 +1838,13 @@ pub mod compliance {
de: "Nicht bewertet",
en: "Not assessed",
};
pub const NO_COMPONENTS: Text = Text {
de: "Die letzte Prüfung hat keine Komponenten erkannt, also wurde nichts geprüft. \
Die Stückliste entsteht aus einem Lockfile, den Firmware-Quellen oder einem \
SPS-Projektarchiv.",
en: "The last scan found no components, so nothing was checked. The SBOM comes \
from a lockfile, the firmware sources or a PLC project archive.",
};
pub const NO_TOOL: Text = Text {
de: "Im Code prüfbar, aber noch ohne Prüfregel.",
en: "Checkable in code, but no rule checks it yet.",
@@ -1995,6 +2002,7 @@ pub mod compliance {
)
),
"languages_unknown" => LANGUAGES_UNKNOWN.get(lang).to_string(),
"no_components" => NO_COMPONENTS.get(lang).to_string(),
"tool_failed" => format!(
"{} {}",
TOOL_FAILED.get(lang),
@@ -2055,6 +2063,10 @@ pub mod compliance {
not_assessed_reason(&serde_json::json!({ "kind": "no_tool" }), Lang::En).as_deref(),
Some("Checkable in code, but no rule checks it yet.")
);
assert!(
not_assessed_reason(&serde_json::json!({ "kind": "no_components" }), Lang::De)
.is_some_and(|text| text.contains("keine Komponenten"))
);
assert_eq!(
not_assessed_reason(&serde_json::Value::Null, Lang::En),
None