Skip to content

Modern Docker Management, Designed for Everyone

fix: exclude ignored vulnerabilities from dashboard action items count (#2197)

Giulio Savini340e598881fb
diff --git a/backend/internal/services/dashboard_service.go b/backend/internal/services/dashboard_service.go
index 3a3c49070..bbc60a6a6 100644
--- a/backend/internal/services/dashboard_service.go
+++ b/backend/internal/services/dashboard_service.go
@@ -416,16 +416,7 @@ func (s *DashboardService) getActionableVulnerabilitiesCountInternal(ctx context
return 0, nil
}
- summary, err := s.vulnerabilityService.GetEnvironmentSummary(ctx)
- if err != nil {
- return 0, fmt.Errorf("failed to load vulnerability summary: %w", err)
- }
-
- if summary == nil || summary.Summary == nil {
- return 0, nil
- }
-
- return summary.Summary.Critical + summary.Summary.High, nil
+ return s.vulnerabilityService.getActionableCountExcludingIgnoredInternal(ctx)
}
func (s *DashboardService) getExpiringAPIKeysCountInternal(ctx context.Context) (int, error) {
diff --git a/backend/internal/services/vulnerability_service.go b/backend/internal/services/vulnerability_service.go
index b60cd1a21..641351a3d 100644
--- a/backend/internal/services/vulnerability_service.go
+++ b/backend/internal/services/vulnerability_service.go
@@ -616,6 +616,70 @@ func (s *VulnerabilityService) GetEnvironmentSummary(ctx context.Context) (*vuln
return summary, nil
}
+// getActionableCountExcludingIgnoredInternal counts critical and high severity vulnerabilities
+// across all completed scans, excluding any that have been ignored. This is used by the dashboard
+// to show an accurate action item count that reflects ignore decisions.
+func (s *VulnerabilityService) getActionableCountExcludingIgnoredInternal(ctx context.Context) (int, error) {
+ if s.db == nil {
+ return 0, nil
+ }
+
+ var records []models.VulnerabilityScanRecord
+ err := s.db.WithContext(ctx).
+ Select("id", "vulnerabilities").
+ Where("status = ?", models.ScanStatusCompleted).
+ Where("critical_count + high_count > 0").
+ Find(&records).Error
+ if err != nil {
+ return 0, fmt.Errorf("failed to list vulnerability scans: %w", err)
+ }
+
+ if len(records) == 0 {
+ return 0, nil
+ }
+
+ // Load all ignore records (not scoped to a single environment, since an
+ // Arcane instance serves one environment and the dashboard does not carry
+ // an environment ID through the service layer today).
+ var ignores []models.VulnerabilityIgnore
+ if err := s.db.WithContext(ctx).Find(&ignores).Error; err != nil {
+ return 0, fmt.Errorf("failed to get ignore records: %w", err)
+ }
+
+ ignoredKeys := make(map[string]struct{}, len(ignores))
+ for _, ig := range ignores {
+ ignoredKeys[vulnerabilityIgnoreKeyInternal(ig.ImageID, ig.VulnerabilityID, ig.PkgName, ig.InstalledVersion)] = struct{}{}
+ }
+
+ count := 0
+ for _, record := range records {
+ if len(record.Vulnerabilities) == 0 || record.Vulnerabilities[0] == "" {
+ continue
+ }
+
+ var vulns []vulnerability.Vulnerability
+ if err := json.Unmarshal([]byte(record.Vulnerabilities[0]), &vulns); err != nil {
+ slog.WarnContext(ctx, "failed to unmarshal vulnerabilities", "error", err, "image_id", record.ID)
+ continue
+ }
+
+ for _, vuln := range vulns {
+ if vuln.Severity != vulnerability.SeverityCritical && vuln.Severity != vulnerability.SeverityHigh {
+ continue
+ }
+ if len(ignoredKeys) > 0 {
+ key := vulnerabilityIgnoreKeyInternal(record.ID, vuln.VulnerabilityID, vuln.PkgName, vuln.InstalledVersion)
+ if _, isIgnored := ignoredKeys[key]; isIgnored {
+ continue
+ }
+ }
+ count++
+ }
+ }
+
+ return count, nil
+}
+
// ListAllVulnerabilities returns a paginated list of vulnerabilities across all scanned images.
func (s *VulnerabilityService) ListAllVulnerabilities(ctx context.Context, envID string, params pagination.QueryParams) ([]vulnerability.VulnerabilityWithImage, pagination.Response, error) {
if params.Limit == 0 {