Skip to content

Add whitespace sanitization in fuzzySearch CPE to fix CPE validation errors#5061

Merged
nscuro merged 1 commit intoDependencyTrack:masterfrom
jonbally:master
Jun 18, 2025
Merged

Add whitespace sanitization in fuzzySearch CPE to fix CPE validation errors#5061
nscuro merged 1 commit intoDependencyTrack:masterfrom
jonbally:master

Conversation

@jonbally
Copy link
Copy Markdown
Contributor

Description

The vendor and product String parameters passed to fuzzySearch() might contain spaces, as the frontend does not prevent inputting strings containing spaces 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 (unless they are sanitized when importing).

As fuzzySearch() creates a new CPE object which validates the attributes inside the constructor, this will cause exceptions to be logged for all components that contain spaces in name and/or vendor.

I have added a simple replace before passing these strings to the CPE constructor to prevent the exceptions from being thrown.
I have also renamed the private method escape() to escapeLuceneQuery() to be more descriptive, as it calls the Lucene QueryParser.escape() method.

Addressed Issue

Fixes #4920

Additional Details

I wanted to add a test for the fix, but the only testable difference is that the exceptions no longer appear in the logs. I tried to find ways to elegantly test this, but could only find solutions which would require adding dependencies to catch the log entries from the tests and asserting that no log entry appears for components with spaces in name or vendor.
If there is a better way to test such cases please let me know.
I ran all tests related to the FuzzyVulnerableSoftwareSearchManager and they passed.

Checklist

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]>
@owasp-dt-bot
Copy link
Copy Markdown

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

@codacy-production
Copy link
Copy Markdown

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) 100.00% (target: 70.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (0b9c45f) 24015 19404 80.80%
Head commit (863b820) 24017 (+2) 19406 (+2) 80.80% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#5061) 5 5 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Copy link
Copy Markdown
Member

@nscuro nscuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@nscuro nscuro added this to the 4.14.0 milestone Jun 18, 2025
@nscuro nscuro added defect Something isn't working backport/4.13.3 PRs to be backported to v4.13.3 labels Jun 18, 2025
@nscuro nscuro merged commit 0767072 into DependencyTrack:master Jun 18, 2025
11 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backport/4.13.3 PRs to be backported to v4.13.3 defect Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERROR Failed to validate fuzz search CPE due to whitespace in cpe string

3 participants