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

Severity Level Validation Improvements (CRASM-1057) #747

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
5 changes: 3 additions & 2 deletions backend/src/api/vulnerabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ class VulnerabilitySearch {
if (this.filters?.severity) {
if (this.filters.severity === 'N/A') {
qs.andWhere(
"vulnerability.severity IS NULL OR vulnerability.severity = ''"
"vulnerability.severity IS NULL OR vulnerability.severity = '' OR vulnerability.severity ILIKE 'N/A' OR vulnerability.severity ILIKE 'NULL'"
);
} else if (this.filters.severity === 'Other') {
qs.andWhere(
`vulnerability.severity NOT ILIKE 'N/A' AND
`vulnerability.severity NOT ILIKE 'NULL' AND
vulnerability.severity NOT ILIKE 'N/A' AND
vulnerability.severity NOT ILIKE 'Low' AND
vulnerability.severity NOT ILIKE 'Medium' AND
vulnerability.severity NOT ILIKE 'High' AND
Expand Down
28 changes: 19 additions & 9 deletions frontend/src/pages/Risk/VulnerabilityBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ const VulnerabilityBarChart = (props: {
</>
);

// Place null values in "N/A" and capitalize the first letter of each word in the data.
// Capitalize the first letter of each word in the data.
const titleCaseData: BarData[] = data.map((d) => {
if (d.id === 'null' || d.id === null || d.id === '') {
return { id: 'N/A', value: d.value };
} else {
return {
id: d.id[0]?.toUpperCase() + d.id.slice(1)?.toLowerCase(),
value: d.value
};
}
return {
id: d.id[0]?.toUpperCase() + d.id.slice(1)?.toLowerCase(),
value: d.value
};
});
console.log('data', data);
console.log('titleCaseData', titleCaseData);

// Group the data by severity level and "Other". Sum the values for each group.
const groupedData = titleCaseData
Expand All @@ -98,6 +96,16 @@ const VulnerabilityBarChart = (props: {
];
if (severityLevels.includes(d.id)) {
return d;
}
if (
d.id === null ||
d.id === undefined ||
d.id === 'Null' ||
d.id === 'N/a' ||
d.id === 'undefined' ||
d.id === ''
) {
return { id: 'N/A', value: d.value };
} else {
return { id: 'Other', value: d.value };
}
Expand All @@ -111,6 +119,8 @@ const VulnerabilityBarChart = (props: {
return acc;
}, {});

console.log('groupedData', groupedData);

// Sort the data to ensure "N/A", "Low", "Medium", "High", and "Critical" appear in the desired order
const sortedData = Object.entries(groupedData)
.map(([id, value]) => ({ id, value }))
Expand Down
59 changes: 51 additions & 8 deletions frontend/src/pages/Vulnerabilities/Vulnerabilities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,39 @@
const titleCase = (str: string) =>
str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();

const severityLevels: string[] = ['Low', 'Medium', 'High', 'Critical'];
const severityLevels: string[] = [
'N/A',
'Low',
'Medium',
'High',
'Critical',
'Other'
];

const formatSeverity = (severity: string) => {
if (severity === null || severity === '' || severity === 'N/A') {
// To-Do: Create array(s) to handle permutations of null and N/A values

const formatSeverity = (severity?: any) => {
const titleCaseSev = titleCase(severity);
if (severityLevels.includes(titleCaseSev)) {
return titleCaseSev;
}
console.log('severity', severity);
console.log('titleCaseSev', titleCaseSev);
if (
titleCaseSev === null ||
Fixed Show fixed Hide fixed
titleCaseSev === undefined ||
titleCaseSev === 'Null' ||
titleCaseSev === 'N/a' ||
titleCaseSev === 'undefined' ||
titleCaseSev === ''
) {
return 'N/A';
} else if (severityLevels.includes(titleCase(severity))) {
return titleCase(severity);
} else {
return 'Other';
}
};

const severity = formatSeverity(vuln.severity ?? '');
const severity = formatSeverity(vuln.severity ?? 'N/A');

return {
id: vuln.id,
Expand All @@ -351,6 +371,11 @@
};
});

const vulnSeverities = vulnerabilities.map((vuln) => vuln.severity);
console.log('vulnSevs', vulnSeverities);
const vulRowsSeverities = vulRows.map((vuln) => vuln.severity);
console.log('vulnRowsSevs', vulRowsSeverities);

const vulCols: GridColDef[] = [
{
field: 'title',
Expand Down Expand Up @@ -388,21 +413,39 @@
flex: 0.5,
sortComparator: (v1, v2, cellParams1, cellParams2) => {
const severityLevels: Record<string, number> = {
'N/A': 0,
Low: 1,
Medium: 2,
High: 3,
Critical: 4
Critical: 4,
Other: 5
};
if (
cellParams1.value === 'N/A' &&
cellParams2.value !== 'N/A' &&
cellParams2.value !== 'Other'
) {
return -1;
}
if (
cellParams2.value === 'N/A' &&
cellParams1.value !== 'N/A' &&
cellParams1.value !== 'Other'
) {
return 1;
}
return (
severityLevels[cellParams1.value] - severityLevels[cellParams2.value]
);
},
renderCell: (cellValues: GridRenderCellParams) => {
const severityLevels: Record<string, number> = {
NA: 0,
Low: 1,
Medium: 2,
High: 3,
Critical: 4
Critical: 4,
Other: 5
};
return (
<Stack>
Expand Down
Loading