Skip to content

Commit 25606aa

Browse files
authored
fix: Gracefully handle CVEs with bad configuration nodes missing CPE match expressions (#7125)
Signed-off-by: Chad Wilson <[email protected]>
1 parent 8e000dd commit 25606aa

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

core/src/main/java/org/owasp/dependencycheck/data/nvdcve/CveItemOperator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package org.owasp.dependencycheck.data.nvdcve;
1919

2020
import io.github.jeremylong.openvulnerability.client.nvd.Config;
21+
22+
import java.util.Objects;
2123
import java.util.stream.Collectors;
2224
import org.owasp.dependencycheck.data.nvd.ecosystem.Ecosystem;
2325

@@ -219,15 +221,15 @@ public boolean isRejected(String description) {
219221
boolean testCveCpeStartWithFilter(final DefCveItem cve) {
220222
if (cve.getCve().getConfigurations() != null) {
221223
//cycle through to see if this is a CPE we care about (use the CPE filters
222-
final boolean result = cve.getCve().getConfigurations().stream()
224+
return cve.getCve().getConfigurations().stream()
223225
.map(Config::getNodes)
224226
.flatMap(List::stream)
225-
.filter(node -> node != null)
227+
.filter(Objects::nonNull)
226228
.map(Node::getCpeMatch)
229+
.filter(Objects::nonNull)
227230
.flatMap(List::stream)
228231
.filter(cpe -> cpe != null && cpe.getCriteria() != null)
229232
.anyMatch(cpe -> cpe.getCriteria().startsWith(cpeStartsWithFilter));
230-
return result;
231233
}
232234
return false;
233235
}

core/src/test/java/org/owasp/dependencycheck/data/nvdcve/CveItemOperatorTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.ArrayList;
3434
import java.util.List;
3535
import org.junit.Test;
36+
3637
import static org.junit.Assert.*;
3738

3839
/**
@@ -89,4 +90,31 @@ public void testTestCveCpeStartWithFilter() {
8990

9091
}
9192

93+
@Test
94+
public void testTestCveCpeStartWithFilterForConfigurationWithoutCpeMatches() {
95+
ZonedDateTime published = ZonedDateTime.now();
96+
ZonedDateTime lastModified = ZonedDateTime.now();
97+
LocalDate cisaExploitAdd = null;
98+
LocalDate cisaActionDue = null;
99+
List<CveTag> cveTags = null;
100+
List<LangString> descriptions = null;
101+
List<Reference> references = null;
102+
Metrics metrics = null;
103+
List<Weakness> weaknesses = null;
104+
105+
Node noCpeMatches = new Node(Node.Operator.OR, null, null);
106+
Config c = new Config(Config.Operator.AND, null, List.of(noCpeMatches));
107+
List<VendorComment> vendorComments = null;
108+
CveItem cveItem = new CveItem("id", "sourceIdentifier", "vulnStatus", published, lastModified,
109+
"evaluatorComment", "evaluatorSolution", "evaluatorImpact", cisaExploitAdd, cisaActionDue,
110+
"cisaRequiredAction", "cisaVulnerabilityName", cveTags, descriptions, references, metrics,
111+
weaknesses, List.of(c), vendorComments);
112+
113+
DefCveItem cve = new DefCveItem(cveItem);
114+
CveItemOperator instance = new CveItemOperator("cpe:2.3:o:");
115+
boolean expResult = false;
116+
boolean result = instance.testCveCpeStartWithFilter(cve);
117+
assertEquals(expResult, result);
118+
}
119+
92120
}

0 commit comments

Comments
 (0)