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

feat(vulnerabilities): handle medium and unknown severities #22257

Merged
merged 8 commits into from May 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/util/template/index.ts
Expand Up @@ -145,7 +145,7 @@ export const allowedFields = {
versioning: 'The versioning scheme in use',
versions: 'An array of ChangeLogRelease objects in the upgrade',
vulnerabilitySeverity:
'The severity for a vulnerability alert upgrade (eg: LOW, MODERATE, HIGH, CRITICAL)',
'The severity for a vulnerability alert upgrade (LOW, MEDIUM, MODERATE, HIGH, CRITICAL, UNKNOWN)',
};

const prBodyFields = [
Expand Down
28 changes: 28 additions & 0 deletions lib/util/vulnerability/utils.spec.ts
Expand Up @@ -85,6 +85,20 @@ describe('util/vulnerability/utils', () => {
expect(severity).toBe('MODERATE');
});

it('child MEDIUM vulnerability severity rating is maintained', () => {
const parentConfig = {
vulnerabilitySeverity: 'LOW',
};

const childConfig = {
vulnerabilitySeverity: 'MEDIUM',
};

const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig);

expect(severity).toBe('MEDIUM');
});

it('parent LOW vulnerability severity rating is maintained', () => {
const parentConfig = {
vulnerabilitySeverity: 'LOW',
Expand Down Expand Up @@ -113,6 +127,20 @@ describe('util/vulnerability/utils', () => {
expect(severity).toBe('LOW');
});

it('child UNKNOWN vulnerability severity rating is maintained', () => {
const parentConfig = {
vulnerabilitySeverity: 'CRITICAL',
};

const childConfig = {
vulnerabilitySeverity: 'UNKNOWN',
};

const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig);

expect(severity).toBe('UNKNOWN');
});

it('handled undefined parent and child vulnerability severity', () => {
const parentConfig = {
vulnerabilitySeverity: undefined,
Expand Down
2 changes: 2 additions & 0 deletions lib/util/vulnerability/utils.ts
@@ -1,8 +1,10 @@
const severityOrder: Record<string, number> = {
LOW: 1,
MEDIUM: 2,
MODERATE: 2,
HIGH: 3,
CRITICAL: 4,
UNKNOWN: 5,
};

export function getHighestVulnerabilitySeverity<
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/process/types.ts
Expand Up @@ -21,5 +21,5 @@ export interface DependencyVulnerabilities {
export interface SeverityDetails {
cvssVector: string;
score: string;
severityLevel?: string;
severityLevel: string;
}
9 changes: 4 additions & 5 deletions lib/workers/repository/process/vulnerabilities.ts
Expand Up @@ -532,10 +532,8 @@ export class Vulnerabilities {
if (severityDetails.cvssVector) {
content += `- CVSS Score: ${severityDetails.score}\n`;
content += `- Vector String: \`${severityDetails.cvssVector}\`\n`;
} else if (severityDetails.severityLevel) {
content += `${severityDetails.severityLevel}\n`;
} else {
content += 'Unknown severity.\n';
content += `${severityDetails.severityLevel}\n`;
}

content += `\n#### References\n${
Expand Down Expand Up @@ -566,8 +564,8 @@ export class Vulnerabilities {
vulnerability: Osv.Vulnerability,
affected: Osv.Affected
): SeverityDetails {
let severityLevel: string | undefined;
let score = 'Unknown';
let severityLevel = 'UNKNOWN';
let score = 'Unknown severity';

const cvssVector =
vulnerability.severity?.find((e) => e.type === 'CVSS_V3')?.score ??
Expand All @@ -585,6 +583,7 @@ export class Vulnerabilities {
const severity = vulnerability.database_specific.severity as string;
severityLevel =
severity.charAt(0).toUpperCase() + severity.slice(1).toLowerCase();
score = severityLevel;
}

return {
Expand Down