Skip to content

Commit cca7783

Browse files
committed
fix: deduplicate (advisory,version range)
1 parent 53c656b commit cca7783

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

modules/fundamental/src/vulnerability/service/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl VulnerabilityService {
120120
// Extract advisory IDs from JSONB array
121121
#[derive(serde::Deserialize)]
122122
struct AdvisoryEntry {
123-
id: Uuid,
123+
advisory_id: Uuid,
124124
}
125125
impl sea_orm::TryGetableFromJson for AdvisoryEntry {}
126126

@@ -136,7 +136,7 @@ impl VulnerabilityService {
136136
if let Some(advisories) = purl_with_vulnerabilities
137137
.try_get_by::<Option<Vec<AdvisoryEntry>>, _>("advisories")?
138138
{
139-
advisory_ids_set.extend(advisories.into_iter().map(|e| e.id));
139+
advisory_ids_set.extend(advisories.into_iter().map(|e| e.advisory_id));
140140
}
141141
}
142142

@@ -262,9 +262,9 @@ SELECT
262262
vulnerability.withdrawn,
263263
vulnerability.cwes,
264264
jsonb_agg(
265-
jsonb_build_object(
265+
DISTINCT jsonb_build_object(
266266
'status', status.slug,
267-
'id', purl_status.advisory_id,
267+
'advisory_id', purl_status.advisory_id,
268268
'version_range', jsonb_build_object(
269269
'version_scheme_id', version_range.version_scheme_id,
270270
'left', version_range.low_version,
@@ -356,7 +356,7 @@ GROUP BY
356356
#[derive(Debug, serde::Deserialize)]
357357
struct RowEntry {
358358
status: String,
359-
id: Uuid,
359+
advisory_id: Uuid,
360360
version_range: VersionRange,
361361
}
362362
impl sea_orm::TryGetableFromJson for RowEntry {}
@@ -369,7 +369,7 @@ GROUP BY
369369
let statuses = advisories.into_iter().flatten().fold(
370370
BTreeMap::new(),
371371
|mut acc: BTreeMap<Uuid, Vec<RowEntry>>, entry| {
372-
match acc.entry(entry.id) {
372+
match acc.entry(entry.advisory_id) {
373373
Entry::Occupied(mut occupied_entry) => {
374374
occupied_entry.get_mut().push(entry);
375375
}
@@ -383,18 +383,18 @@ GROUP BY
383383

384384
let mut purl_statuses = Vec::new();
385385

386-
for (advisory_id, statuses) in &statuses {
386+
for (advisory_id, entries) in &statuses {
387387
let score = Score::from_iter(
388388
cvss3_map
389389
.get(&(*advisory_id, vulnerability.id.clone()))
390390
.cloned()
391391
.unwrap_or_default(),
392392
);
393-
for status in statuses {
393+
for entry in entries {
394394
let purl_status = PurlStatus::from_head(
395395
head.clone(),
396-
status.status.clone(),
397-
Some(status.version_range.clone()),
396+
entry.status.clone(),
397+
Some(entry.version_range.clone()),
398398
None,
399399
score,
400400
)?;

modules/fundamental/tests/advisory/osv/reingest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async fn withdrawn(ctx: &TrustifyContext) -> anyhow::Result<()> {
132132
status: "affected".to_string(),
133133
context: None,
134134
version_range: Some(VersionRange::Full {
135-
version_scheme_id: "cran".into(),
135+
version_scheme_id: "generic".into(),
136136
left: "1.0".into(),
137137
left_inclusive: true,
138138
right: "1.0".into(),
@@ -153,7 +153,7 @@ async fn withdrawn(ctx: &TrustifyContext) -> anyhow::Result<()> {
153153
status: "affected".to_string(),
154154
context: None,
155155
version_range: Some(VersionRange::Full {
156-
version_scheme_id: "cran".into(),
156+
version_scheme_id: "generic".into(),
157157
left: "1.0".into(),
158158
left_inclusive: true,
159159
right: "1.0".into(),

modules/fundamental/tests/vuln/mod.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,33 @@ async fn issue_1840(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
5757
.filter(|status| status.status == "affected")
5858
.collect();
5959

60-
assert_eq!(status_entries.len(), 1);
60+
assert_eq!(status_entries.len(), 2);
6161
let json = serde_json::to_value(status_entries).expect("must serialize");
6262
assert!(
6363
json.contains_subset(json!([{
64+
"vulnerability": {
65+
"normative": true,
66+
"identifier": "CVE-2024-28834",
67+
"title": "Gnutls: vulnerable to minerva side-channel information leak",
68+
"description": "A flaw was found in GnuTLS. The Minerva attack is a cryptographic vulnerability that exploits deterministic behavior in systems like GnuTLS, leading to side-channel leaks. In specific scenarios, such as when using the GNUTLS_PRIVKEY_FLAG_REPRODUCIBLE flag, it can result in a noticeable step in nonce size from 513 to 512 bits, exposing a potential timing side-channel.",
69+
"reserved": "2024-03-11T14:43:43.973Z",
70+
"published": "2024-03-21T13:29:11.532Z",
71+
"modified": "2024-11-25T02:45:53.454Z",
72+
"withdrawn": null,
73+
"discovered": null,
74+
"released": null,
75+
"cwes": ["CWE-327"]
76+
},
77+
"average_severity": "medium",
78+
"average_score": 5.3,
79+
"status": "affected",
80+
"context": null,
81+
"version_range": {
82+
"version_scheme_id": "rpm",
83+
"right": "3.7.6-23.el9_3.4",
84+
"right_inclusive": false,
85+
}
86+
}, {
6487
"vulnerability": {
6588
"normative": true,
6689
"identifier": "CVE-2024-28834",

0 commit comments

Comments
 (0)