Skip to content
Merged
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
14 changes: 14 additions & 0 deletions lib/modules/platform/github/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4762,12 +4762,14 @@ describe('modules/platform/github/index', () => {
description: 'description',
identifiers: [{ type: 'type', value: 'value' }],
references: [],
severity: 'high',
},
security_vulnerability: {
package: {
ecosystem: 'npm',
name: 'left-pad',
},
severity: 'high',
vulnerable_version_range: '0.0.2',
first_patched_version: { identifier: '0.0.3' },
},
Expand All @@ -4780,6 +4782,7 @@ describe('modules/platform/github/index', () => {
description: 'description',
identifiers: [{ type: 'type', value: 'value' }],
references: [],
severity: 'high',
},
security_vulnerability: null,
dependency: {
Expand Down Expand Up @@ -4833,12 +4836,14 @@ describe('modules/platform/github/index', () => {
description: 'description',
identifiers: [{ type: 'type', value: 'value' }],
references: [],
severity: 'high',
},
security_vulnerability: {
package: {
ecosystem: 'npm',
name: 'left-pad',
},
severity: 'high',
vulnerable_version_range: '0.0.2',
first_patched_version: { identifier: '0.0.3' },
},
Expand All @@ -4852,6 +4857,7 @@ describe('modules/platform/github/index', () => {
description: 'description',
identifiers: [{ type: 'type', value: 'value' }],
references: [],
severity: 'high',
},
security_vulnerability: null,
dependency: {
Expand Down Expand Up @@ -4882,12 +4888,14 @@ describe('modules/platform/github/index', () => {
description: 'description',
identifiers: [{ type: 'type', value: 'value' }],
references: [],
severity: 'medium',
},
security_vulnerability: {
package: {
ecosystem: 'pip',
name: 'FrIeNdLy.-.BARD',
},
severity: 'medium',
vulnerable_version_range: '0.0.2',
first_patched_version: { identifier: '0.0.3' },
},
Expand Down Expand Up @@ -4917,12 +4925,14 @@ describe('modules/platform/github/index', () => {
description: 'description',
identifiers: [{ type: 'type', value: 'value' }],
references: [],
severity: 'high',
},
security_vulnerability: {
package: {
ecosystem: 'npm',
name: 'left-pad',
},
severity: 'high',
vulnerable_version_range: '0.0.2',
first_patched_version: { identifier: '0.0.3' },
},
Expand All @@ -4935,12 +4945,14 @@ describe('modules/platform/github/index', () => {
description: 'description',
identifiers: [{ type: 'type', value: 'value' }],
references: [],
severity: 'critical',
},
security_vulnerability: {
package: {
ecosystem: 'npm',
name: 'right-pad',
},
severity: 'critical',
vulnerable_version_range: '0.0.1',
first_patched_version: { identifier: '0.0.2' },
},
Expand All @@ -4962,12 +4974,14 @@ describe('modules/platform/github/index', () => {
description: 'description',
identifiers: [{ type: 'type', value: 'value' }],
references: [],
severity: 'low',
},
security_vulnerability: {
package: {
ecosystem: 'npm',
name: 'center-pad',
},
severity: 'low',
vulnerable_version_range: '0.0.3',
first_patched_version: { identifier: '0.0.4' },
},
Expand Down
43 changes: 43 additions & 0 deletions lib/modules/platform/github/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ describe('modules/platform/github/schema', () => {
security_advisory: {
description: 'Test advisory',
identifiers: [{ type: 'CVE', value: 'CVE-2024-1234' }],
severity: 'high',
},
security_vulnerability: {
first_patched_version: { identifier: '1.0.0' },
package: { ecosystem: 'dotnet', name: 'test-package' },
severity: 'high',
vulnerable_version_range: '< 1.0.0',
},
dependency: { manifest_path: 'package.json' },
Expand All @@ -128,10 +130,12 @@ describe('modules/platform/github/schema', () => {
security_advisory: {
description: 'Test advisory',
identifiers: [{ type: 'CVE', value: 'CVE-2024-5678' }],
severity: 'medium',
},
security_vulnerability: {
first_patched_version: { identifier: '2.0.0' },
package: { ecosystem: 'npm', name: 'valid-package' },
severity: 'medium',
vulnerable_version_range: '< 2.0.0',
},
dependency: { manifest_path: 'package.json' },
Expand All @@ -148,10 +152,12 @@ describe('modules/platform/github/schema', () => {
security_advisory: {
description: 'Test advisory',
identifiers: [{ type: 'CVE', value: 'CVE-2024-1234' }],
severity: 'high',
},
security_vulnerability: {
first_patched_version: { identifier: '1.0.0' },
package: { ecosystem: 'dotnet', name: 'test-package' },
severity: 'high',
vulnerable_version_range: '< 1.0.0',
},
},
Expand All @@ -173,6 +179,7 @@ describe('modules/platform/github/schema', () => {
security_advisory: {
description: 'Test advisory',
identifiers: [{ type: 'CVE', value: 'CVE-2024-5678' }],
severity: 'high',
},
security_vulnerability: null,
dependency: { manifest_path: 'package.json' },
Expand All @@ -187,4 +194,40 @@ describe('modules/platform/github/schema', () => {
'Vulnerability Alert: Failed to parse some alerts',
);
});

it('should parse severity and cvss_severities fields', () => {
const result = GithubVulnerabilityAlerts.parse([
{
dismissed_reason: null,
security_advisory: {
description: 'Test advisory',
identifiers: [{ type: 'CVE', value: 'CVE-2024-1234' }],
severity: 'high',
cvss_severities: {
cvss_v3: {
vector_string: 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H',
score: 9.8,
},
cvss_v4: null,
},
},
security_vulnerability: {
first_patched_version: { identifier: '2.0.0' },
package: { ecosystem: 'npm', name: 'test-package' },
severity: 'critical',
vulnerable_version_range: '< 2.0.0',
},
dependency: { manifest_path: 'package.json' },
},
]);

expect(result).toHaveLength(1);
expect(result[0].security_advisory.severity).toBe('high');
expect(result[0].security_vulnerability?.severity).toBe('critical');
expect(result[0].security_advisory.cvss_severities?.cvss_v3).toEqual({
vector_string: 'CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H',
score: 9.8,
});
expect(result[0].security_advisory.cvss_severities?.cvss_v4).toBeNull();
});
});
15 changes: 15 additions & 0 deletions lib/modules/platform/github/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ const Package = z.object({
name: z.string(),
});

const Severity = z.enum(['low', 'medium', 'high', 'critical']);

const SecurityVulnerability = z
.object({
first_patched_version: z.object({ identifier: z.string() }).nullish(),
package: Package,
severity: Severity,
Comment thread
viceice marked this conversation as resolved.
vulnerable_version_range: z.string(),
})
.nullable();

const CvssSeverity = z.object({
vector_string: z.string().nullable(),
score: z.number().nullable(),
});

const SecurityAdvisory = z.object({
description: z.string(),
identifiers: z.array(
Expand All @@ -43,6 +51,13 @@ const SecurityAdvisory = z.object({
}),
),
references: z.array(z.object({ url: z.string() })).optional(),
severity: Severity,
Comment thread
viceice marked this conversation as resolved.
cvss_severities: z
.object({
cvss_v3: CvssSeverity.nullish(),
cvss_v4: CvssSeverity.nullish(),
})
.nullish(),
});
export type SecurityAdvisory = z.infer<typeof SecurityAdvisory>;

Expand Down
Loading
Loading