Skip to content

Commit

Permalink
add cves filter
Browse files Browse the repository at this point in the history
  • Loading branch information
milan-deepfence committed Jul 12, 2024
1 parent 686ad39 commit 6442ea0
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ export const getNotificationPrettyName = (notificationType: string) => {

export const canSendScanSummary = (notificationType: string, integrationType: string) => {
return (
((integrationType === IntegrationType.slack ||
(integrationType === IntegrationType.slack ||
integrationType === IntegrationType.microsoftTeams) &&
['Secret', 'Vulnerability', 'Malware'].includes(notificationType)) ||
isComplianceNotification(notificationType) ||
isCloudComplianceNotification(notificationType)
(['Secret', 'Vulnerability', 'Malware'].includes(notificationType) ||
isComplianceNotification(notificationType) ||
isCloudComplianceNotification(notificationType))
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const SearchableCVE = ({
? `${selectedCVEIds.length} selected`
: null
}
placeholder="CVEs"
placeholder="CVE ID"
multiple
value={selectedCVEIds}
onChange={(values) => {
Expand Down Expand Up @@ -129,7 +129,7 @@ export const SearchableCVEList = (props: SearchableCVEListProps) => {
label={isSelectVariantType ? 'CVE' : undefined}
triggerVariant={triggerVariant || 'button'}
startIcon={<CircleSpinner size="sm" className="w-3 h-3" />}
placeholder="CVEs"
placeholder="CVE ID"
multiple
onQueryChange={() => {
// no operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { VulnerabilityIcon } from '@/components/sideNavigation/icons/Vulnerabili
import { TruncatedText } from '@/components/TruncatedText';
import { BreadcrumbWrapper } from '@/features/common/BreadcrumbWrapper';
import { FilterWrapper } from '@/features/common/FilterWrapper';
import { SearchableCVEList } from '@/features/vulnerabilities/components/ScanResults/SearchableCVEList';
import { queries } from '@/queries';
import { useTheme } from '@/theme/ThemeContext';
import { ScanTypeEnum, VulnerabilitySeverityType } from '@/types/common';
Expand All @@ -61,6 +62,7 @@ enum FILTER_SEARCHPARAMS_KEYS_ENUM {
containers = 'containers',
containerImages = 'containerImages',
clusters = 'clusters',
cveId = 'cveId',
}

const FILTER_SEARCHPARAMS_DYNAMIC_KEYS = [
Expand All @@ -77,6 +79,7 @@ const FILTER_SEARCHPARAMS: Record<FILTER_SEARCHPARAMS_KEYS_ENUM, string> = {
containers: 'Container',
containerImages: 'Container Images',
clusters: 'Clusters',
cveId: 'CVE Id',
};

const getPrettyNameForAppliedFilters = ({
Expand Down Expand Up @@ -261,6 +264,27 @@ const Filters = () => {
);
})}
</Combobox>
<SearchableCVEList
scanId={''}
defaultSelectedCVEIds={searchParams.getAll('cveId')}
onChange={(values) => {
setSearchParams((prev) => {
prev.delete('cveId');
values.forEach((value) => {
prev.append('cveId', value);
});
prev.delete('page');
return prev;
});
}}
onClearAll={() => {
setSearchParams((prev) => {
prev.delete('cveId');
prev.delete('page');
return prev;
});
}}
/>
<Combobox
getDisplayValue={() => FILTER_SEARCHPARAMS['liveConnection']}
multiple
Expand Down Expand Up @@ -524,7 +548,12 @@ const MostExploitTable = () => {
maxSize: 85,
}),
columnHelper.accessor('cve_attack_vector', {
cell: (info) => <TruncatedText text={info.getValue() ?? ''} />,
cell: (info) => {
if (!info.getValue().length) {
return <div className="ml-[26px] border-b w-[8px] border-text-icon"></div>;
}
return <TruncatedText text={info.getValue() ?? ''} />;
},
header: () => <TruncatedText text="Attack vector" />,
minSize: 100,
size: 120,
Expand All @@ -542,7 +571,9 @@ const MostExploitTable = () => {
enableSorting: false,
enableResizing: false,
cell: (info) => {
if (!info.getValue().length) return '-';
if (!info.getValue().length) {
return <div className="ml-[26px] border-b w-[8px] border-text-icon"></div>;
}
return (
<DFLink href={info.getValue()} target="_blank">
<div className="w-4 h-4">
Expand Down Expand Up @@ -578,6 +609,7 @@ const MostExploitTable = () => {
containerIds: searchParams.getAll('containers'),
containerImageIds: searchParams.getAll('containerImages'),
clusterIds: searchParams.getAll('clusters'),
cve: searchParams.getAll('cveId'),
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { VulnerabilityIcon } from '@/components/sideNavigation/icons/Vulnerabili
import { TruncatedText } from '@/components/TruncatedText';
import { BreadcrumbWrapper } from '@/features/common/BreadcrumbWrapper';
import { FilterWrapper } from '@/features/common/FilterWrapper';
import { SearchableCVEList } from '@/features/vulnerabilities/components/ScanResults/SearchableCVEList';
import { queries } from '@/queries';
import { useTheme } from '@/theme/ThemeContext';
import { ScanTypeEnum, VulnerabilitySeverityType } from '@/types/common';
Expand All @@ -47,6 +48,7 @@ enum FILTER_SEARCHPARAMS_KEYS_ENUM {
containers = 'containers',
containerImages = 'containerImages',
clusters = 'clusters',
cveId = 'cveId',
}

const FILTER_SEARCHPARAMS_DYNAMIC_KEYS = [
Expand All @@ -63,6 +65,7 @@ const FILTER_SEARCHPARAMS: Record<FILTER_SEARCHPARAMS_KEYS_ENUM, string> = {
containers: 'Container',
containerImages: 'Container Images',
clusters: 'Clusters',
cveId: 'CVE Id',
};

const getPrettyNameForAppliedFilters = ({
Expand Down Expand Up @@ -149,6 +152,27 @@ const Filters = () => {
);
})}
</Combobox>
<SearchableCVEList
scanId={''}
defaultSelectedCVEIds={searchParams.getAll('cveId')}
onChange={(values) => {
setSearchParams((prev) => {
prev.delete('cveId');
values.forEach((value) => {
prev.append('cveId', value);
});
prev.delete('page');
return prev;
});
}}
onClearAll={() => {
setSearchParams((prev) => {
prev.delete('cveId');
prev.delete('page');
return prev;
});
}}
/>
<Combobox
getDisplayValue={() => FILTER_SEARCHPARAMS['liveConnection']}
multiple
Expand Down Expand Up @@ -401,7 +425,12 @@ const UniqueTable = () => {
}),
columnHelper.accessor('cve_attack_vector', {
enableSorting: false,
cell: (info) => <TruncatedText text={info.getValue() ?? ''} />,
cell: (info) => {
if (!info.getValue().length) {
return <div className="ml-[26px] border-b w-[8px] border-text-icon"></div>;
}
return <TruncatedText text={info.getValue() ?? ''} />;
},
header: () => <TruncatedText text="Attack vector" />,
minSize: 100,
size: 120,
Expand All @@ -419,7 +448,9 @@ const UniqueTable = () => {
enableSorting: false,
enableResizing: true,
cell: (info) => {
if (!info.getValue().length) return '-';
if (!info.getValue().length) {
return <div className="ml-[26px] border-b w-[8px] border-text-icon"></div>;
}
return (
<DFLink href={info.getValue()} target="_blank">
<div className="w-4 h-4">
Expand Down Expand Up @@ -458,6 +489,7 @@ const UniqueTable = () => {
containerIds: searchParams.getAll('containers'),
containerImageIds: searchParams.getAll('containerImages'),
clusterIds: searchParams.getAll('clusters'),
cve: searchParams.getAll('cveId'),
}),
keepPreviousData: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ const Filters = () => {
}}
onClearAll={() => {
setSearchParams((prev) => {
prev.delete('cve');
prev.delete('cveId');
prev.delete('page');
return prev;
});
Expand Down
16 changes: 16 additions & 0 deletions deepfence_frontend/apps/dashboard/src/queries/vulnerability.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ export const vulnerabilityQueries = createQueryKeys('vulnerability', {
containerIds: string[];
containerImageIds: string[];
clusterIds: string[];
cve: string[];
}) => {
const {
page = 1,
Expand All @@ -678,6 +679,7 @@ export const vulnerabilityQueries = createQueryKeys('vulnerability', {
containerIds,
containerImageIds,
clusterIds,
cve,
} = filters;
return {
queryKey: [{ filters }],
Expand Down Expand Up @@ -785,6 +787,12 @@ export const vulnerabilityQueries = createQueryKeys('vulnerability', {
}
}

if (cve.length) {
searchVulnerabilitiesRequestParams.node_filter.filters.contains_filter.filter_in![
'cve_id'
] = cve;
}

if (order) {
searchVulnerabilitiesRequestParams.node_filter.filters.order_filter.order_fields =
[
Expand Down Expand Up @@ -843,6 +851,7 @@ export const vulnerabilityQueries = createQueryKeys('vulnerability', {
containerIds: string[];
containerImageIds: string[];
clusterIds: string[];
cve: string[];
}) => {
const {
severity,
Expand All @@ -851,6 +860,7 @@ export const vulnerabilityQueries = createQueryKeys('vulnerability', {
containerIds,
containerImageIds,
clusterIds,
cve,
} = filters;
return {
queryKey: [{ filters }],
Expand Down Expand Up @@ -970,6 +980,12 @@ export const vulnerabilityQueries = createQueryKeys('vulnerability', {
};
}

if (cve.length) {
searchVulnerabilitiesRequestParams!.extended_node_filter!.filters.contains_filter.filter_in![
'cve_id'
] = cve;
}

const searchVulnerabilitiesApi = apiWrapper({
fn: getSearchApiClient().searchVulnerabilities,
});
Expand Down

0 comments on commit 6442ea0

Please sign in to comment.