Skip to content

Commit bcc41f6

Browse files
authored
fix: avoid duplicated CVE recommendations (#301)
Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent adce51f commit bcc41f6

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/main/java/com/redhat/exhort/integration/trustedcontent/TcResponseHandler.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.redhat.exhort.model.trustedcontent.Recommendations;
4343
import com.redhat.exhort.model.trustedcontent.TcRecommendation;
4444
import com.redhat.exhort.model.trustedcontent.TrustedContentResponse;
45+
import com.redhat.exhort.model.trustedcontent.Vulnerability;
4546

4647
import io.quarkus.runtime.annotations.RegisterForReflection;
4748

@@ -53,6 +54,10 @@
5354
@RegisterForReflection
5455
public class TcResponseHandler extends ProviderResponseHandler {
5556

57+
// Other values are Affected and UnderInvestigation
58+
// see https://www.cisa.gov/sites/default/files/2023-01/VEX_Status_Justification_Jun22.pdf
59+
private static final List<String> FIXED_STATUSES = List.of("NotAffected", "Fixed");
60+
5661
@Inject ObjectMapper mapper;
5762

5863
@ConfigProperty(name = "trustedcontent.recommended.ubi")
@@ -91,7 +96,7 @@ private IndexedRecommendation aggregateRecommendations(List<TcRecommendation> re
9196
recommendations.stream()
9297
.map(TcRecommendation::vulnerabilities)
9398
.flatMap(List::stream)
94-
.collect(Collectors.toMap(v -> v.getId().toUpperCase(), v -> v)));
99+
.collect(Collectors.toMap(v -> v.getId().toUpperCase(), v -> v, this::filterFixed)));
95100
}
96101

97102
private PackageRef getHighestRemediationRecommendation(List<TcRecommendation> tcRecommendations) {
@@ -138,4 +143,11 @@ public ProviderResponse responseToIssues(
138143
byte[] response, String privateProviders, DependencyTree tree) throws IOException {
139144
throw new UnsupportedOperationException("Not yet implemented");
140145
}
146+
147+
private Vulnerability filterFixed(Vulnerability a, Vulnerability b) {
148+
if (!FIXED_STATUSES.contains(a.getStatus())) {
149+
return a;
150+
}
151+
return b;
152+
}
141153
}

src/test/resources/__files/trustedcontent/simple.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"vulnerabilities": [
2929
{
3030
"id": "cve-2020-36518",
31-
"status": "NotAffected",
31+
"status": "Affected",
3232
"justification": "VulnerableCodeNotPresent"
3333
}
3434
]
@@ -40,6 +40,11 @@
4040
"id": "cve-2023-44487",
4141
"status": "NotAffected",
4242
"justification": "VulnerableCodeNotPresent"
43+
},
44+
{
45+
"id": "cve-2020-36518",
46+
"status": "NotAffected",
47+
"justification": "VulnerableCodeNotPresent"
4348
}
4449
]
4550
},

0 commit comments

Comments
 (0)