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 #747

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 8 additions & 9 deletions frontend/src/pages/Risk/VulnerabilityBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,12 @@ 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
};
});

// Group the data by severity level and "Other". Sum the values for each group.
Expand All @@ -98,6 +94,9 @@ const VulnerabilityBarChart = (props: {
];
if (severityLevels.includes(d.id)) {
return d;
}
if (!d.id || ['Null', 'N/a', 'undefined', ''].includes(d.id)) {
return { id: 'N/A', value: d.value };
} else {
return { id: 'Other', value: d.value };
}
Expand Down
38 changes: 27 additions & 11 deletions frontend/src/pages/Vulnerabilities/Vulnerabilities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,31 @@ export const Vulnerabilities: React.FC<{ groupBy?: string }> = ({
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') {
const formatSeverity = (severity?: any) => {
const titleCaseSev = titleCase(severity);
if (severityLevels.includes(titleCaseSev)) {
return titleCaseSev;
}
if (
!titleCaseSev ||
['Null', 'N/a', 'undefined', ''].includes(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 Down Expand Up @@ -388,21 +400,25 @@ export const Vulnerabilities: React.FC<{ groupBy?: string }> = ({
flex: 0.5,
sortComparator: (v1, v2, cellParams1, cellParams2) => {
const severityLevels: Record<string, number> = {
Low: 1,
Medium: 2,
High: 3,
Critical: 4
'N/A': 1,
Low: 2,
Medium: 3,
High: 4,
Critical: 5,
Other: 6
};
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