Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing slog.Error for KEV validations #69

Merged
merged 3 commits into from
Jun 5, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [UNRELEASED]

### Fixed

- Missing `slog.Error` for KEV validations

## [0.7.0] - 2024-05-17

### Changed
Expand Down
24 changes: 14 additions & 10 deletions pkg/gatecheck/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,21 @@ func ruleGrypeKEVLimit(config *Config, report *artifacts.GrypeReportMin, catalog
slog.Error("kev limit enabled but no catalog data exists")
return false
}
foundKevMatch := false
badCVEs := make([]string, 0)
// Check if vulnerability is in the KEV Catalog
for _, vulnerability := range report.Matches {
inKEVCatalog := slices.ContainsFunc(catalog.Vulnerabilities, func(kevVul kev.Vulnerability) bool {
return kevVul.CveID == vulnerability.Vulnerability.ID
})
if inKEVCatalog {
slog.Warn("Matched to KEV Catalog",
"vulnerability", vulnerability.Vulnerability.ID)
foundKevMatch = true
badCVEs = append(badCVEs, vulnerability.Vulnerability.ID)
slog.Warn("cve found in kev catalog",
"cve_id", vulnerability.Vulnerability.ID)
}
}
if foundKevMatch {
if len(badCVEs) > 0 {
slog.Error("cve(s) found in kev catalog",
"vulnerabilities", len(badCVEs), "kev_catalog_count", len(catalog.Vulnerabilities))
return false
}
slog.Info("kev limit validated, no cves in catalog",
Expand All @@ -242,20 +244,22 @@ func ruleCyclonedxKEVLimit(config *Config, report *artifacts.CyclonedxReportMin,
slog.Error("kev limit enabled but no catalog data exists", "artifact", "cyclonedx")
return false
}
foundKevMatch := false
badCVEs := make([]string, 0)
// Check if vulnerability is in the KEV Catalog
for _, vulnerability := range report.Vulnerabilities {
inKEVCatalog := slices.ContainsFunc(catalog.Vulnerabilities, func(kevVul kev.Vulnerability) bool {
return strings.EqualFold(kevVul.CveID, vulnerability.ID)
})

if inKEVCatalog {
slog.Warn("Matched to KEV Catalog",
"vulnerability", vulnerability.ID)
foundKevMatch = true
badCVEs = append(badCVEs, vulnerability.ID)
slog.Warn("cve found in kev catalog",
"cve_id", vulnerability.ID)
}
}
if foundKevMatch {
if len(badCVEs) > 0 {
slog.Error("cve(s) found in kev catalog",
"vulnerabilities", len(badCVEs), "kev_catalog_count", len(catalog.Vulnerabilities))
return false
}
slog.Info("kev limit validated, no cves in catalog",
Expand Down
Loading