From 4f8c803b88963533066dff19b9a3c32a556138ef Mon Sep 17 00:00:00 2001 From: Hubtrick-Git Date: Fri, 6 Feb 2026 20:10:25 +0100 Subject: [PATCH 1/3] deduplicate csaf entries and fix dependency search --- controllers/csaf_controller.go | 7 ++++++- database/repositories/dependency_vuln_repository.go | 4 ++++ utils/common.go | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/controllers/csaf_controller.go b/controllers/csaf_controller.go index 5b25c632..e0ecd38b 100644 --- a/controllers/csaf_controller.go +++ b/controllers/csaf_controller.go @@ -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 } @@ -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 diff --git a/database/repositories/dependency_vuln_repository.go b/database/repositories/dependency_vuln_repository.go index 295bcfac..f96b966f 100644 --- a/database/repositories/dependency_vuln_repository.go +++ b/database/repositories/dependency_vuln_repository.go @@ -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 { diff --git a/utils/common.go b/utils/common.go index 6ae9c30a..a2961965 100644 --- a/utils/common.go +++ b/utils/common.go @@ -158,3 +158,16 @@ func GetDirFromPath(path string) string { } return path } + +// deduplicates a slice in O(n) out of place +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) + } + return deduplicatedSlice +} From 87c301a4bd7405cc13b230d09e13ccd97161f228 Mon Sep 17 00:00:00 2001 From: Tim Bastin <38261809+timbastin@users.noreply.github.com> Date: Fri, 6 Feb 2026 20:22:31 +0100 Subject: [PATCH 2/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Tim Bastin <38261809+timbastin@users.noreply.github.com> --- utils/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/common.go b/utils/common.go index a2961965..1c7c3816 100644 --- a/utils/common.go +++ b/utils/common.go @@ -159,7 +159,7 @@ func GetDirFromPath(path string) string { return path } -// deduplicates a slice in O(n) out of place +// DeduplicateSlice deduplicates a slice in O(n) out of place. 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)) From 828e7d6694b5798068bc9376df4d983fbeb60c08 Mon Sep 17 00:00:00 2001 From: Tim Bastin <38261809+timbastin@users.noreply.github.com> Date: Fri, 6 Feb 2026 20:23:03 +0100 Subject: [PATCH 3/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Tim Bastin <38261809+timbastin@users.noreply.github.com> --- utils/common.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utils/common.go b/utils/common.go index 1c7c3816..92c3b254 100644 --- a/utils/common.go +++ b/utils/common.go @@ -161,13 +161,15 @@ func GetDirFromPath(path string) string { // DeduplicateSlice deduplicates a slice in O(n) out of place. 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)) + seen := make(map[string]struct{}, len(slice)) for i := range slice { - deduplicationMap[idFunc(slice[i])] = slice[i] - } - for _, t := range deduplicationMap { - deduplicatedSlice = append(deduplicatedSlice, t) + id := idFunc(slice[i]) + if _, ok := seen[id]; ok { + continue + } + seen[id] = struct{}{} + deduplicatedSlice = append(deduplicatedSlice, slice[i]) } return deduplicatedSlice }