-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix(cyclonedx): fix work when there are same pkgs from different dirs #5798
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -144,12 +144,20 @@ func (e *Marshaler) marshalPackages(metadata types.Metadata, result types.Result | |||||
|
||||||
// Group vulnerabilities by package ID | ||||||
vulns := lo.GroupBy(result.Vulnerabilities, func(v types.DetectedVulnerability) string { | ||||||
return lo.Ternary(v.PkgID == "", fmt.Sprintf("%s@%s", v.PkgName, v.InstalledVersion), v.PkgID) | ||||||
pkgID := lo.Ternary(v.PkgID == "", fmt.Sprintf("%s@%s", v.PkgName, v.InstalledVersion), v.PkgID) | ||||||
if v.PkgPath != "" { | ||||||
pkgID = fmt.Sprintf("%s@%s", pkgID, v.PkgPath) | ||||||
} | ||||||
return pkgID | ||||||
}) | ||||||
|
||||||
// Create package map | ||||||
pkgs := lo.SliceToMap(result.Packages, func(pkg ftypes.Package) (string, Package) { | ||||||
pkgID := lo.Ternary(pkg.ID == "", fmt.Sprintf("%s@%s", pkg.Name, utils.FormatVersion(pkg)), pkg.ID) | ||||||
// To avoid skip same packages with different paths | ||||||
if pkg.FilePath != "" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only applies to trivy/pkg/fanal/types/artifact.go Lines 91 to 92 in abf227e
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So it doesn't break logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about saving slice of Looks like this update is enough for now. If we will add |
||||||
pkgID = fmt.Sprintf("%s@%s", pkgID, pkg.FilePath) | ||||||
} | ||||||
return pkgID, Package{ | ||||||
Type: result.Type, | ||||||
Metadata: metadata, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1190,7 +1190,7 @@ func TestMarshaler_Marshal(t *testing.T) { | |
}, | ||
}, | ||
{ | ||
name: "happy path. 2 packages for 1 CVE", | ||
name: "happy path. Multiple packages for 1 CVE (2 same packages from different dirs and 1 package with a different name)", | ||
inputReport: types.Report{ | ||
SchemaVersion: report.SchemaVersion, | ||
ArtifactName: "CVE-2023-34468", | ||
|
@@ -1211,6 +1211,11 @@ func TestMarshaler_Marshal(t *testing.T) { | |
Version: "1.20.0", | ||
FilePath: "nifi-hikari-dbcp-service-1.20.0.jar", | ||
}, | ||
{ | ||
Name: "org.apache.nifi:nifi-hikari-dbcp-service", | ||
Version: "1.20.0", | ||
FilePath: "dir/nifi-hikari-dbcp-service-1.20.0.jar", | ||
}, | ||
}, | ||
Vulnerabilities: []types.DetectedVulnerability{ | ||
{ | ||
|
@@ -1255,6 +1260,48 @@ func TestMarshaler_Marshal(t *testing.T) { | |
LastModifiedDate: lo.ToPtr(time.Date(2023, 6, 21, 02, 20, 0, 0, time.UTC)), | ||
}, | ||
}, | ||
{ | ||
VulnerabilityID: "CVE-2023-34468", | ||
PkgName: "org.apache.nifi:nifi-hikari-dbcp-service", | ||
PkgPath: "dir/nifi-hikari-dbcp-service-1.20.0.jar", | ||
InstalledVersion: "1.20.0", | ||
FixedVersion: "1.22.0", | ||
SeveritySource: vulnerability.GHSA, | ||
PrimaryURL: "https://avd.aquasec.com/nvd/cve-2023-34468", | ||
DataSource: &dtypes.DataSource{ | ||
ID: vulnerability.GHSA, | ||
Name: "GitHub Security Advisory Maven", | ||
URL: "https://github.com/advisories?query=type%3Areviewed+ecosystem%3Amaven", | ||
}, | ||
Vulnerability: dtypes.Vulnerability{ | ||
Title: "Apache NiFi vulnerable to Code Injection", | ||
Description: "The DBCPConnectionPool and HikariCPConnectionPool Controller Services in Apache NiFi 0.0.2 through 1.21.0...", | ||
Severity: dtypes.SeverityHigh.String(), | ||
CweIDs: []string{ | ||
"CWE-94", | ||
}, | ||
VendorSeverity: dtypes.VendorSeverity{ | ||
vulnerability.GHSA: dtypes.SeverityHigh, | ||
vulnerability.NVD: dtypes.SeverityHigh, | ||
}, | ||
CVSS: dtypes.VendorCVSS{ | ||
vulnerability.GHSA: dtypes.CVSS{ | ||
V3Vector: "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H", | ||
V3Score: 8.8, | ||
}, | ||
vulnerability.NVD: dtypes.CVSS{ | ||
V3Vector: "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H", | ||
V3Score: 8.8, | ||
}, | ||
}, | ||
References: []string{ | ||
"http://www.openwall.com/lists/oss-security/2023/06/12/3", | ||
"https://github.com/advisories/GHSA-xm2m-2q6h-22jw", | ||
}, | ||
PublishedDate: lo.ToPtr(time.Date(2023, 6, 12, 16, 15, 0, 0, time.UTC)), | ||
LastModifiedDate: lo.ToPtr(time.Date(2023, 6, 21, 02, 20, 0, 0, time.UTC)), | ||
}, | ||
}, | ||
{ | ||
VulnerabilityID: "CVE-2023-34468", | ||
PkgName: "org.apache.nifi:nifi-hikari-dbcp-service", | ||
|
@@ -1348,6 +1395,24 @@ func TestMarshaler_Marshal(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
BOMRef: "pkg:maven/org.apache.nifi/[email protected]?file_path=dir%2Fnifi-hikari-dbcp-service-1.20.0.jar", | ||
Type: "library", | ||
Name: "nifi-hikari-dbcp-service", | ||
Group: "org.apache.nifi", | ||
Version: "1.20.0", | ||
PackageURL: "pkg:maven/org.apache.nifi/[email protected]", | ||
Properties: &[]cdx.Property{ | ||
{ | ||
Name: "aquasecurity:trivy:FilePath", | ||
Value: "dir/nifi-hikari-dbcp-service-1.20.0.jar", | ||
}, | ||
{ | ||
Name: "aquasecurity:trivy:PkgType", | ||
Value: "jar", | ||
}, | ||
}, | ||
}, | ||
{ | ||
BOMRef: "pkg:maven/org.apache.nifi/[email protected]?file_path=nifi-hikari-dbcp-service-1.20.0.jar", | ||
Type: "library", | ||
|
@@ -1372,13 +1437,18 @@ func TestMarshaler_Marshal(t *testing.T) { | |
Ref: "3ff14136-e09f-4df9-80ea-000000000002", | ||
Dependencies: &[]string{ | ||
"pkg:maven/org.apache.nifi/[email protected]?file_path=nifi-dbcp-base-1.20.0.jar", | ||
"pkg:maven/org.apache.nifi/[email protected]?file_path=dir%2Fnifi-hikari-dbcp-service-1.20.0.jar", | ||
"pkg:maven/org.apache.nifi/[email protected]?file_path=nifi-hikari-dbcp-service-1.20.0.jar", | ||
}, | ||
}, | ||
{ | ||
Ref: "pkg:maven/org.apache.nifi/[email protected]?file_path=nifi-dbcp-base-1.20.0.jar", | ||
Dependencies: lo.ToPtr([]string{}), | ||
}, | ||
{ | ||
Ref: "pkg:maven/org.apache.nifi/[email protected]?file_path=dir%2Fnifi-hikari-dbcp-service-1.20.0.jar", | ||
Dependencies: lo.ToPtr([]string{}), | ||
}, | ||
{ | ||
Ref: "pkg:maven/org.apache.nifi/[email protected]?file_path=nifi-hikari-dbcp-service-1.20.0.jar", | ||
Dependencies: lo.ToPtr([]string{}), | ||
|
@@ -1437,6 +1507,15 @@ func TestMarshaler_Marshal(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
Ref: "pkg:maven/org.apache.nifi/[email protected]?file_path=dir%2Fnifi-hikari-dbcp-service-1.20.0.jar", | ||
Range: &[]cdx.AffectedVersions{ | ||
{ | ||
Version: "1.20.0", | ||
Status: cdx.VulnerabilityStatusAffected, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Ref: "pkg:maven/org.apache.nifi/[email protected]?file_path=nifi-hikari-dbcp-service-1.20.0.jar", | ||
Range: &[]cdx.AffectedVersions{ | ||
|
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.
same:
trivy/pkg/detector/library/detect.go
Line 35 in abf227e