Fleet UI: Fix vulns from being counted multiple times in vuln count (#32044)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
- Fleet UI: Fixed bug deduplicating to only count unique vulns when counting software title vulnerabilities across versions in various software title vulnerabilities count, and host software title vulnerabilities count
|
||||
+1
-20
@@ -20,6 +20,7 @@ import SoftwareNameCell from "components/TableContainer/DataTable/SoftwareNameCe
|
||||
|
||||
import VersionCell from "../../components/tables/VersionCell";
|
||||
import VulnerabilitiesCell from "../../components/tables/VulnerabilitiesCell";
|
||||
import { getVulnerabilities } from "./helpers";
|
||||
|
||||
// NOTE: cellProps come from react-table
|
||||
// more info here https://react-table.tanstack.com/docs/api/useTable#cell-properties
|
||||
@@ -36,26 +37,6 @@ type IViewAllHostsLinkProps = CellProps<ISoftwareTitle>;
|
||||
|
||||
type ITableHeaderProps = IHeaderProps<ISoftwareTitle>;
|
||||
|
||||
export const getVulnerabilities = <
|
||||
T extends { vulnerabilities: string[] | null }
|
||||
>(
|
||||
versions: T[]
|
||||
) => {
|
||||
if (!versions) {
|
||||
return [];
|
||||
}
|
||||
const vulnerabilities = versions.reduce((acc: string[], currentVersion) => {
|
||||
if (
|
||||
currentVersion.vulnerabilities &&
|
||||
currentVersion.vulnerabilities.length !== 0
|
||||
) {
|
||||
acc.push(...currentVersion.vulnerabilities);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
return vulnerabilities;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the data needed to render the software name cell.
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isValidNumber } from "./helpers";
|
||||
import { isValidNumber, getVulnerabilities } from "./helpers";
|
||||
|
||||
describe("isValidNumber", () => {
|
||||
// Test valid numbers
|
||||
@@ -47,3 +47,54 @@ describe("isValidNumber", () => {
|
||||
expect(isValidNumber(11, 0, 10)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
const versions = [
|
||||
{
|
||||
id: 531270,
|
||||
version: "131.0.6778.86",
|
||||
vulnerabilities: ["CVE-2024-12053", "CVE-2024-12381", "CVE-2025-0444"],
|
||||
},
|
||||
{
|
||||
id: 538184,
|
||||
version: "132.0.6834.160",
|
||||
vulnerabilities: ["CVE-2025-0444", "CVE-2025-0445"], // 0444 is duplicate
|
||||
},
|
||||
{
|
||||
id: 541233,
|
||||
version: "133.0.6943.53",
|
||||
vulnerabilities: ["CVE-2025-0995", "CVE-2025-0996"],
|
||||
},
|
||||
{
|
||||
id: 572993,
|
||||
version: "139.0.7258.127",
|
||||
vulnerabilities: null, // should be ignored
|
||||
},
|
||||
];
|
||||
|
||||
describe("getVulnerabilities", () => {
|
||||
it("returns a unique list of vulnerabilities across all versions", () => {
|
||||
const result = getVulnerabilities(versions);
|
||||
|
||||
// Expect no duplicates
|
||||
expect(new Set(result).size).toBe(result.length);
|
||||
|
||||
// Expect specific vulns present
|
||||
expect(result).toEqual(
|
||||
expect.arrayContaining([
|
||||
"CVE-2024-12053",
|
||||
"CVE-2024-12381",
|
||||
"CVE-2025-0444",
|
||||
"CVE-2025-0445",
|
||||
"CVE-2025-0995",
|
||||
"CVE-2025-0996",
|
||||
])
|
||||
);
|
||||
|
||||
// Should not contain unintended values
|
||||
expect(result).not.toContain("CVE-DOES-NOT-EXIST");
|
||||
});
|
||||
|
||||
it("returns an empty array if no versions are given", () => {
|
||||
expect(getVulnerabilities([])).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -239,3 +239,22 @@ export const getVulnFilterRenderDetails = (
|
||||
tooltipText: tooltipTextWithLineBreaks(tooltipText),
|
||||
};
|
||||
};
|
||||
|
||||
export const getVulnerabilities = <
|
||||
T extends { vulnerabilities: string[] | null }
|
||||
>(
|
||||
versions: T[]
|
||||
): string[] => {
|
||||
if (!versions) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const vulnerabilities = versions.reduce((acc, current) => {
|
||||
if (current.vulnerabilities?.length) {
|
||||
current.vulnerabilities.forEach((vuln) => acc.add(vuln));
|
||||
}
|
||||
return acc;
|
||||
}, new Set<string>());
|
||||
|
||||
return [...vulnerabilities];
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ import TextCell from "components/TableContainer/DataTable/TextCell";
|
||||
|
||||
import VulnerabilitiesCell from "pages/SoftwarePage/components/tables/VulnerabilitiesCell";
|
||||
import VersionCell from "pages/SoftwarePage/components/tables/VersionCell";
|
||||
import { getVulnerabilities } from "pages/SoftwarePage/SoftwareTitles/SoftwareTable/SoftwareTitlesTableConfig";
|
||||
import { getVulnerabilities } from "pages/SoftwarePage/SoftwareTitles/SoftwareTable/helpers";
|
||||
import SoftwareNameCell from "components/TableContainer/DataTable/SoftwareNameCell";
|
||||
|
||||
type ISoftwareTableConfig = Column<IHostSoftware>;
|
||||
|
||||
@@ -22,7 +22,7 @@ import { HumanTimeDiffWithDateTip } from "components/HumanTimeDiffWithDateTip";
|
||||
|
||||
import VulnerabilitiesCell from "pages/SoftwarePage/components/tables/VulnerabilitiesCell";
|
||||
import VersionCell from "pages/SoftwarePage/components/tables/VersionCell";
|
||||
import { getVulnerabilities } from "pages/SoftwarePage/SoftwareTitles/SoftwareTable/SoftwareTitlesTableConfig";
|
||||
import { getVulnerabilities } from "pages/SoftwarePage/SoftwareTitles/SoftwareTable/helpers";
|
||||
import { getAutomaticInstallPoliciesCount } from "pages/SoftwarePage/helpers";
|
||||
import { sourcesWithLastOpenedTime } from "pages/hosts/details/components/InventoryVersions/InventoryVersions";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user