Skip to content

Commit

Permalink
Fixing false negative vulnerabilities on macOS Homebrew python packag…
Browse files Browse the repository at this point in the history
…es. (#17709)

#17061

TODO: Need to also merge this fix into patch branch.

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
  • Loading branch information
getvictor authored Mar 19, 2024
1 parent 61544f4 commit 759003e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/17061-homebrew-python
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixing false negative vulnerabilities on macOS Homebrew python packages.
9 changes: 9 additions & 0 deletions server/vulnerabilities/nvd/cpe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,15 @@ func TestCPEFromSoftwareIntegration(t *testing.T) {
// DO NOT MATCH with Cisco Umbrella
cpe: "",
},
{
software: fleet.Software{
Name: "python@3.9",
Source: "homebrew_packages",
Version: "3.9.18_2",
Vendor: "",
},
cpe: `cpe:2.3:a:python:python:3.9.18_2:*:*:*:*:*:*:*`,
},
}

// NVD_TEST_CPEDB_PATH can be used to speed up development (sync cpe.sqlite only once).
Expand Down
7 changes: 7 additions & 0 deletions server/vulnerabilities/nvd/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ var langCodes = map[string]bool{
// - Removing any extra spaces
// - Lowercasing the name
// - Removing parts from the bundle identifier
// - Removing version contained in homebrew_packages name
func sanitizeSoftwareName(s *fleet.Software) string {
archs := regexp.MustCompile(` \(?x64\)?|\(?64-bit\)?|\(?64bit\)?|\(?amd64\)? `)
ver := regexp.MustCompile(` \.?\(?(\d+\.)?(\d+\.)?(\*|\d+)\)?\s?`)
gen := regexp.MustCompile(` \(\w+\)\s?`)
comments := regexp.MustCompile(` (-|:)\s?.+`)
versions := regexp.MustCompile(`@\d+($|(\.\d+($|\..+)))`) // @3 or @3.9 or @3.9.18 or @3.9.18_2

r := strings.ToLower(s.Name)
r = strings.TrimSuffix(r, ".app")
Expand Down Expand Up @@ -119,6 +121,11 @@ func sanitizeSoftwareName(s *fleet.Software) string {
r = strings.Replace(r, ")", " ", -1)
r = strings.Join(strings.Fields(r), " ")

// Remove @<version> from homebrew names
if s.Source == "homebrew_packages" {
r = versions.ReplaceAllString(r, "")
}

return r
}

Expand Down

0 comments on commit 759003e

Please sign in to comment.