Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion controllers/csaf_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func (controller *CSAFController) GetReportsByYearHTML(ctx shared.Context) error
// extract the requested year and build the revision history first
year := strings.TrimRight(ctx.Param("year"), "/")
allVulns, err := controller.dependencyVulnRepository.GetAllVulnsByAssetID(nil, asset.ID)

if err != nil {
return err
}
Expand All @@ -257,6 +256,12 @@ func (controller *CSAFController) GetReportsByYearHTML(ctx shared.Context) error
vulnsOfThatYear := utils.Filter(allVulns, func(vuln models.DependencyVuln) bool {
return len(vuln.Events) > 0 && vuln.Events[0].CreatedAt.Year() == yearNumber
})

// deduplicate Slice to avoid listing the same CVEs
vulnsOfThatYear = utils.DeduplicateSlice(vulnsOfThatYear, func(vuln models.DependencyVuln) string {
return vuln.CVEID
})

type pageData struct {
Year int
Filenames []string
Expand Down
4 changes: 4 additions & 0 deletions database/repositories/dependency_vuln_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func (repository *dependencyVulnRepository) GetByAssetVersionPaged(tx *gorm.DB,
packageNameQuery = packageNameQuery.Where(f.SQL(), f.Value())
}

if search != "" && len(search) > 2 {
packageNameQuery.Where("(\"CVE\".description ILIKE ? OR dependency_vulns.cve_id ILIKE ? OR component_purl ILIKE ?)", "%"+search+"%", "%"+search+"%", "%"+search+"%")
}

// apply sorting
if len(sort) > 0 {
for _, s := range sort {
Expand Down
15 changes: 15 additions & 0 deletions utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,18 @@ func GetDirFromPath(path string) string {
}
return path
}

// DeduplicateSlice deduplicates a slice in O(n) out of place.
func DeduplicateSlice[T any](slice []T, idFunc func(t T) string) []T {
deduplicatedSlice := make([]T, 0, len(slice))
seen := make(map[string]struct{}, len(slice))
for i := range slice {
id := idFunc(slice[i])
if _, ok := seen[id]; ok {
continue
}
seen[id] = struct{}{}
deduplicatedSlice = append(deduplicatedSlice, slice[i])
}
return deduplicatedSlice
}
Loading