From c529d63cb17fe83d345f8375f785ce57883336fe Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 28 Sep 2026 19:34:46 +0200 Subject: [PATCH] feat(findings): two kinds of Fehlalarm, the rule's and the mapping's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A finding a person rejects can be wrong in two ways, and they need different fixes: the rule fired on code that is fine ("Fehlalarm – Regel", the existing false_positive, relabelled), or the finding is real but does not violate the CRA requirement it was mapped to ("Fehlalarm – Zuordnung", a new wrong_mapping status). Kept apart, they become clean labels for the finding classifier (#416). A wrong mapping needs a reason, like an accepted risk (FindingStatus:: needs_reason, enforced by the agent and asked for on the finding's page). It no longer counts against its controls in the CRA status or the OSCAL report; the finding keeps its control refs, so which mapping was wrong stays on record, and the semantic pass does not map it again. Bulk actions offer neither status that needs a reason. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- compliance-agent/src/api/handlers/findings.rs | 12 ++++++--- compliance-agent/src/controls/scan_triage.rs | 13 ++++++--- compliance-agent/src/evidence/compliance.rs | 13 ++++++--- compliance-core/src/models/finding.rs | 16 +++++++++++ .../src/models/oscal_assessment.rs | 9 +++++-- compliance-dashboard/src/i18n/texts.rs | 23 +++++++++++++--- .../src/pages/finding_detail.rs | 27 +++++++++++++------ compliance-dashboard/src/pages/findings.rs | 8 ++++-- compliance-mcp/src/tools/findings.rs | 4 ++- 9 files changed, 100 insertions(+), 25 deletions(-) diff --git a/compliance-agent/src/api/handlers/findings.rs b/compliance-agent/src/api/handlers/findings.rs index 33fbe29..1314458 100644 --- a/compliance-agent/src/api/handlers/findings.rs +++ b/compliance-agent/src/api/handlers/findings.rs @@ -137,15 +137,16 @@ pub async fn get_finding( })) } -/// The `$set` and `$push` of a status change by `user`, or 422 when an -/// accepted risk comes without a reason. +/// The `$set` and `$push` of a status change by `user`, or 422 when a status +/// that needs a reason (an accepted risk, a wrong CRA mapping) comes without +/// one. fn status_update( status: &FindingStatus, reason: Option<&str>, user: &str, ) -> Result { let reason = reason.map(str::trim).filter(|r| !r.is_empty()); - if *status == FindingStatus::AcceptedRisk && reason.is_none() { + if status.needs_reason() && reason.is_none() { return Err(StatusCode::UNPROCESSABLE_ENTITY); } let change = StatusChange { @@ -253,6 +254,11 @@ mod tests { Some(StatusCode::UNPROCESSABLE_ENTITY) ); assert!(status_update(&FindingStatus::AcceptedRisk, Some("isolated network"), "u").is_ok()); + assert_eq!( + status_update(&FindingStatus::WrongMapping, None, "u").err(), + Some(StatusCode::UNPROCESSABLE_ENTITY) + ); + assert!(status_update(&FindingStatus::FalsePositive, None, "u").is_ok()); assert!(status_update(&FindingStatus::Resolved, None, "u").is_ok()); } diff --git a/compliance-agent/src/controls/scan_triage.rs b/compliance-agent/src/controls/scan_triage.rs index acdf550..f7cab81 100644 --- a/compliance-agent/src/controls/scan_triage.rs +++ b/compliance-agent/src/controls/scan_triage.rs @@ -282,7 +282,12 @@ pub async fn semantic_stamp_findings( let candidates = semantic_candidates(findings); let considered = findings .iter() - .filter(|f| f.status != FindingStatus::FalsePositive && f.control_refs.is_empty()) + .filter(|f| { + !matches!( + f.status, + FindingStatus::FalsePositive | FindingStatus::WrongMapping + ) && f.control_refs.is_empty() + }) .count(); if candidates.len() < considered { tracing::info!( @@ -332,8 +337,10 @@ fn semantic_candidates(findings: &[Finding]) -> Vec { .iter() .enumerate() .filter(|(_, f)| { - f.status != FindingStatus::FalsePositive - && f.control_refs.is_empty() + !matches!( + f.status, + FindingStatus::FalsePositive | FindingStatus::WrongMapping + ) && f.control_refs.is_empty() && f.file_path.is_some() && f.line_number.is_some() }) diff --git a/compliance-agent/src/evidence/compliance.rs b/compliance-agent/src/evidence/compliance.rs index b75dd0e..40ca37e 100644 --- a/compliance-agent/src/evidence/compliance.rs +++ b/compliance-agent/src/evidence/compliance.rs @@ -91,12 +91,13 @@ pub struct ControlStatus { pub findings: Vec, } -/// Whether a finding still counts against its controls: a false positive -/// and a resolved finding do not; an accepted risk still does. +/// Whether a finding still counts against its controls: a false positive, a +/// wrong CRA mapping and a resolved finding do not; an accepted risk still +/// does. fn counts(finding: &Finding) -> bool { !matches!( finding.status, - FindingStatus::FalsePositive | FindingStatus::Resolved + FindingStatus::FalsePositive | FindingStatus::WrongMapping | FindingStatus::Resolved ) } @@ -263,6 +264,8 @@ mod tests { finding("cra-ai-8", FindingStatus::AcceptedRisk), finding("cra-ai-13", FindingStatus::FalsePositive), finding("cra-ai-16", FindingStatus::Resolved), + // A real code issue that does not violate this requirement. + finding("cra-ai-9", FindingStatus::WrongMapping), ]; let statuses = control_statuses(&map, &findings, Some(&c_only()), &[], true); assert_eq!(state_of(&statuses, "cra-ai-8"), ControlState::NotSatisfied); @@ -274,6 +277,10 @@ mod tests { state_of(&statuses, "cra-ai-16"), ControlState::NoViolationFound ); + assert_eq!( + state_of(&statuses, "cra-ai-9"), + ControlState::NoViolationFound + ); let violated = statuses .iter() .find(|s| s.control == "cra-ai-8") diff --git a/compliance-core/src/models/finding.rs b/compliance-core/src/models/finding.rs index 72cd0a0..96da184 100644 --- a/compliance-core/src/models/finding.rs +++ b/compliance-core/src/models/finding.rs @@ -30,6 +30,8 @@ impl std::fmt::Display for Severity { pub enum FindingStatus { Open, Triaged, + /// A person decided the rule fired wrongly: the finding is not real + /// ("Fehlalarm – Regel"). FalsePositive, Resolved, Ignored, @@ -39,6 +41,19 @@ pub enum FindingStatus { /// as possibly not a real issue. It stays open until a person decides; no /// finding is ever hidden automatically. NeedsReview, + /// A person decided the finding does not violate the CRA requirement it + /// was mapped to ("Fehlalarm – Zuordnung"). The code issue may be real; + /// the finding keeps its control refs, so which mapping was wrong stays + /// on record, but it no longer counts against them. + WrongMapping, +} + +impl FindingStatus { + /// Whether setting this status needs a reason from the person setting + /// it (recorded in the status history). + pub fn needs_reason(&self) -> bool { + matches!(self, Self::AcceptedRisk | Self::WrongMapping) + } } impl std::fmt::Display for FindingStatus { @@ -51,6 +66,7 @@ impl std::fmt::Display for FindingStatus { Self::Ignored => write!(f, "ignored"), Self::AcceptedRisk => write!(f, "accepted_risk"), Self::NeedsReview => write!(f, "needs_review"), + Self::WrongMapping => write!(f, "wrong_mapping"), } } } diff --git a/compliance-core/src/models/oscal_assessment.rs b/compliance-core/src/models/oscal_assessment.rs index eeb961b..2b914f7 100644 --- a/compliance-core/src/models/oscal_assessment.rs +++ b/compliance-core/src/models/oscal_assessment.rs @@ -97,8 +97,13 @@ pub fn assess(findings: &[Finding], at: DateTime) -> AssessmentResultsDoc { let mut unmapped = 0usize; for finding in findings { - if finding.status == FindingStatus::FalsePositive { - continue; // flagged tool false positive — excluded from the report + // A person decided it is not real, or does not violate the mapped + // requirement: it is not evidence against a control. + if matches!( + finding.status, + FindingStatus::FalsePositive | FindingStatus::WrongMapping + ) { + continue; } let obs_uuid = det_uuid(&format!("obs:{}", finding.fingerprint)); let location = match (&finding.file_path, finding.line_number) { diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index fe2dc16..60e3d2d 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -1533,8 +1533,8 @@ pub mod findings { en: "Triaged", }, FindingStatus::FalsePositive => Text { - de: "Fehlalarm", - en: "False positive", + de: "Fehlalarm – Regel", + en: "False positive – rule", }, FindingStatus::Resolved => Text { de: "Behoben", @@ -1552,6 +1552,10 @@ pub mod findings { de: "Zu prüfen", en: "Needs review", }, + FindingStatus::WrongMapping => Text { + de: "Fehlalarm – Zuordnung", + en: "False positive – mapping", + }, } } @@ -1599,12 +1603,25 @@ pub mod findings { ]; /// Every status, in the order the forms offer them. - pub const STATUSES: [FindingStatus; 7] = [ + pub const WRONG_MAPPING_HINT: Text = Text { + de: "Warum verletzt der Befund die zugeordnete CRA-Anforderung nicht (z. B. der Code \ + ist in Ordnung, oder die Anforderung betrifft etwas anderes)? Die Begründung hilft, \ + künftige Zuordnungen zu verbessern.", + en: "Why does the finding not violate the CRA requirement it was mapped to (e.g. the \ + code is fine, or the requirement is about something else)? The reason helps \ + improve future mappings.", + }; + pub const CONFIRM_WRONG_MAPPING: Text = Text { + de: "Als Fehlalarm – Zuordnung markieren", + en: "Mark as false positive – mapping", + }; + pub const STATUSES: [FindingStatus; 8] = [ FindingStatus::Open, FindingStatus::NeedsReview, FindingStatus::Triaged, FindingStatus::Resolved, FindingStatus::FalsePositive, + FindingStatus::WrongMapping, FindingStatus::AcceptedRisk, FindingStatus::Ignored, ]; diff --git a/compliance-dashboard/src/pages/finding_detail.rs b/compliance-dashboard/src/pages/finding_detail.rs index fc8c26f..1623f31 100644 --- a/compliance-dashboard/src/pages/finding_detail.rs +++ b/compliance-dashboard/src/pages/finding_detail.rs @@ -27,7 +27,9 @@ pub fn FindingDetailPage(id: String) -> Element { let mut status_save = use_signal(|| SaveState::Idle); let mut feedback_save = use_signal(|| SaveState::Idle); // Accepting a risk asks for a reason before it is saved. - let mut accepting = use_signal(|| false); + // A status that needs a reason (accepted risk, wrong mapping) asks for it + // before it is saved. + let mut reasoning_for = use_signal(|| Option::::None); let mut risk_reason = use_signal(String::new); let mut finding = use_resource(move || { @@ -248,8 +250,8 @@ pub fn FindingDetailPage(id: String) -> Element { title: "{label}", disabled: current, onclick: move |_| { - if status == FindingStatus::AcceptedRisk { - accepting.set(true); + if status.needs_reason() { + reasoning_for.set(Some(status.clone())); return; } let s = wire.clone(); @@ -271,10 +273,14 @@ pub fn FindingDetailPage(id: String) -> Element { } } } - if accepting() { + if let Some(pending) = reasoning_for() { div { style: "margin-top: 10px;", p { style: "font-size: 13px; color: var(--text-secondary); margin-bottom: 6px;", - {tx::ACCEPT_RISK_HINT.get(lang)} + if pending == FindingStatus::WrongMapping { + {tx::WRONG_MAPPING_HINT.get(lang)} + } else { + {tx::ACCEPT_RISK_HINT.get(lang)} + } } textarea { style: "width: 100%; min-height: 60px;", @@ -288,17 +294,18 @@ pub fn FindingDetailPage(id: String) -> Element { onclick: move |_| { let id = finding_id_for_risk.clone(); let reason = risk_reason(); + let status = wire_name(&pending); spawn(async move { match crate::infrastructure::findings::update_finding_status( id, - wire_name(&FindingStatus::AcceptedRisk), + status, Some(reason), ) .await { Ok(()) => { status_save.set(SaveState::Saved); - accepting.set(false); + reasoning_for.set(None); risk_reason.set(String::new()); } Err(e) => status_save.set(SaveState::Failed(e.to_string())), @@ -306,7 +313,11 @@ pub fn FindingDetailPage(id: String) -> Element { finding.restart(); }); }, - {tx::ACCEPT_RISK.get(lang)} + if pending == FindingStatus::WrongMapping { + {tx::CONFIRM_WRONG_MAPPING.get(lang)} + } else { + {tx::ACCEPT_RISK.get(lang)} + } } } } diff --git a/compliance-dashboard/src/pages/findings.rs b/compliance-dashboard/src/pages/findings.rs index 6b0b197..229ec2c 100644 --- a/compliance-dashboard/src/pages/findings.rs +++ b/compliance-dashboard/src/pages/findings.rs @@ -172,11 +172,12 @@ pub fn FindingsPage(target: String) -> Element { style: "font-size: 14px; color: var(--text-secondary);", "{selected_ids().len()} {tx::SELECTED.get(lang)}" } - // Accepting a risk needs a reason per finding: on its page. + // An accepted risk or a wrong mapping needs a reason per + // finding: on its page. for status in tx::STATUSES .into_iter() .skip(1) - .filter(|s| *s != compliance_core::models::FindingStatus::AcceptedRisk) + .filter(|s| !s.needs_reason()) { { let label = tx::status(&status).get(lang); @@ -406,6 +407,9 @@ pub fn status_icon(status: &compliance_core::models::FindingStatus) -> Element { FindingStatus::FalsePositive => rsx! { Icon { icon: BsXCircle, width: 12, height: 12 } }, FindingStatus::Ignored => rsx! { Icon { icon: BsDashCircle, width: 12, height: 12 } }, FindingStatus::AcceptedRisk => rsx! { Icon { icon: BsShieldCheck, width: 12, height: 12 } }, + FindingStatus::WrongMapping => { + rsx! { Icon { icon: BsSignpostSplit, width: 12, height: 12 } } + } FindingStatus::NeedsReview => { rsx! { Icon { icon: BsQuestionCircle, width: 12, height: 12 } } } diff --git a/compliance-mcp/src/tools/findings.rs b/compliance-mcp/src/tools/findings.rs index acf4fa9..a13679a 100644 --- a/compliance-mcp/src/tools/findings.rs +++ b/compliance-mcp/src/tools/findings.rs @@ -101,7 +101,8 @@ pub struct ListFindingsParams { pub repo_id: Option, /// Filter by severity: info, low, medium, high, critical pub severity: Option, - /// Filter by status: open, triaged, false_positive, resolved, ignored + /// Filter by status: open, triaged, needs_review, false_positive, wrong_mapping, + /// accepted_risk, resolved, ignored pub status: Option, /// Filter by scan type: sast, sbom, cve, gdpr, oauth, secret_detection, lint, code_review pub scan_type: Option, @@ -230,6 +231,7 @@ pub async fn findings_summary( "ignored", "accepted_risk", "needs_review", + "wrong_mapping", ] { let mut filter = base_filter.clone(); filter.insert("status", status); -- 2.54.1