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

Added util func around semver to allow for custom preprocessing. Upgraded semver lib #25437

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

ksykulev
Copy link
Contributor

@ksykulev ksykulev commented Jan 14, 2025

For #22919

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Added/updated automated tests
  • A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it)
  • Manual QA for all new/changed functionality

@ksykulev ksykulev requested a review from a team as a code owner January 14, 2025 22:04
@@ -632,7 +632,7 @@ func getMatchingVersionEndExcluding(ctx context.Context, cve string, hostSoftwar

// convert the host software version to semver for later comparison
formattedVersion := preprocessVersion(wfn.StripSlashes(hostSoftwareMeta.Version))
softwareVersion, err := semver.NewVersion(formattedVersion)
softwareVersion, err := fleet.VersionToSemverVersion(formattedVersion)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is failing because semver v3 considers6.72.10-06 an invalid prerelease value.

V1 seems to be ok parsing it.

major: 6
minor: 72
patch: 10
pre: "06"
metadata: ""
original: "6.72.10-06"

Looking at the regex https://regex101.com/r/Ly7O1x/3/ this is indeed technically "not valid"

Copy link
Contributor Author

@ksykulev ksykulev Jan 14, 2025

Choose a reason for hiding this comment

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

https://github.com/fleetdm/fleet/blob/main/server/vulnerabilities/nvd/cve_test.go#L710-L719

{
			name: "Can compare 4th version part",
			cve:  "CVE-2022-45889",
			meta: &wfn.Attributes{
				Vendor:  "planetestream",
				Product: "planet_estream",
				Version: "6.72.10.06",
			},
			want:    "6.72.10.07",
			wantErr: false,
		},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added as part of #17683

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing this test to something like 6.72.10.1 and 6.72.10.2 would make this test pass. The 0\d+ pattern is what is considered "invalid"

Copy link
Contributor Author

@ksykulev ksykulev Jan 15, 2025

Choose a reason for hiding this comment

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

Going to skip this location as #24810 will most likely be removing semver usage here.

6.72.10.07 is a real software version number > https://nvd.nist.gov/vuln/detail/CVE-2022-45889

So trying to munge this sort of parsing to be valid semver seems futile.

Copy link
Contributor Author

@ksykulev ksykulev left a comment

Choose a reason for hiding this comment

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

Should server/vulnerabilities/nvd/cve.go#L731 be merged with the new func VersionToSemverVersion?

Answer: No. This code is going to be dealt with #24810

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.59%. Comparing base (a672ff8) to head (73131a3).
Report is 114 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #25437   +/-   ##
=======================================
  Coverage   63.58%   63.59%           
=======================================
  Files        1619     1619           
  Lines      154939   154986   +47     
  Branches     4038     4038           
=======================================
+ Hits        98524    98568   +44     
- Misses      48646    48648    +2     
- Partials     7769     7770    +1     
Flag Coverage Δ
backend 64.44% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@mostlikelee mostlikelee left a comment

Choose a reason for hiding this comment

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

suggested a few places to remove to reduce risk/testing, otherwise LGTM

@@ -406,7 +406,7 @@ func isCryptsetupVersionLessThan2_4() (bool, error) {
return false, fmt.Errorf("unexpected output format: %s", outputStr)
}

installedVersion, err := semver.NewVersion(parts[1])
installedVersion, err := fleet.VersionToSemverVersion(parts[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

i'd argue we don't need to change this (possibly adding risk) since this code only touches cryptsetup on linux

@@ -89,7 +90,7 @@ func buildNFPM(opt Options, pkger nfpm.Packager) (string, error) {
}

varLibSymlink := false
if orbitSemVer, err := semver.NewVersion(updatesData.OrbitVersion); err == nil {
if orbitSemVer, err := fleet.VersionToSemverVersion(updatesData.OrbitVersion); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, Apple host OS version shouldn't come through this path

@@ -88,7 +89,7 @@ func BuildPkg(opt Options) (string, error) {
opt.Version = updatesData.OrbitVersion
}

if orbitSemVer, err := semver.NewVersion(updatesData.OrbitVersion); err == nil {
if orbitSemVer, err := fleet.VersionToSemverVersion(updatesData.OrbitVersion); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here as above

Copy link
Contributor

@mostlikelee mostlikelee left a comment

Choose a reason for hiding this comment

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

LGTM!

@ksykulev ksykulev merged commit d893025 into main Jan 23, 2025
32 checks passed
@ksykulev ksykulev deleted the 22919-semver-util branch January 23, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants