Skip to content

Commit

Permalink
Fixed bug when using without_vulnerability_details and vulnerabilit…
Browse files Browse the repository at this point in the history
…y filters
  • Loading branch information
ksykulev committed Dec 13, 2024
1 parent fb118b6 commit 3e75532
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions changes/24765-software-versions-bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Fixed bug when using the `without_vulnerability_details` param along with vulnerability filters in fleet premium.
6 changes: 1 addition & 5 deletions ee/server/service/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import (

func (svc *Service) ListSoftware(ctx context.Context, opts fleet.SoftwareListOptions) ([]fleet.Software, *fleet.PaginationMetadata, error) {
// 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 {
opts.IncludeCVEScores = true
}
opts.IncludeCVEScores = true
return svc.Service.ListSoftware(ctx, opts)
}

Expand Down
2 changes: 1 addition & 1 deletion server/datastore/mysql/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions server/service/integration_enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
6 changes: 5 additions & 1 deletion server/service/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 3e75532

Please sign in to comment.