Skip to content

Commit 863b820

Browse files
committed
Added whitespace sanitization in fuzzySearch CPE
The vendor and product String parameters passed to fuzzySearch() might contain spaces, as the frontend does not prevent inputting these when manually creating a component. As far as I know CycloneDX and SPDX also do not restrict this, so imported components could also contain spaces in their name and vendor properties. As fuzzySearch() creates a new CPE object which is validated inside the constructor, this will cause exceptions to be logged for all components that contain spaces. I have added a simple replace before passing these strings to the CPE constructor to prevent the exceptions from being thrown. Signed-off-by: jonbally <[email protected]>
1 parent 0b9c45f commit 863b820

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/main/java/org/dependencytrack/search/FuzzyVulnerableSoftwareSearchManager.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ public List<VulnerableSoftware> fuzzyAnalysis(QueryManager qm, final Component c
150150
}
151151
private List<VulnerableSoftware> fuzzySearch(QueryManager qm, Part part, String vendor, String product) {
152152
try {
153-
us.springett.parsers.cpe.Cpe cpe = new us.springett.parsers.cpe.Cpe(part, escape(vendor), escape(product), "*", "*", "*", "*", "*", "*", "*", "*");
153+
String sanitizedVendor = vendor.replace(" ", "_");
154+
String sanitizedProduct = product.replace(" ", "_");
155+
us.springett.parsers.cpe.Cpe cpe = new us.springett.parsers.cpe.Cpe(part, escapeLuceneQuery(sanitizedVendor), escapeLuceneQuery(sanitizedProduct), "*", "*", "*", "*", "*", "*", "*", "*");
154156
String cpeSearch = getLuceneCpeRegexp(cpe.toCpe23FS());
155157
return fuzzySearch(qm, cpeSearch);
156158
} catch (CpeValidationException cpeValidationException) {
@@ -239,8 +241,8 @@ public static String getLuceneCpeRegexp(String cpeString) {
239241
exp.insert(0, "cpe22:/");
240242
exp.append("\\/").append(cpe.getPart().getAbbreviation());
241243
}
242-
exp.append("\\:").append(escape(getComponentRegex(cpe.getVendor())));
243-
exp.append("\\:").append(escape(getComponentRegex(cpe.getProduct())));
244+
exp.append("\\:").append(escapeLuceneQuery(getComponentRegex(cpe.getVendor())));
245+
exp.append("\\:").append(escapeLuceneQuery(getComponentRegex(cpe.getProduct())));
244246
exp.append("\\:").append(getComponentRegex(cpe.getVersion()));
245247
exp.append("\\:").append(getComponentRegex(cpe.getUpdate()));
246248
exp.append("\\:").append(getComponentRegex(cpe.getEdition()));
@@ -266,7 +268,7 @@ private static String getComponentRegex(String component) {
266268
}
267269
}
268270

269-
private static String escape(final String input) {
271+
private static String escapeLuceneQuery(final String input) {
270272
if(input == null) {
271273
return null;
272274
} else if (input.equals(".*")) {

0 commit comments

Comments
 (0)