feat(findings): two kinds of Fehlalarm, the rule's and the mapping's
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 7m1s

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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-09-28 19:34:46 +02:00
1 parent e9bda32dc6
commit c529d63cb1
9 files changed
+100 -25

No files matched your search

@@ -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<mongodb::bson::Document, StatusCode> {
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());
}
+10 -3
View File
@@ -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<usize> {
.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()
})
+10 -3
View File
@@ -91,12 +91,13 @@ pub struct ControlStatus {
pub findings: Vec<FindingRef>,
}
/// 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")
+16
View File
@@ -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"),
}
}
}
@@ -97,8 +97,13 @@ pub fn assess(findings: &[Finding], at: DateTime<Utc>) -> 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) {
+20 -3
View File
@@ -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,
];
@@ -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::<FindingStatus>::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)}
}
}
}
}
+6 -2
View File
@@ -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 } }
}
+3 -1
View File
@@ -101,7 +101,8 @@ pub struct ListFindingsParams {
pub repo_id: Option<String>,
/// Filter by severity: info, low, medium, high, critical
pub severity: Option<String>,
/// 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<String>,
/// Filter by scan type: sast, sbom, cve, gdpr, oauth, secret_detection, lint, code_review
pub scan_type: Option<String>,
@@ -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);