Skip to content
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

trivy:bugfix - adding func to avoid hash changes in trivy formatter #929

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion internal/services/formatters/generic/trivy/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,24 @@ func (f *Formatter) addVulnerabilitiesOutput(vulnerabilities []*trivyVulnerabili
addVuln.File = target
addVuln.Details = vuln.getDetails()
addVuln.Severity = severities.GetSeverityByString(vuln.Severity)
addVuln = vulnhash.Bind(addVuln)
addVuln.VulnHash = f.getOldHash(vuln.PkgName, *addVuln)
f.AddNewVulnerabilityIntoAnalysis(addVuln)
}
}

// getOldHash func necessary to avoid a breaking change in the trivy hash generation. Since the pull request
// https://github.com/ZupIT/horusec/pull/882 some changes were made in the line and code, and this data influences
// directly the hash generation. This func will avoid this hash change by using the same data as before, but for the
// users the data will be showed with the fixes made in the pull request 882, leading to no braking changes and keeping
// the fixes.
// nolint:gocritic // it has to be without pointer
func (f *Formatter) getOldHash(pkgName string, vuln vulnerability.Vulnerability) string {
vuln.Line = "0"
vuln.Code = pkgName

return vulnhash.Bind(&vuln).VulnHash
}

func (f *Formatter) addMisconfigurationOutput(result []*trivyMisconfiguration, target string) {
for _, vuln := range result {
addVuln := f.getVulnBase()
Expand Down