diff --git a/strix/report/state.py b/strix/report/state.py index ac15db899..7a952e71b 100644 --- a/strix/report/state.py +++ b/strix/report/state.py @@ -442,6 +442,10 @@ class ReportState: return None changed: dict[str, Any] = {} + # Every field the revision states, including one that repeats the stored + # value. Resubmitting a rationale unchanged affirms it still holds for the + # new rating, so it must not be dropped as superseded below. + supplied: set[str] = set() for key, raw_value in fields.items(): if key not in UPDATABLE_REPORT_FIELDS or raw_value is None: continue @@ -452,6 +456,7 @@ class ReportState: value = value.lower() if not value: continue + supplied.add(key) if report.get(key) == value: continue changed[key] = value @@ -461,7 +466,7 @@ class ReportState: for primary, dependents in _DEPENDENT_REPORT_FIELDS.items() if primary in changed for dependent in dependents - if dependent not in changed and report.get(dependent) not in (None, "", [], {}) + if dependent not in supplied and report.get(dependent) not in (None, "", [], {}) } if not changed and not superseded: diff --git a/tests/test_reporting_fields.py b/tests/test_reporting_fields.py index 9ce39c8b0..73b297331 100644 --- a/tests/test_reporting_fields.py +++ b/tests/test_reporting_fields.py @@ -2109,3 +2109,45 @@ def test_update_does_not_apply_dynamic_rules_to_a_dependency_finding( ) assert result["success"] is True + + +def test_update_keeps_a_rationale_resubmitted_unchanged_with_a_new_confidence( + report_state: ReportState, +) -> None: + """Restating the stored rationale affirms it for the new rating; it must survive.""" + _seed_weak_report(report_state) + report_state.vulnerability_reports[0]["confidence_rationale"] = "Static trace only." + + result = _do_update( + report_id="vuln-0009", + update_reason="Reachability confirmed statically; still no runtime access.", + fields={"confidence": "medium", "confidence_rationale": "Static trace only."}, + ) + + assert result["success"] is True + report = report_state.vulnerability_reports[0] + assert report["confidence"] == "medium" + assert report["confidence_rationale"] == "Static trace only.", ( + "an explicitly resubmitted rationale must not be dropped as superseded" + ) + assert "dropped_fields" not in report["update_history"][-1] + + +def test_update_keeps_severity_conditions_resubmitted_unchanged_with_a_new_vector( + report_state: ReportState, +) -> None: + _seed_weak_report(report_state) + conditions = "A guard before the write would remove the impact." + report_state.vulnerability_reports[0]["severity_change_conditions"] = conditions + + result = _do_update( + report_id="vuln-0009", + update_reason="Confirmed unauthenticated write.", + fields={"cvss_breakdown": _CVSS, "severity_change_conditions": conditions}, + ) + + assert result["success"] is True + assert result["severity"] == "critical" + report = report_state.vulnerability_reports[0] + assert report["severity_change_conditions"] == conditions + assert "dropped_fields" not in report["update_history"][-1]