Skip to content

Commit

Permalink
Cherry-Pick: Fixed bug when using without_vulnerability_details and…
Browse files Browse the repository at this point in the history
… vulnerability filters (#24774)

issue #24765
original pr #24769
  • Loading branch information
ksykulev authored Dec 13, 2024
1 parent 653fc8a commit d4b91e3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ee/server/service/software.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 d4b91e3

Please sign in to comment.