fix(report): keep a dependent field the revision restates unchanged

ReportState.update_vulnerability_report skipped a supplied field equal
to the stored value when building `changed`, then decided which
dependents were superseded from `changed`. A rationale the revision
explicitly restated therefore counted as absent and was dropped: moving
confidence from low to medium while resubmitting the same
confidence_rationale stored medium with no rationale, the state
create_vulnerability_report rejects. The same happened to unchanged
severity_change_conditions sent with a severity-moving cvss_breakdown.

Record every field the revision states, equal or not, and only drop a
dependent that was not supplied. Restating a rationale affirms it still
holds for the new rating. `changed` is built exactly as before, so
no-op detection and update_history.fields are unaffected.

Reported by review on #1307.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
itzzdev09 2026-09-13 22:51:57 +05:30
parent 099d149706
commit 80b8336073
2 changed files with 48 additions and 1 deletions

View file

@ -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:

View file

@ -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]