Skip to content

Commit

Permalink
Count total unique vulnerabilities across severities (#3776)
Browse files Browse the repository at this point in the history
Signed-off-by: Cintia Sanchez Garcia <[email protected]>
  • Loading branch information
cynthia-sg authored Apr 18, 2024
1 parent c43ccf9 commit b48907b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 4 additions & 5 deletions web/src/layout/package/securityReport/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import API from '../../../api';
import { FixableVulnerabilitiesInReport, RepositoryKind, SecurityReport, SecurityReportSummary } from '../../../types';
import alertDispatcher from '../../../utils/alertDispatcher';
import isFuture from '../../../utils/isFuture';
import sumObjectValues from '../../../utils/sumObjectValues';
import {
filterFixableVulnerabilities,
prepareFixableSummary,
Expand Down Expand Up @@ -86,10 +85,10 @@ const SecurityModal = (props: Props) => {
const fixableVulnerabilities = filterFixableVulnerabilities(currentReport);
setFixableReport(fixableVulnerabilities);
setFixableReportSummary(prepareFixableSummary(fixableVulnerabilities));
const uniqueSummary = prepareUniqueVulnerabilitiesSummary(currentReport);
setUniqueSummary(uniqueSummary);
if (!isNull(uniqueSummary)) {
setTotalUniqueVulnerabilities(sumObjectValues(uniqueSummary));
const uniqueVulnerabilities = prepareUniqueVulnerabilitiesSummary(currentReport);
if (!isNull(uniqueVulnerabilities)) {
setUniqueSummary(uniqueVulnerabilities.summary);
setTotalUniqueVulnerabilities(uniqueVulnerabilities.total);
}
activateTargetWhenIsOnlyOne(currentReport);
setIsLoading(false);
Expand Down
4 changes: 2 additions & 2 deletions web/src/layout/package/securityReport/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const SecuritySummary = (props: Props) => {
};

const getExtraData = (): JSX.Element => {
if (props.totalFixableVulnerabilities > 0 || props.totalUniqueVulnerabilities > 0) {
const visibleFixable = props.totalFixableVulnerabilities > 0 && !props.allVulnerabilitiesAreFixable;
const visibleFixable = props.totalFixableVulnerabilities > 0 && !props.allVulnerabilitiesAreFixable;

if (visibleFixable || props.totalUniqueVulnerabilities > 0) {
return (
<>
(
Expand Down
8 changes: 6 additions & 2 deletions web/src/utils/vulnerabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ const prepareFixableSummary = (
return fixReport;
};

const prepareUniqueVulnerabilitiesSummary = (currentReport: SecurityReport | null): SecurityReportSummary | null => {
const prepareUniqueVulnerabilitiesSummary = (
currentReport: SecurityReport | null
): { summary: SecurityReportSummary; total: number } | null => {
if (isNull(currentReport)) return null;

const fullReportSumary: SecurityReportSummary = {};
const summary: any = {};
const uniqueSummaryReport: SecurityReportSummary = {};
const allVulnerabilities: string[] = [];

Object.keys(currentReport).forEach((img: string) => {
currentReport[img].Results.forEach((target: SecurityReportResult) => {
if (target.Vulnerabilities) {
target.Vulnerabilities.forEach((vulnerability: Vulnerability) => {
const severity = vulnerability.Severity.toLowerCase() as VulnerabilitySeverity;
allVulnerabilities.push(vulnerability.VulnerabilityID);
if (isUndefined(summary[severity])) {
summary[severity] = [vulnerability.VulnerabilityID];
fullReportSumary[severity] = 1;
Expand All @@ -69,7 +73,7 @@ const prepareUniqueVulnerabilitiesSummary = (currentReport: SecurityReport | nul
if (isEqual(fullReportSumary, uniqueSummaryReport)) {
return null;
} else {
return uniqueSummaryReport;
return { summary: uniqueSummaryReport, total: new Set(allVulnerabilities).size };
}
};

Expand Down

0 comments on commit b48907b

Please sign in to comment.