-
-
Notifications
You must be signed in to change notification settings - Fork 779
Issue-6654 : Skip malformed PURLs instead of assigning to empty resolver #6679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sahibamittal
wants to merge
1
commit into
DependencyTrack:main
Choose a base branch
from
sahibamittal:issue-6654-skip-malformed-purl-resolution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+62
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simply skipping these would cause them to always remain eligible for resolution because no result is persisted for them.
The previous behavior assigned the "empty" resolver, which then later trivially persists empty results:
dependency-track/apiserver/src/main/java/org/dependencytrack/pkgmetadata/ResolvePackageMetadataActivity.java
Lines 97 to 108 in 13d5b2d
This prevents the next
FetchPackageMetadataResolutionCandidatesResiteration from discovering entries with invalid PURLs again.By skipping this mechanism,
ResolvePackageMetadataWorkflowwould effectively loop forever and never terminate. It basically breaks the exit condition, i.e. this query returning no results:dependency-track/apiserver/src/main/java/org/dependencytrack/pkgmetadata/FetchPackageMetadataResolutionCandidatesActivity.java
Lines 118 to 130 in 13d5b2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing the same malformed PURL being logged on every resolution cycle with the current implementation. So the empty resolver path is not actually preventing it from being rediscovered. Same malformed PURL should not be processed again after the first successful workflow execution.
I'll check whether the empty result is being persisted and why
FetchPackageMetadataResolutionCandidatesResis still selecting it.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay found it, I noticed that for the malformed PURL,
ResultBuffer.addEmptyResult()returns immediately without persisting empty results becausePurlUtil.silentPurl(purlStr)returns null:As a result, no
PackageMetadataorPackageArtifactMetadatarecords are written, and the same component is selected again byFetchPackageMetadataResolutionCandidatesActivityon every cycle. This needs to be fixed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The model currently requires a valid PURL since the identifiers are
PackageURLobjects. We'd need a way to pass empty results for broken PURLs, ideally without loosening the types (i.e. changing fromPackageURLtoString) too much.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OR instead of persisting malformed PURLs (empty results), should it not just reject or sanitize them during BOM ingestion so they never reach the metadata resolver?
Also, currently we decide resolution state based on metadata tables if data exists. How about persisting the outcome of metadata resolution separately from the metadata itself. Say,
PACKAGE_METADATA_RESOLUTIONto record resolution state (e.g. SUCCESS, EMPTY, INVALID_PURL etc) keyed by the raw PURL. This way metadata becomes just the payload.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm that is already happening:
dependency-track/apiserver/src/main/java/org/dependencytrack/parser/cyclonedx/util/ModelConverter.java
Lines 224 to 232 in f7e5611
Which begs the question how you could still see invalid PURLs reaching the metadata resolver. I wonder if it's related to an encoding bug in the
packageurl-javalibrary (see #6383 where it came up recently). Does that error pattern match what you're observing in your instance?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked none of repository records have authenticationRequired set to null. Error is due to malformed escape pair in invalid PURL during metadata resolution:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, no I meant the PURL encoding issue that's also mentioned there.
pkg:nuget/serilog.sinks.file%A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%205.0.0@5.0.0is likely not how the PURL looked when it entered the system, thepackageurl-javalib may have borked it when converting it fromPackageURLtoString. That would explain why it survived the import:new PackageURL(cdxComponent.getPurl())works finePackageURL.canonicalize(), which borks the encodingnew PackageURL(<value-from-db>)now fails