Skip to content

chore: Extend /vulnerabilities response to return fixed versions - #141

Merged
jdobes merged 1 commit into
RedHatInsights:mainfrom
RostyslavKachan:extend_vuln_endpoint_fixed_version
Sep 10, 2026
Merged

jdobes merged 1 commit into
RedHatInsights:mainfrom
RostyslavKachan:extend_vuln_endpoint_fixed_version

Conversation

@RostyslavKachan

Copy link
Copy Markdown
Contributor

RHINENG-29137

@codecov-commenter

codecov-commenter commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.56%. Comparing base (b64c496) to head (def2127).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
vmaas/vulnerabilities.go 75.86% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #141      +/-   ##
==========================================
- Coverage   70.72%   70.56%   -0.16%     
==========================================
  Files          30       30              
  Lines        2842     2844       +2     
==========================================
- Hits         2010     2007       -3     
- Misses        722      727       +5     
  Partials      110      110              
Flag Coverage Δ
unittests 70.56% <75.86%> (-0.16%) ⬇️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread vmaas/vulnerabilities.go Outdated
}
if update.manuallyFixable {
updateCves(tmpManualCves, cve, Package{String: pkg}, []string{update.Erratum}, "", nil)
updateCves(tmpManualCves, cve, pkgDetail, []string{update.Erratum}, "", nil, update.EVRA)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would avoid displaying any fixed version for manually fixable CVEs.

Comment thread vmaas/types.go
Comment thread vmaas/vulnerabilities.go
seenPkgErratum := map[packageErratum]bool{}
tmpManualCves := map[string]VulnerabilityDetail{}
for pkg, upDetail := range updates.UpdateList {
for _, update := range upDetail.AvailableUpdates {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since it's going through all available updated packages (from multiple errata) and collecting CVEs, the affected section can contain multiple newer fixed EVRAs.

Only one affected item for each affected package would be better - probably the earliest fixed EVRA would be best.

E.g.

    {
      "cve": "CVE-2026-31885",
      "affected_packages": [
        "freerdp-2:2.11.7-1.el9_7.2.x86_64",
        "freerdp-libs-2:2.11.7-1.el9_7.2.x86_64",
        "libwinpr-2:2.11.7-1.el9_7.2.x86_64"
      ],
      "errata": [
        "RHSA-2026:16482",
        "RHSA-2026:19358"
      ],
      "affected": [
        {
          "package_name": "libwinpr",
          "evra": "2:2.11.7-1.el9_7.2.x86_64",
          "fixed_evra": "2:2.11.7-1.el9_7.7.x86_64",
          "cpe": "",
          "module_name": null,
          "module_stream": null
        },
        {
          "package_name": "libwinpr",
          "evra": "2:2.11.7-1.el9_7.2.x86_64",
          "fixed_evra": "2:2.11.7-7.el9_8.3.x86_64",
          "cpe": "",
          "module_name": null,
          "module_stream": null
        },
        {
          "package_name": "freerdp-libs",
          "evra": "2:2.11.7-1.el9_7.2.x86_64",
          "fixed_evra": "2:2.11.7-1.el9_7.7.x86_64",
          "cpe": "",
          "module_name": null,
          "module_stream": null
        },
        {
          "package_name": "freerdp-libs",
          "evra": "2:2.11.7-1.el9_7.2.x86_64",
          "fixed_evra": "2:2.11.7-7.el9_8.3.x86_64",
          "cpe": "",
          "module_name": null,
          "module_stream": null
        },
        {
          "package_name": "freerdp",
          "evra": "2:2.11.7-1.el9_7.2.x86_64",
          "fixed_evra": "2:2.11.7-1.el9_7.7.x86_64",
          "cpe": "",
          "module_name": null,
          "module_stream": null
        },
        {
          "package_name": "freerdp",
          "evra": "2:2.11.7-1.el9_7.2.x86_64",
          "fixed_evra": "2:2.11.7-7.el9_8.3.x86_64",
          "cpe": "",
          "module_name": null,
          "module_stream": null
        }
      ]
    }

@RostyslavKachan
RostyslavKachan force-pushed the extend_vuln_endpoint_fixed_version branch 8 times, most recently from 2253e62 to 49bc237 Compare September 7, 2026 11:39
Comment thread vmaas/vulnerabilities.go Outdated
found := false
for i, ap := range vulnDetail.Affected {
if affectedKey(ap) == newKey {
if newAP.FixedEVRA != "" && ap.FixedEVRA != "" && isEarlierEVRA(newAP.FixedEVRA, ap.FixedEVRA) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any version comparison is not needed. Just take the first one reported from Updates API, they are already sorted. https://github.com/RedHatInsights/vmaas-lib/blob/main/vmaas/common.go#L168

Comment thread vmaas/vulnerabilities_test.go Outdated
assert.Contains(t, cves.ManualCves["CVE-1"].Errata, "RHSA-6")
assert.Len(t, cves.ManualCves["CVE-1"].Affected, 2)
assert.Equal(t, cves.ManualCves["CVE-1"].Affected[0].Cpe, currentReleaseCPE)
assert.Equal(t, "0:1-1.x86_64", cves.ManualCves["CVE-1"].Affected[0].FixedEVRA)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FixedEVRA for any ManualCves shouldn't be empty?

@RostyslavKachan
RostyslavKachan force-pushed the extend_vuln_endpoint_fixed_version branch 3 times, most recently from fb1028a to 884373e Compare September 7, 2026 15:11
Comment thread vmaas/vulnerabilities.go Outdated
return p
}
pkgDetail := Package{String: pkg}
if nevra, err := utils.ParseNevra(pkg, true); err == nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Calling the utils.ParseNevra should not be needed. This information should be available from other structs. Also always you can concat name + "-" + evra to get nevra

Comment thread vmaas/vulnerabilities.go Outdated
newAP := buildAffectedPackage(pkg, cpe, module, fixedEVRA)
newKey := affectedKey(newAP)
found := false
for _, ap := range vulnDetail.Affected {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this use a map instead of looping the slice?

Comment thread vmaas/vulnerabilities.go Outdated
EVRA: pkg.EVRAStringE(true),
Cpe: cpe,
newAP := buildAffectedPackage(pkg, cpe, module, fixedEVRA)
newKey := affectedKey(newAP)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Composite string key from almost all AffectedPackage attributes is not needed. We can assume that the package name is unique in this scope.

@RostyslavKachan
RostyslavKachan force-pushed the extend_vuln_endpoint_fixed_version branch from 884373e to def2127 Compare September 9, 2026 13:58
@jdobes
jdobes merged commit 7a73c2e into RedHatInsights:main Sep 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants