@node-core/utils 5.8.0 → 5.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -363,8 +363,14 @@ export default class ReleasePreparation extends Session {
363
363
  try {
364
364
  runSync('git', ['rev-parse', tagName]);
365
365
  } catch {
366
- this.cli.startSpinner(`Error parsing git ref ${tagName}, attempting fetching it as a tag`);
367
- runSync('git', ['fetch', this.upstream, 'tag', '-n', tagName]);
366
+ this.cli.error(`Error parsing git ref ${tagName}`);
367
+ this.cli.startSpinner('Attempting fetching it as a tag\n');
368
+ try {
369
+ runSync('git', ['fetch', this.upstream, 'tag', '-n', tagName]);
370
+ } catch (e) {
371
+ this.cli.error(`${e.message}\nRun: git remote update`);
372
+ process.exit(1);
373
+ }
368
374
  this.cli.stopSpinner(`Tag fetched: ${tagName}`);
369
375
  }
370
376
  try {
@@ -765,7 +771,7 @@ export default class ReleasePreparation extends Session {
765
771
  }
766
772
 
767
773
  async prepareLocalBranch() {
768
- const { cli } = this;
774
+ const { cli, isSecurityRelease } = this;
769
775
  if (this.newVersion) {
770
776
  // If the CLI asked for a specific version:
771
777
  const newVersion = semver.parse(this.newVersion);
@@ -789,11 +795,19 @@ export default class ReleasePreparation extends Session {
789
795
  // Otherwise, we need to figure out what's the next version number for the
790
796
  // release line of the branch that's currently checked out.
791
797
  const currentBranch = this.getCurrentBranch();
792
- const match = /^v(\d+)\.x-staging$/.exec(currentBranch);
793
798
 
799
+ // In security releases vN.x branch is the base
800
+ let regex = /^v(\d+)\.x-staging$/;
801
+ let targetBranch = 'vN.x-staging';
802
+ if (isSecurityRelease) {
803
+ regex = /^v(\d+)\.x$/;
804
+ targetBranch = 'vN.x';
805
+ }
806
+
807
+ const match = regex.exec(currentBranch);
794
808
  if (!match) {
795
809
  cli.warn(`Cannot prepare a release from ${currentBranch
796
- }. Switch to a staging branch before proceeding.`);
810
+ }. Switch to a ${targetBranch} branch before proceeding.`);
797
811
  return;
798
812
  }
799
813
  this.stagingBranch = currentBranch;
@@ -131,6 +131,7 @@ export default class ReleasePromotion extends Session {
131
131
  throw new Error('Aborted');
132
132
  }
133
133
  await this.secureTagRelease();
134
+ await this.verifyTagSignature();
134
135
 
135
136
  // Set up for next release.
136
137
  cli.startSpinner('Setting up for next release');
@@ -223,6 +224,28 @@ export default class ReleasePromotion extends Session {
223
224
  this.isLTS ? '=false' : ''} --title=${JSON.stringify(this.releaseTitle)} --notes-file -`);
224
225
  }
225
226
 
227
+ async verifyTagSignature() {
228
+ const { cli, version } = this;
229
+ const [needle, haystack] = await Promise.all([forceRunAsync(
230
+ 'git', ['--no-pager',
231
+ 'log', '-1',
232
+ `refs/tags/v${version}`,
233
+ '--format=* **%an** <<%ae>>\n `%GF`'
234
+ ], { captureStdout: true }), fs.readFile('README.md')]);
235
+ if (haystack.includes(needle)) {
236
+ return;
237
+ }
238
+ cli.warn('Tag was signed with an undocumented identity/key pair!');
239
+ cli.info('Expected to find the following entry in the README:');
240
+ cli.info(needle);
241
+ cli.info('If you are using a subkey, it might be OK.');
242
+ cli.info(`Otherwise consider removing the tag (git tag -d v${version
243
+ }), check your local config, and start the process over.`);
244
+ if (!await cli.prompt('Do you want to proceed anyway?', { defaultAnswer: false })) {
245
+ throw new Error('Aborted');
246
+ }
247
+ }
248
+
226
249
  async verifyPRAttributes() {
227
250
  const { cli, prid, owner, repo, req } = this;
228
251
 
@@ -47,7 +47,7 @@ export default class SecurityBlog extends SecurityRelease {
47
47
  const fileNameExt = fileName + '.md';
48
48
  const preRelease = this.buildPreRelease(template, data);
49
49
 
50
- const pathToBlogPosts = 'apps/site/pages/en/blog/release';
50
+ const pathToBlogPosts = 'apps/site/pages/en/blog/vulnerability';
51
51
  const pathToBannerJson = 'apps/site/site.json';
52
52
 
53
53
  const file = path.resolve(process.cwd(), nodejsOrgFolder, pathToBlogPosts, fileNameExt);
@@ -161,7 +161,7 @@ export default class SecurityBlog extends SecurityRelease {
161
161
  link: content.link ?? currentValue.link,
162
162
  type: content.type ?? currentValue.type
163
163
  };
164
- fs.writeFileSync(siteJsonPath, JSON.stringify(siteJson, null, 2));
164
+ fs.writeFileSync(siteJsonPath, JSON.stringify(siteJson, null, 2) + '\n');
165
165
  }
166
166
 
167
167
  formatReleaseDate(releaseDate) {
@@ -299,34 +299,37 @@ export default class SecurityBlog extends SecurityRelease {
299
299
  }
300
300
 
301
301
  getImpact(content) {
302
- const impact = content.reports.reduce((acc, report) => {
303
- for (const affectedVersion of report.affectedVersions) {
304
- if (acc[affectedVersion]) {
305
- acc[affectedVersion].push(report);
306
- } else {
307
- acc[affectedVersion] = [report];
308
- }
302
+ const impact = new Map();
303
+ for (const report of content.reports) {
304
+ for (const version of report.affectedVersions) {
305
+ if (!impact.has(version)) impact.set(version, []);
306
+ impact.get(version).push(report);
309
307
  }
310
- return acc;
311
- }, {});
312
-
313
- const impactText = [];
314
- for (const [key, value] of Object.entries(impact)) {
315
- const groupedByRating = Object.values(_.groupBy(value, 'severity.rating'))
316
- .map(severity => {
317
- if (!severity[0]?.severity?.rating) {
318
- this.cli.error(`severity.rating not found for the report ${severity[0].id}. \
319
- Please add it manually before continuing.`);
308
+ }
309
+
310
+ const result = Array.from(impact.entries())
311
+ .sort(([a], [b]) => b.localeCompare(a)) // DESC
312
+ .map(([version, reports]) => {
313
+ const severityCount = new Map();
314
+
315
+ for (const report of reports) {
316
+ const rating = report.severity.rating?.toLowerCase();
317
+ if (!rating) {
318
+ this.cli.error(`severity.rating not found for report ${report.id}.`);
320
319
  process.exit(1);
321
320
  }
322
- const firstSeverityRating = severity[0].severity.rating.toLocaleLowerCase();
323
- return `${severity.length} ${firstSeverityRating} severity issues`;
324
- }).join(', ');
321
+ severityCount.set(rating, (severityCount.get(rating) || 0) + 1);
322
+ }
325
323
 
326
- impactText.push(`The ${key} release line of Node.js is vulnerable to ${groupedByRating}.`);
327
- }
324
+ const groupedByRating = Array.from(severityCount.entries())
325
+ .map(([rating, count]) => `${count} ${rating} severity issues`)
326
+ .join(', ');
327
+
328
+ return `The ${version} release line of Node.js is vulnerable to ${groupedByRating}.`;
329
+ })
330
+ .join('\n');
328
331
 
329
- return impactText.join('\n');
332
+ return result;
330
333
  }
331
334
 
332
335
  getVulnerabilities(content) {
@@ -226,8 +226,11 @@ Summary: ${summary}\n`,
226
226
  vectorString: cvss_vector_string
227
227
  }
228
228
  ],
229
+ auto_submit_on_publicly_disclosing_report: true,
230
+ references: ['https://nodejs.org/en/blog/vulnerability'],
231
+ report_id: report.id,
229
232
  weakness_id: Number(weakness_id),
230
- description: title,
233
+ description: report.summary,
231
234
  vulnerability_discovered_at: new Date().toISOString()
232
235
  }
233
236
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-core/utils",
3
- "version": "5.8.0",
3
+ "version": "5.9.0",
4
4
  "description": "Utilities for Node.js core collaborators",
5
5
  "type": "module",
6
6
  "engines": {
@@ -40,7 +40,7 @@
40
40
  "@pkgjs/nv": "^0.2.2",
41
41
  "branch-diff": "^3.1.1",
42
42
  "chalk": "^5.3.0",
43
- "changelog-maker": "^4.1.1",
43
+ "changelog-maker": "^4.3.1",
44
44
  "cheerio": "^1.0.0",
45
45
  "clipboardy": "^4.0.0",
46
46
  "core-validate-commit": "^4.1.0",