Fixed bug when using without_vulnerability_details and vulnerability filters (#24769)

https://github.com/fleetdm/fleet/issues/24765

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [x] Added/updated tests
This commit is contained in:
Konstantin Sykulev
2024-12-13 16:39:21 -06:00
committed by GitHub
parent 7d7fc7b249
commit 4503b2f334
4 changed files with 26 additions and 3 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ func (svc *Service) ListSoftware(ctx context.Context, opts fleet.SoftwareListOpt
// reuse ListSoftware, but include cve scores in premium version
// unless without_vulnerability_details is set to true
// including these details causes a lot of memory bloat
if !opts.WithoutVulnerabilityDetails {
if (opts.MaximumCVSS > 0 || opts.MinimumCVSS > 0 || opts.KnownExploit) || !opts.WithoutVulnerabilityDetails {
opts.IncludeCVEScores = true
}
return svc.Service.ListSoftware(ctx, opts)
+1 -1
View File
@@ -917,7 +917,7 @@ func listSoftwareDB(
DetailsLink: fmt.Sprintf("https://nvd.nist.gov/vuln/detail/%s", cveID),
CreatedAt: *result.CreatedAt,
}
if opts.IncludeCVEScores {
if opts.IncludeCVEScores && !opts.WithoutVulnerabilityDetails {
cve.CVSSScore = &result.CVSSScore
cve.EPSSProbability = &result.EPSSProbability
cve.CISAKnownExploit = &result.CISAKnownExploit
@@ -5223,6 +5223,25 @@ func (s *integrationEnterpriseTestSuite) TestListSoftware() {
require.Nil(t, cve.ResolvedInVersion)
}
}
// without_vulnerability_details with vulnerability filter
s.DoJSON(
"GET", "/api/latest/fleet/software/versions",
listSoftwareRequest{},
http.StatusOK, &respVersions,
"exploit", "true",
"vulnerable", "true",
"without_vulnerability_details", "true",
)
for _, s := range respVersions.Software {
for _, cve := range s.Vulnerabilities {
require.Nil(t, cve.CVSSScore)
require.Nil(t, cve.EPSSProbability)
require.Nil(t, cve.CISAKnownExploit)
require.Nil(t, cve.CVEPublished)
require.Nil(t, cve.Description)
require.Nil(t, cve.ResolvedInVersion)
}
}
s.DoJSON(
"GET", "/api/latest/fleet/software/versions",
listSoftwareRequest{},
+5 -1
View File
@@ -106,7 +106,11 @@ func (svc *Service) ListSoftware(ctx context.Context, opt fleet.SoftwareListOpti
}
// Vulnerability filters are only available in premium (opt.IncludeCVEScores is only true in premium)
if !opt.IncludeCVEScores && (opt.MaximumCVSS > 0 || opt.MinimumCVSS > 0 || opt.KnownExploit) {
lic, err := svc.License(ctx)
if err != nil {
return nil, nil, err
}
if !lic.IsPremium() && (opt.MaximumCVSS > 0 || opt.MinimumCVSS > 0 || opt.KnownExploit) {
return nil, nil, fleet.ErrMissingLicense
}