fix(cve): an alert keeps when it was first found when a scan reports it again (#1041) (#1045)
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Successful in 5m59s

This commit was merged in pull request #1045.
This commit is contained in:
sharang committed 2026-11-17 12:59:51 +00:00
1 parent eff6f92a33
commit 832f9b13e1
2 files changed
+18 -2

No files matched your search

+10 -2
View File
@@ -110,8 +110,12 @@ pub async fn upsert_reported(db: &Database, alert: &CveAlert) -> Result<(), Agen
let filter = doc! { "cve_id": &alert.cve_id, "repo_id": &alert.repo_id };
// The alert as found now; a VEX statement on it is left as it is (the
// alert carries none), and it is reported again.
let found = mongodb::bson::to_document(alert)
let mut found = mongodb::bson::to_document(alert)
.map_err(|e| AgentError::Other(format!("encode CVE alert: {e}")))?;
// When it was first found is written once (#1041): every scan builds its
// alerts anew, and a rescan must neither list it as new again nor move
// it later in the CVE history.
let first_found = found.remove("created_at");
// A purl is written when the scan knows one and otherwise kept (an alert
// stored before purls were recorded gets one on its next scan); kept only
// while it is the purl of the same package and version.
@@ -134,8 +138,12 @@ pub async fn upsert_reported(db: &Database, alert: &CveAlert) -> Result<(), Agen
if alert.supplier_vex.is_none() {
unset.insert("supplier_vex", "");
}
let mut update = doc! { "$set": found, "$unset": unset };
if let Some(first_found) = first_found {
update.insert("$setOnInsert", doc! { "created_at": first_found });
}
db.cve_alerts()
.update_one(filter.clone(), doc! { "$set": found, "$unset": unset })
.update_one(filter.clone(), update)
.upsert(true)
.await?;
// The first scan that finds it actively exploited starts the CRA's
+8
View File
@@ -149,6 +149,14 @@ async fn vex_status_follows_the_scans_but_never_overrides_a_person() {
upsert_reported(&db, &exploited).await.unwrap();
assert_eq!(stored(&db, "CVE-5").await.exploited_seen_at, Some(first));
// When it was first found stays (#1041): a scan reporting it again
// builds it with a later `created_at`, which is not kept.
let first_found = stored(&db, "CVE-5").await.created_at;
let mut again = alert("CVE-5");
again.created_at = first_found + chrono::Duration::hours(5);
upsert_reported(&db, &again).await.unwrap();
assert_eq!(stored(&db, "CVE-5").await.created_at, first_found);
// An alert stored without a purl gets its component's on the next scan;
// a scan that knows none keeps it, unless the alert is now about another
// component.