Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
})
Comment thread
timbastin marked this conversation as resolved.

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+"%")
}
Comment thread
timbastin marked this conversation as resolved.

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

// deduplicates a slice in O(n) out of place
Comment thread
timbastin marked this conversation as resolved.
Outdated
func DeduplicateSlice[T any](slice []T, idFunc func(t T) string) []T {
deduplicationMap := make(map[string]T, len(slice))
deduplicatedSlice := make([]T, 0, len(slice))
for i := range slice {
deduplicationMap[idFunc(slice[i])] = slice[i]
}
for _, t := range deduplicationMap {
deduplicatedSlice = append(deduplicatedSlice, t)
}
Comment thread
timbastin marked this conversation as resolved.
Outdated
return deduplicatedSlice
}
Loading