Skip to content

Commit

Permalink
Add: Toggle to enable EPSS fields
Browse files Browse the repository at this point in the history
The EPSS fields for CVEs and VTs can now be toggled with an option in
the config.js file.

This is done because no EPSS feed is provided yet, so the new fields
should only be enabled for testing.
  • Loading branch information
timopollmeier committed Jun 18, 2024
1 parent e9a1b84 commit a0042e4
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 96 deletions.
2 changes: 2 additions & 0 deletions src/gmp/gmpsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const warnDeprecatedSetting = (oldName, newName) => {
class GmpSettings {
constructor(storage = global.localStorage, options = {}) {
const {
enableEPSS = false,
enableGreenboneSensor = false,
disableLoginForm = false,
enableStoreDebugLog,
Expand Down Expand Up @@ -109,6 +110,7 @@ class GmpSettings {
setAndFreeze(this, 'apiProtocol', apiProtocol);
setAndFreeze(this, 'apiServer', apiServer);
setAndFreeze(this, 'disableLoginForm', disableLoginForm);
setAndFreeze(this, 'enableEPSS', enableEPSS);
setAndFreeze(this, 'enableGreenboneSensor', enableGreenboneSensor);
setAndFreeze(this, 'guestUsername', guestUsername);
setAndFreeze(this, 'guestPassword', guestPassword);
Expand Down
5 changes: 4 additions & 1 deletion src/web/pages/cves/__tests__/detailspage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ describe('CVE Detailspage tests', () => {
get: getCve,
},
reloadInterval,
settings: {manualUrl},
settings: {
manualUrl,
enableEPSS: true,
},
user: {
currentSettings,
renewSession,
Expand Down
2 changes: 1 addition & 1 deletion src/web/pages/cves/__tests__/listpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('CvesPage tests', () => {
filters: {
get: getFilters,
},
settings: {manualUrl, reloadInterval},
settings: {manualUrl, reloadInterval, enableEPSS: true},
user: {currentSettings, getSetting},
};

Expand Down
5 changes: 3 additions & 2 deletions src/web/pages/cves/details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import TableData from 'web/components/table/data';
import TableRow from 'web/components/table/row';

import PropTypes from 'web/utils/proptypes';
import useGmp from "web/utils/useGmp.jsx";

const CVSS_PROPS = {
cvssAccessVector: _l('Access Vector'),
Expand All @@ -49,7 +50,7 @@ const CVSS_PROPS = {

const CveDetails = ({entity}) => {
const {cvssBaseVector, description, references = [], severity, epss} = entity;

const gmp = useGmp();
return (
<Layout flex="column" grow="1">
{isDefined(description) && (
Expand Down Expand Up @@ -92,7 +93,7 @@ const CveDetails = ({entity}) => {
</InfoTable>
</DetailsBlock>

{isDefined(epss) && (
{gmp.settings.enableEPSS && isDefined(epss) && (
<DetailsBlock title={_('EPSS')}>
<InfoTable>
<TableBody>
Expand Down
71 changes: 40 additions & 31 deletions src/web/pages/cves/row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,53 @@ import {RowDetailsToggle} from 'web/entities/row';

import PropTypes from 'web/utils/proptypes';
import {isNumber} from "gmp/utils/identity";
import useGmp from "web/utils/useGmp.jsx";

const Row = ({
actionsComponent: ActionsComponent = EntitiesActions,
entity,
links = true,
onToggleDetailsClick,
...props
}) => (
<TableRow>
<TableData>
<span>
<RowDetailsToggle name={entity.id} onClick={onToggleDetailsClick}>
{entity.name}
</RowDetailsToggle>
</span>
<Comment text={entity.comment} />
</TableData>
<TableData>{shorten(entity.description, 160)}</TableData>
<TableData>
<DateTime date={entity.creationTime} />
</TableData>
<TableData>
<Link to="cvsscalculator" query={{cvssVector: entity.cvssBaseVector}}>
{entity.cvssBaseVector}
</Link>
</TableData>
<TableData>
<SeverityBar severity={entity.severity} />
</TableData>
<TableData>
{isNumber(entity?.epss?.score) ? entity.epss?.score.toFixed(5) : _("N/A")}
</TableData>
<TableData>
{isNumber(entity?.epss?.percentile) ? entity.epss?.percentile.toFixed(5) : _("N/A")}
</TableData>
<ActionsComponent {...props} entity={entity} />
</TableRow>
);
}) => {
const gmp = useGmp();
return (
<TableRow>
<TableData>
<span>
<RowDetailsToggle name={entity.id} onClick={onToggleDetailsClick}>
{entity.name}
</RowDetailsToggle>
</span>
<Comment text={entity.comment} />
</TableData>
<TableData>{shorten(entity.description, 160)}</TableData>
<TableData>
<DateTime date={entity.creationTime} />
</TableData>
<TableData>
<Link to="cvsscalculator" query={{cvssVector: entity.cvssBaseVector}}>
{entity.cvssBaseVector}
</Link>
</TableData>
<TableData>
<SeverityBar severity={entity.severity} />
</TableData>
{
gmp.settings.enableEPSS &&
<>
<TableData>
{isNumber(entity?.epss?.score) ? entity.epss?.score.toFixed(5) : _("N/A")}
</TableData>
<TableData>
{isNumber(entity?.epss?.percentile) ? entity.epss?.percentile.toFixed(5) : _("N/A")}
</TableData>
</>
}
<ActionsComponent {...props} entity={entity} />
</TableRow>
)
};

Row.propTypes = {
actionsComponent: PropTypes.component,
Expand Down
51 changes: 29 additions & 22 deletions src/web/pages/cves/table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import TableRow from 'web/components/table/row';
import CveDetails from './details';
import CveRow from './row';
import {isDefined} from "gmp/utils/identity.js";
import useGmp from "web/utils/useGmp.jsx";

const Header = ({
actionsColumn,
Expand All @@ -30,6 +31,7 @@ const Header = ({
currentSortDir,
onSortChange,
}) => {
const gmp = useGmp();
return (
<TableHeader>
<TableRow>
Expand All @@ -44,7 +46,7 @@ const Header = ({
/>
<TableHead
rowSpan="2"
width="52%"
width={gmp.settings.enableEPSS ? '52%' : '62%'}
currentSortDir={currentSortDir}
currentSortBy={currentSortBy}
sortBy={sort ? 'description' : false}
Expand Down Expand Up @@ -78,9 +80,11 @@ const Header = ({
onSortChange={onSortChange}
title={_('Severity')}
/>
<TableHead colSpan="2">
{_("EPSS")}
</TableHead>
{gmp.settings.enableEPSS &&
<TableHead colSpan="2">
{_("EPSS")}
</TableHead>
}
{isDefined(actionsColumn) ? (
actionsColumn
) : (
Expand All @@ -89,24 +93,27 @@ const Header = ({
</TableHead>
)}
</TableRow>
<TableRow>
<TableHead
width="5%"
currentSortDir={currentSortDir}
currentSortBy={currentSortBy}
sortBy={sort ? 'epss_score' : false}
onSortChange={onSortChange}
title={_('Score')}
/>
<TableHead
width="5%"
currentSortDir={currentSortDir}
currentSortBy={currentSortBy}
sortBy={sort ? 'epss_percentile' : false}
onSortChange={onSortChange}
title={_('Percentile')}
/>
</TableRow>
{
gmp.settings.enableEPSS &&
<TableRow>
<TableHead
width="5%"
currentSortDir={currentSortDir}
currentSortBy={currentSortBy}
sortBy={sort ? 'epss_score' : false}
onSortChange={onSortChange}
title={_('Score')}
/>
<TableHead
width="5%"
currentSortDir={currentSortDir}
currentSortBy={currentSortBy}
sortBy={sort ? 'epss_percentile' : false}
onSortChange={onSortChange}
title={_('Percentile')}
/>
</TableRow>
}
</TableHeader>
);
};
Expand Down
10 changes: 5 additions & 5 deletions src/web/pages/nvts/__tests__/detailspage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ describe('Nvt Detailspage tests', () => {
nvt: {
get: getNvt,
},
settings: {manualUrl, reloadInterval},
settings: {manualUrl, reloadInterval, enableEPSS: true},
user: {
currentSettings,
},
Expand Down Expand Up @@ -375,7 +375,7 @@ describe('Nvt Detailspage tests', () => {
overrides: {
get: getEntities,
},
settings: {manualUrl, reloadInterval},
settings: {manualUrl, reloadInterval, enableEPSS: true},
user: {
currentSettings,
renewSession,
Expand Down Expand Up @@ -419,7 +419,7 @@ describe('Nvt Detailspage tests', () => {
overrides: {
get: getEntities,
},
settings: {manualUrl, reloadInterval},
settings: {manualUrl, reloadInterval, enableEPSS: true},
user: {
currentSettings,
renewSession,
Expand Down Expand Up @@ -455,7 +455,7 @@ describe('Nvt ToolBarIcons tests', () => {
const handleOnNoteCreateClick = testing.fn();
const handleOnOverrideCreateClick = testing.fn();

const gmp = {settings: {manualUrl}};
const gmp = {settings: {manualUrl, enableEPSS: true}};

const {render} = rendererWith({
gmp,
Expand Down Expand Up @@ -502,7 +502,7 @@ describe('Nvt ToolBarIcons tests', () => {
const handleOnNoteCreateClick = testing.fn();
const handleOnOverrideCreateClick = testing.fn();

const gmp = {settings: {manualUrl}};
const gmp = {settings: {manualUrl, enableEPSS: true}};

const {render} = rendererWith({
gmp,
Expand Down
4 changes: 2 additions & 2 deletions src/web/pages/nvts/__tests__/listpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('NvtsPage tests', () => {
filters: {
get: getFilters,
},
settings: {manualUrl, reloadInterval},
settings: {manualUrl, reloadInterval, enableEPSS: true},
user: {currentSettings, getSetting},
};

Expand Down Expand Up @@ -238,7 +238,7 @@ describe('NvtsPage tests', () => {
filters: {
get: getFilters,
},
settings: {manualUrl, reloadInterval},
settings: {manualUrl, reloadInterval, enableEPSS: true},
user: {renewSession, currentSettings, getSetting: getSetting},
};

Expand Down
6 changes: 4 additions & 2 deletions src/web/pages/nvts/details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {isDefined, isNumber} from 'gmp/utils/identity';
import {TAG_NA} from 'gmp/models/nvt';

import PropTypes from 'web/utils/proptypes';
import useGmp from "web/utils/useGmp.jsx";

import {na, getTranslatableSeverityOrigin} from 'web/utils/render';

Expand Down Expand Up @@ -45,6 +46,7 @@ const NvtDetails = ({entity, links = true}) => {
severityOrigin,
severityDate,
} = entity;
const gmp = useGmp();
return (
<Layout flex="column" grow="1">
{entity.isDeprecated() && <div>{_('This NVT is deprecated.')}</div>}
Expand Down Expand Up @@ -97,7 +99,7 @@ const NvtDetails = ({entity, links = true}) => {
)}
</TableData>
</TableRow>
{ isDefined(epss?.max_severity) &&
{ gmp.settings.enableEPSS && isDefined(epss?.max_severity) &&
<>
<TableData colSpan="2">
<b>{_('EPSS (CVE with highest severity)')}</b>
Expand Down Expand Up @@ -133,7 +135,7 @@ const NvtDetails = ({entity, links = true}) => {
</TableRow>
</>
}
{ isDefined(epss?.max_epss) &&
{ gmp.settings.enableEPSS && isDefined(epss?.max_epss) &&
<>
<TableData colSpan="2">
<b>{_('EPSS (highest EPSS score)')}</b>
Expand Down
23 changes: 15 additions & 8 deletions src/web/pages/nvts/row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import EntitiesActions from 'web/entities/actions';
import {RowDetailsToggle} from 'web/entities/row';

import PropTypes from 'web/utils/proptypes';
import useGmp from "web/utils/useGmp.jsx";
import {_} from "gmp/locale/lang.js";

const Row = ({
Expand All @@ -40,6 +41,7 @@ const Row = ({
onToggleDetailsClick,
...props
}) => {
const gmp = useGmp();
const handleFilterChanged = () => {
const filter = Filter.fromString('family="' + entity.family + '"');
onFilterChanged(filter);
Expand Down Expand Up @@ -90,14 +92,19 @@ const Row = ({
<TableData align="end">
{entity.qod && <Qod value={entity.qod.value} />}
</TableData>
<TableData>
{isNumber(entity?.epss?.max_severity?.score)
? entity.epss?.max_severity?.score.toFixed(5) : _("N/A")}
</TableData>
<TableData>
{isNumber(entity?.epss?.max_severity?.percentile)
? entity.epss?.max_severity?.percentile.toFixed(5) : _("N/A")}
</TableData>
{
gmp.settings.enableEPSS &&
<>
<TableData>
{isNumber(entity?.epss?.max_severity?.score)
? entity.epss?.max_severity?.score.toFixed(5) : _("N/A")}
</TableData>
<TableData>
{isNumber(entity?.epss?.max_severity?.percentile)
? entity.epss?.max_severity?.percentile.toFixed(5) : _("N/A")}
</TableData>
</>
}
<ActionsComponent {...props} entity={entity} />
</TableRow>
);
Expand Down
Loading

0 comments on commit a0042e4

Please sign in to comment.