Skip to content

Commit

Permalink
CVE report should include changed requirements.
Browse files Browse the repository at this point in the history
Previously it would only show for added requirements. If a requirement changes versions, we should include it in the CVE report.
  • Loading branch information
mitchell-as committed Nov 7, 2024
1 parent 0100fab commit 110c0db
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions internal/runbits/cves/cves.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *CveReport) Report(newBuildPlan *buildplan.BuildPlan, oldBuildPlan *buil
}
}

names := addedRequirements(oldBuildPlan, newBuildPlan)
names := changedRequirements(oldBuildPlan, newBuildPlan)
pg := output.StartSpinner(c.prime.Output(), locale.Tr("progress_cve_search", strings.Join(names, ", ")), constants.TerminalAnimationInterval)

ingredientVulnerabilities, err := model.FetchVulnerabilitiesForIngredients(c.prime.Auth(), ingredients)
Expand Down Expand Up @@ -235,21 +235,24 @@ func (c *CveReport) promptForSecurity() (bool, error) {
return confirm, nil
}

func addedRequirements(oldBuildPlan *buildplan.BuildPlan, newBuildPlan *buildplan.BuildPlan) []string {
func changedRequirements(oldBuildPlan *buildplan.BuildPlan, newBuildPlan *buildplan.BuildPlan) []string {
var names []string
var oldRequirements buildplan.Requirements
if oldBuildPlan != nil {
oldRequirements = oldBuildPlan.Requirements()
}
newRequirements := newBuildPlan.Requirements()

oldReqs := make(map[string]bool)
oldReqs := make(map[string]string)
for _, req := range oldRequirements {
oldReqs[qualifiedName(req)] = true
oldReqs[qualifiedName(req)] = req.Ingredient.Version
}

for _, req := range newRequirements {
if oldReqs[qualifiedName(req)] || req.Namespace == buildplan.NamespaceInternal {
if req.Namespace == buildplan.NamespaceInternal {
continue
}
if version, exists := oldReqs[qualifiedName(req)]; exists && version == req.Ingredient.Version {
continue
}
names = append(names, req.Name)
Expand Down

0 comments on commit 110c0db

Please sign in to comment.