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: improve sanitation of python version strings to match CPEs #26538

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions changes/25991-pre-python
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixed an issue with Fleet's processing of Python versions to ensure that the correct CPEs are
checked for vulnerabilities.
6 changes: 3 additions & 3 deletions server/service/osquery_utils/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1784,11 +1784,11 @@ var (
candidateSuffix := ""
switch releaseLevel { // see https://github.com/python/cpython/issues/100829#issuecomment-1374656643
case "10":
candidateSuffix = "-alpha" + releaseSerial
candidateSuffix = "a" + releaseSerial
case "11":
candidateSuffix = "-beta" + releaseSerial
candidateSuffix = "b" + releaseSerial
case "12":
candidateSuffix = "-rc" + releaseSerial
candidateSuffix = "rc" + releaseSerial
} // default

if patchVersion == "" { // dot-zero patch releases have a 3-digit patch + build number
Expand Down
9 changes: 5 additions & 4 deletions server/service/osquery_utils/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,8 @@ func TestDirectIngestDiskEncryptionKeyDarwin(t *testing.T) {
}

ds.SetOrUpdateHostDiskEncryptionKeyFunc = func(ctx context.Context, incomingHost *fleet.Host, encryptedBase64Key, clientError string,
decryptable *bool) error {
decryptable *bool,
) error {
if base64.StdEncoding.EncodeToString([]byte(wantKey)) != encryptedBase64Key {
return errors.New("key mismatch")
}
Expand Down Expand Up @@ -2013,7 +2014,7 @@ func TestSanitizeSoftware(t *testing.T) {
},
sanitized: &fleet.Software{
Name: "Python 3.14.0a4 (64-bit)",
Version: "3.14.0-alpha4",
Version: "3.14.0a4",
Source: "programs",
},
},
Expand All @@ -2027,7 +2028,7 @@ func TestSanitizeSoftware(t *testing.T) {
},
sanitized: &fleet.Software{
Name: "Python 3.14.0b3 (64-bit)",
Version: "3.14.0-beta3",
Version: "3.14.0b3",
Source: "programs",
},
},
Expand All @@ -2041,7 +2042,7 @@ func TestSanitizeSoftware(t *testing.T) {
},
sanitized: &fleet.Software{
Name: "Python 3.14.0rc2 (64-bit)",
Version: "3.14.0-rc2",
Version: "3.14.0rc2",
Source: "programs",
},
},
Expand Down
8 changes: 8 additions & 0 deletions server/vulnerabilities/nvd/cve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ func TestTranslateCPEToCVE(t *testing.T) {
"cpe:2.3:a:simple_password_store_project:simple_password_store:1.7.0:*:*:*:*:macos:*:*": {
includedCVEs: []cve{{ID: "CVE-2018-12356", resolvedInVersion: "1.7.2"}},
},
"cpe:2.3:a:python:python:3.14.0a2:*:*:*:*:windows:*:*": {
includedCVEs: []cve{
{
ID: "CVE-2024-12254",
resolvedInVersion: "3.12.9",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it should be 3.14.0a3, per https://www.cve.org/CVERecord?id=CVE-2024-12254

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iansltx could this be an issue with the semver changes we made recently?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. Would probably require digging into the vuln feed to see the information that's there. As mentioned in chat, I think that the CPE wouldn't even generate without the recent fix in place, but maybe we're matching the wrong CPE?

},
},
},
}

cveOSTests := []struct {
Expand Down
Loading