Skip to content

Commit 470c021

Browse files
committed
feat: sort by severity on post-release
1 parent 89d5a87 commit 470c021

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎lib/security_blog.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
import auth from './auth.js';
1515
import Request from './request.js';
1616

17+
const SEVERITY_ORDER = ['critical', 'high', 'medium', 'low'];
18+
1719
export default class SecurityBlog extends SecurityRelease {
1820
req;
1921

@@ -256,7 +258,8 @@ export default class SecurityBlog extends SecurityRelease {
256258
}
257259

258260
async getReportsTemplate(content) {
259-
const reports = content.reports;
261+
const reports = [...content.reports].sort((a, b) =>
262+
this.getSeverityOrder(a) - this.getSeverityOrder(b));
260263
let template = '';
261264
for (const report of reports) {
262265
const cveId = report.cveIds?.join(', ');
@@ -282,6 +285,13 @@ export default class SecurityBlog extends SecurityRelease {
282285
return template;
283286
}
284287

288+
getSeverityOrder(report) {
289+
const rating = report.severity?.rating?.toLowerCase();
290+
const index = SEVERITY_ORDER.indexOf(rating);
291+
if (index === -1) return SEVERITY_ORDER.length;
292+
return index;
293+
}
294+
285295
getDependencyUpdatesTemplate(dependencyUpdates) {
286296
if (typeof dependencyUpdates !== 'object') return '';
287297
if (Object.keys(dependencyUpdates).length === 0) return '';

‎test/unit/security_release.test.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,31 @@ describe('security_blog: post-release severity wording', () => {
301301
assert.throws(() => blog.getVulnerabilities(content), /severity\.rating not found for report 1/);
302302
});
303303

304+
it('sorts post-release reports by severity', async() => {
305+
const blog = new SecurityBlog();
306+
const createReport = (title, rating) => ({
307+
title,
308+
cveIds: [`CVE-2026-${title}`],
309+
severity: { rating },
310+
summary: 'summary',
311+
affectedVersions: ['24.x'],
312+
patchAuthors: ['nodejs'],
313+
reporter: 'reporter',
314+
link: `https://hackerone.com/reports/${title}`
315+
});
316+
317+
const output = await blog.getReportsTemplate({
318+
reports: [
319+
createReport('low-report', 'low'),
320+
createReport('high-report', 'high'),
321+
createReport('medium-report', 'medium')
322+
]
323+
});
324+
325+
assert.ok(output.indexOf('## high-report') < output.indexOf('## medium-report'));
326+
assert.ok(output.indexOf('## medium-report') < output.indexOf('## low-report'));
327+
});
328+
304329
it('formats dependency update object versions', () => {
305330
const blog = new SecurityBlog();
306331

0 commit comments

Comments
 (0)