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

Merged
merged 20 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3f7de25
Refined Severity Levels filtering in Bar Chart
hawkishpolicy Dec 23, 2024
e5a8017
Added to-do for N/A values array
hawkishpolicy Dec 23, 2024
c562310
Refined Severity Level sorting and grouping
hawkishpolicy Dec 27, 2024
2da4510
Removed unnecessary if statement from Comparator
hawkishpolicy Dec 27, 2024
cbd704d
Removed unused console.logs and variables
hawkishpolicy Dec 27, 2024
1afe5c3
Refactored if statement for N/A values
hawkishpolicy Dec 30, 2024
ffa2013
Removed console.logs and unused variables
hawkishpolicy Dec 30, 2024
d0d6694
Merge remote-tracking branch 'origin/develop' into Severity-Level-Imp…
hawkishpolicy Jan 8, 2025
8489044
Merge remote-tracking branch 'origin/develop' into Severity-Level-Imp…
hawkishpolicy Jan 10, 2025
57b4da5
Irregular Severity Levels Improvements
hawkishpolicy Jan 13, 2025
096cfe3
Removed console.logs and prints
hawkishpolicy Jan 13, 2025
0bb820b
Refactored boolean logic in filter_helpers.py
hawkishpolicy Jan 13, 2025
382d408
Removed commented out code
hawkishpolicy Jan 13, 2025
eadd96a
hawkishpolicy Jan 15, 2025
bc76c2f
Removed console.logs
hawkishpolicy Jan 16, 2025
185ca6f
Updated import of sanitize in app.ts
hawkishpolicy Jan 16, 2025
cacba6d
Changes to dompurify import
hawkishpolicy Jan 16, 2025
c6eff3a
Reverted changes to ResultCard
hawkishpolicy Jan 16, 2025
1eb0117
Merge remote-tracking branch 'origin/develop' into Severity-Level-Imp…
hawkishpolicy Jan 16, 2025
3d16c52
Merge remote-tracking branch 'origin/develop' into Severity-Level-Imp…
hawkishpolicy Jan 21, 2025
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
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