From e62c71972da2fbb66499f38579928834c39668e3 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Sat, 26 Sep 2026 11:57:30 +0200 Subject: [PATCH] fix(compliance): an empty SBOM claims nothing about the SBOM requirements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A target whose scan found no components showed cra-ai-22, 23 and 33 ("Software Bill of Materials", "SBOM-Pflege", "Dependency-Monitoring") as "Kein Verstoß gefunden", although nothing was checked. Requirements checked on components only (syft and the CVE lookup) are now "Nicht bewertet" with the reason "no components found" when the SBOM is empty; a failed tool still takes precedence. Requirements checked in the code are unaffected, and the OSCAL export (which reports violations only) is unchanged. Closes #404. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- compliance-agent/src/evidence/compliance.rs | 59 +++++++++++++++++---- compliance-agent/src/evidence/mod.rs | 1 + compliance-dashboard/src/i18n/texts.rs | 12 +++++ 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/compliance-agent/src/evidence/compliance.rs b/compliance-agent/src/evidence/compliance.rs index 5723a0c..b75dd0e 100644 --- a/compliance-agent/src/evidence/compliance.rs +++ b/compliance-agent/src/evidence/compliance.rs @@ -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 }, + /// 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 { 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, diff --git a/compliance-agent/src/evidence/mod.rs b/compliance-agent/src/evidence/mod.rs index 99cab4f..4e57252 100644 --- a/compliance-agent/src/evidence/mod.rs +++ b/compliance-agent/src/evidence/mod.rs @@ -183,6 +183,7 @@ pub fn compliance_of(inputs: &EvidenceInputs) -> Vec &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 { diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 03e4331..af9229e 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -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