cve-lite-cli 1.34.0 → 1.36.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.
Files changed (42) hide show
  1. package/README.md +34 -0
  2. package/dist/cli/advisories-init.js +13 -0
  3. package/dist/cli/advisories-sync.js +30 -0
  4. package/dist/cli/config-command.js +15 -0
  5. package/dist/cli/config.js +29 -0
  6. package/dist/cli/help.js +4 -4
  7. package/dist/cli/overrides.js +10 -1
  8. package/dist/constants.js +52 -0
  9. package/dist/index.js +25 -719
  10. package/dist/osv/cache.js +19 -12
  11. package/dist/output/cyclonedx.js +12 -0
  12. package/dist/output/html-reporter.js +73 -38
  13. package/dist/output/multi-folder-html-reporter.js +16 -10
  14. package/dist/output/multi-folder-printer.js +1 -1
  15. package/dist/output/override-findings-sarif.js +1 -0
  16. package/dist/output/printers.js +460 -288
  17. package/dist/output/sarif.js +17 -1
  18. package/dist/output/sbom-dependency-edges.js +29 -19
  19. package/dist/overrides/admitted-scan.js +158 -0
  20. package/dist/overrides/api.js +16 -0
  21. package/dist/overrides/context-builder.js +4 -0
  22. package/dist/overrides/context.js +8 -1
  23. package/dist/overrides/detectors/index.js +2 -0
  24. package/dist/overrides/detectors/oa010-vulnerable-floor.js +123 -0
  25. package/dist/overrides/parsing/registry.js +53 -0
  26. package/dist/parsers/bun-lock-graph.js +182 -0
  27. package/dist/parsers/bun-lock.js +93 -132
  28. package/dist/parsers/index.js +132 -147
  29. package/dist/parsers/multi-package.js +5 -6
  30. package/dist/parsers/pnpm-lock-graph.js +94 -0
  31. package/dist/parsers/pnpm-lock.js +5 -5
  32. package/dist/parsers/yarn-lock-graph.js +148 -0
  33. package/dist/parsers/yarn-lock.js +3 -3
  34. package/dist/remediation/fix-commands.js +76 -20
  35. package/dist/scan/completeness.js +1 -1
  36. package/dist/scan/single-scan.js +643 -0
  37. package/dist/scanner.js +29 -8
  38. package/dist/utils/file.js +11 -14
  39. package/dist/utils/network.js +4 -0
  40. package/dist/utils/version.js +10 -0
  41. package/package.json +2 -1
  42. package/scripts/pr-scan-delta.mjs +315 -0
@@ -1,9 +1,10 @@
1
1
  import { chalk, stripAnsi } from "../utils/chalk.js";
2
- import { buildSuggestedFixCommandPlan, UNVERIFIED_PARENT_UPGRADE_NOTE } from "../remediation/fix-commands.js";
2
+ import { buildSuggestedFixCommandPlan, findFixTargetForFinding, UNVERIFIED_PARENT_UPGRADE_NOTE } from "../remediation/fix-commands.js";
3
3
  import { isBreakingUpgrade } from "../utils/version.js";
4
4
  import { getPrimaryParent } from "../utils/finding.js";
5
5
  import { countUniqueAdvisories, countProdFindings, formatRelationshipLabel, formatRelLabel, formatRootDependencySummary, formatFixCommandWithPublishDates, formatCooldownWarning, } from "./formatters.js";
6
6
  import { formatSeverityLabel } from "../utils/severity.js";
7
+ import { severityOrder } from "../constants.js";
7
8
  import { pluralize } from "../utils/string.js";
8
9
  import { hasMaliciousAdvisory } from "../utils/vuln.js";
9
10
  import { selectFindingsForCompact } from "./finding-display.js";
@@ -75,68 +76,38 @@ function printUnverifiedParentUpgradeWarning(target) {
75
76
  console.log(chalk.yellow(` ${UNVERIFIED_PARENT_UPGRADE_NOTE}`));
76
77
  }
77
78
  }
78
- function printChainProofLines(targets) {
79
- for (const target of targets) {
80
- if (!target.chainProof || !target.chainSafeVersion)
81
- continue;
82
- const pkgLabel = target.chainVulnerablePackage
83
- ? `${target.chainVulnerablePackage}@${target.chainSafeVersion}`
84
- : target.chainSafeVersion;
85
- const hops = target.chainProof.map(h => `${h.name}@${h.version}`);
86
- const proof = hops.length > 0
87
- ? ` resolves via ${hops.join(" -> ")} -> ${pkgLabel} (safe)`
88
- : ` resolves to ${pkgLabel} (safe)`;
89
- console.log(chalk.gray(proof));
90
- }
91
- }
92
79
  export function printSuggestedFixCommands(findings, scanInput, options) {
93
80
  const plan = buildSuggestedFixCommandPlan(findings, scanInput, options);
94
81
  if (!plan)
95
82
  return;
83
+ const fixRowContexts = buildFixRowContexts(findings);
96
84
  if (plan.sections.length === 0)
97
85
  return;
98
- const sharedDirectTableWidths = computeSharedDirectTableWidths(plan.sections);
99
- const sharedParentUpgradeTableWidths = computeSharedParentUpgradeTableWidths(plan.sections);
86
+ // One decision for every fix table in the run, so sections that share widths
87
+ // cannot disagree about whether the Usage column exists.
88
+ const showUsage = findings.some(finding => !!finding.usage);
89
+ const sharedActionTableWidths = computeSharedActionTableWidths(plan.sections, showUsage, fixRowContexts);
100
90
  console.log("");
101
91
  console.log(chalk.bold.yellow("🛠 Suggested Fix Commands"));
102
92
  console.log(chalk.white(formatFixCommandSummary(plan)));
103
93
  for (const section of plan.sections) {
104
94
  console.log("");
105
95
  console.log(colorFixSectionTitle(section.severity, section.title));
106
- if (section.kind === "direct" || section.kind === "direct-adjusted") {
107
- const validationSummary = summarizeAdjustedValidation(section.targets);
108
- const remainingNotes = [];
109
- printDirectTargetsTable(section.targets, remainingNotes, validationSummary, sharedDirectTableWidths);
110
- for (const note of remainingNotes) {
111
- console.log(chalk.gray(` Note: ${note}`));
112
- }
113
- }
114
- else if (section.kind === "urgent") {
115
- const directTargets = section.targets.filter(t => t.kind === "direct");
116
- const parentUpgradeTargets = section.targets.filter(t => t.kind === "parent-upgrade" || t.kind === "parent-update");
117
- if (directTargets.length > 0) {
118
- const validationSummary = summarizeAdjustedValidation(directTargets);
119
- const remainingNotes = [];
120
- // Urgent sections compute their own widths so the Breaking? column
121
- // is not truncated by widths derived from smaller non-urgent sections.
122
- printDirectTargetsTable(directTargets, remainingNotes, validationSummary, undefined);
123
- for (const note of remainingNotes) {
124
- console.log(chalk.gray(` Note: ${note}`));
125
- }
126
- }
127
- if (parentUpgradeTargets.length > 0) {
128
- printParentUpgradeTargetsTable(parentUpgradeTargets, undefined);
129
- }
130
- }
131
- else if (shouldRenderParentUpgradeTable(section.targets)) {
132
- printParentUpgradeTargetsTable(section.targets, sharedParentUpgradeTableWidths);
96
+ // One table per section, always, holding every target the section covers.
97
+ // Direct and parent upgrades used to go in separately shaped tables chosen by
98
+ // section kind, which is why the same title drew a 7-column table in one
99
+ // project and a 4-column one in another, and why a section whose targets
100
+ // matched neither shape drew no table at all.
101
+ const remainingNotes = [];
102
+ printActionTargetsTable(section.targets, remainingNotes, sharedActionTableWidths, fixRowContexts, showUsage);
103
+ for (const note of remainingNotes) {
104
+ console.log(chalk.gray(` Note: ${note}`));
133
105
  }
134
106
  for (const target of section.targets) {
135
107
  printCooldownWarning(target);
136
108
  printUnverifiedParentUpgradeWarning(target);
137
109
  }
138
110
  console.log(renderCommandCallout(section.command, section.targets));
139
- printChainProofLines(section.targets);
140
111
  }
141
112
  if (plan.coveredFindingCount > 0) {
142
113
  console.log("");
@@ -211,89 +182,293 @@ function formatPrioritySignal(signal) {
211
182
  return chalk.blue(label);
212
183
  return chalk.gray(label);
213
184
  }
214
- export function printTable(findings, threshold, skippedKeys) {
215
- const headers = ["Package", "Version", "Severity", "Type", "Root", "Usage", "Fixed", "EPSS", "EPSS Priority", "IDs"];
216
- const rowSignals = [];
217
- const rawRows = findings.map(f => {
218
- let usageText = "n/a";
219
- if (f.usage) {
220
- usageText = f.usage.imported ? `${f.usage.files.length} file(s)` : "unused";
221
- }
222
- const isSkipped = skippedKeys?.has(`${f.pkg.name}@${f.pkg.version}`);
223
- const fixVersion = f.validatedFirstFixedVersion ?? f.firstFixedVersion;
224
- let fixedDisplay;
225
- if (isSkipped && fixVersion) {
226
- fixedDisplay = chalk.gray(`${fixVersion} ⊘`);
227
- }
228
- else if (fixVersion) {
229
- fixedDisplay = fixVersion;
230
- }
231
- else if (f.maliciousUnverifiable) {
232
- fixedDisplay = chalk.yellow("⚠ Unverifiable (private source)");
233
- }
234
- else if (f.maliciousGitSource) {
235
- fixedDisplay = chalk.yellow(f.maliciousGitSourcePinned ? MAL_GIT_SOURCE_PINNED_DISPLAY : MAL_GIT_SOURCE_FLOATING_DISPLAY);
236
- }
237
- else if (hasMaliciousAdvisory(f.vulnerabilities)) {
238
- fixedDisplay = chalk.yellow("⚠ Malicious");
239
- }
240
- else {
241
- fixedDisplay = chalk.yellow("⚠ no fix");
242
- }
243
- let epssDisplay = "-";
244
- let signal = null;
245
- if (f.epssScores && f.epssScores.length > 0) {
246
- const best = f.epssScores.slice().sort((a, b) => b.percentile - a.percentile)[0];
247
- epssDisplay = `${(best.epss * 100).toFixed(1)}%`;
248
- signal = computePrioritySignal(f.severity, f.epssScores);
249
- }
250
- rowSignals.push(signal);
251
- const priorityDisplay = signal ? PRIORITY_SIGNAL_TABLE_LABELS[signal] : "-";
252
- return [
253
- f.pkg.name,
254
- f.pkg.version,
255
- f.severity,
256
- formatRelLabel(f),
257
- formatRootDependencySummary(f),
258
- usageText,
259
- fixedDisplay,
260
- epssDisplay,
261
- priorityDisplay,
262
- f.vulnerabilities.map(v => v.id).join(", ")
263
- ];
185
+ // Package names are the only unbounded values in a table, so they are capped
186
+ // tighter than versions, counts and fixed labels.
187
+ const PACKAGE_NAME_COLUMN_CAP = 32;
188
+ const DEFAULT_COLUMN_CAP = 40;
189
+ // Root holds a package name too, but it is a secondary column, so it is capped
190
+ // below Package. 24 is a floor rather than a preference: unscoped roots such as
191
+ // "start-server-and-test +1" are themselves 24 characters with nothing to trim.
192
+ const ROOT_COLUMN_CAP = 24;
193
+ // Context is prose, so it gets room and is word-wrapped rather than truncated.
194
+ const CONTEXT_COLUMN_CAP = 60;
195
+ const dash = (value) => (value == null || value === "" ? "-" : value);
196
+ const TABLE_COLUMNS = [
197
+ {
198
+ name: "package",
199
+ header: "Package",
200
+ cap: PACKAGE_NAME_COLUMN_CAP,
201
+ cell: row => ({ value: row.package, decorated: row.packageDecorated }),
202
+ },
203
+ { name: "version", header: "Version", cell: row => ({ value: dash(row.version) }) },
204
+ {
205
+ name: "severity",
206
+ header: "Severity",
207
+ cell: row => (row.severity
208
+ ? { value: row.severity, decorated: formatSeverityLabel(row.severity) }
209
+ : { value: "-" }),
210
+ },
211
+ {
212
+ name: "type",
213
+ header: "Type",
214
+ cell: row => (row.relationship
215
+ ? { value: row.relationship, decorated: formatRelationshipLabel(row.relationship) }
216
+ : { value: "-" }),
217
+ },
218
+ {
219
+ name: "root",
220
+ header: "Root",
221
+ cap: ROOT_COLUMN_CAP,
222
+ cell: row => ({ value: dash(row.root) }),
223
+ },
224
+ {
225
+ name: "usage",
226
+ header: "Usage",
227
+ cell: row => {
228
+ if (!row.usage)
229
+ return { value: "n/a", decorated: chalk.gray("n/a") };
230
+ const value = row.usage.imported ? `${row.usage.files.length} file(s)` : "unused";
231
+ return { value, decorated: row.usage.imported ? chalk.red(value) : chalk.green(value) };
232
+ },
233
+ },
234
+ {
235
+ name: "advisory",
236
+ header: "Advisory",
237
+ cell: row => {
238
+ const value = dash(row.advisoryVersion);
239
+ return { value, decorated: chalk.gray(value) };
240
+ },
241
+ },
242
+ { name: "target", header: "Target", cell: row => ({ value: dash(row.target) }) },
243
+ {
244
+ name: "scanned",
245
+ header: "Scanned",
246
+ cell: row => {
247
+ const value = row.scanned == null ? "-" : String(row.scanned);
248
+ return { value, decorated: chalk.blue(value) };
249
+ },
250
+ },
251
+ {
252
+ name: "stillVulnerable",
253
+ header: "Still\nvulnerable",
254
+ cell: row => {
255
+ if (row.stillVulnerable == null)
256
+ return { value: "-", decorated: chalk.gray("-") };
257
+ const value = String(row.stillVulnerable);
258
+ return { value, decorated: row.stillVulnerable > 0 ? chalk.yellow(value) : chalk.green(value) };
259
+ },
260
+ },
261
+ {
262
+ name: "breaking",
263
+ header: "Breaking?",
264
+ cell: row => (row.breaking ? { value: "⚠", decorated: chalk.yellow("⚠") } : { value: "" }),
265
+ },
266
+ {
267
+ name: "epss",
268
+ header: "EPSS",
269
+ cell: row => {
270
+ const value = row.epss == null ? "-" : `${(row.epss * 100).toFixed(1)}%`;
271
+ return { value, decorated: chalk.gray(value) };
272
+ },
273
+ },
274
+ {
275
+ name: "epssPriority",
276
+ header: "EPSS\nPriority",
277
+ cell: row => ({
278
+ value: row.signal ? PRIORITY_SIGNAL_TABLE_LABELS[row.signal] : "-",
279
+ decorated: formatPrioritySignal(row.signal ?? null),
280
+ }),
281
+ },
282
+ {
283
+ name: "ids",
284
+ header: "IDs",
285
+ cell: row => ({ value: row.ids ? formatAdvisoryIdFoothold(row.ids) : "-" }),
286
+ },
287
+ {
288
+ name: "context",
289
+ header: "Context",
290
+ cap: CONTEXT_COLUMN_CAP,
291
+ wrapCap: CONTEXT_COLUMN_CAP,
292
+ cell: row => {
293
+ const value = dash(row.context);
294
+ return { value, decorated: chalk.gray(value) };
295
+ },
296
+ },
297
+ ];
298
+ /**
299
+ * The findings table is the research view: everything we know, in one place.
300
+ * The action tables are what you read to decide what to run, so they carry the
301
+ * remediation columns only. Both are selections from TABLE_COLUMNS.
302
+ */
303
+ const FINDINGS_TABLE_COLUMNS = [
304
+ "package", "version", "severity", "type", "root", "usage",
305
+ "advisory", "target", "scanned", "stillVulnerable", "breaking",
306
+ "epss", "epssPriority", "ids",
307
+ ];
308
+ // Both remediation tables draw the same columns. A direct upgrade and a parent
309
+ // upgrade are different rows, but showing them in differently shaped tables made
310
+ // the same section title render two different tables depending on the project.
311
+ const ACTION_TABLE_COLUMNS = [
312
+ "package", "version", "usage", "advisory", "target",
313
+ "scanned", "stillVulnerable", "breaking", "context",
314
+ ];
315
+ // Usage is "n/a" on every row unless --usage or --only-used ran, so it is dropped
316
+ // rather than shown empty. Keyed off the data, which cannot disagree with the rows.
317
+ const USAGE_COLUMN = "usage";
318
+ function selectColumns(names, showUsage) {
319
+ return TABLE_COLUMNS.filter(column => {
320
+ if (!names.includes(column.name))
321
+ return false;
322
+ return column.name !== USAGE_COLUMN || showUsage;
264
323
  });
265
- const widths = headers.map((header, index) => Math.min(40, Math.max(header.length, ...rawRows.map(r => stripAnsi(String(r[index])).length))));
266
- console.log("");
267
- if (threshold) {
268
- console.log(chalk.bold(`Showing ${threshold}+ findings in the main table. Use --all to show everything.`));
269
- }
324
+ }
325
+ function columnWidths(columns, rows) {
326
+ return columns.map(column => Math.min(column.cap ?? DEFAULT_COLUMN_CAP, Math.max(cellWidth(column.header), ...rows.map(row => cellWidth(column.cell(row).value)))));
327
+ }
328
+ function renderCells(columns, row) {
329
+ return columns.map(column => {
330
+ const { value, decorated } = column.cell(row);
331
+ return decorated ?? value;
332
+ });
333
+ }
334
+ /** Draws a table from a column selection. `wrap` word-wraps instead of truncating. */
335
+ function printColumnTable(columns, rows, widths, options) {
270
336
  const line = (left, mid, right) => left + widths.map(w => "─".repeat(w + 2)).join(mid) + right;
271
337
  console.log(line("┌", "┬", "┐"));
272
- console.log(renderRow(headers, widths));
338
+ console.log(renderRow(columns.map(column => column.header), widths));
273
339
  console.log(line("├", "┼", "┤"));
274
- rawRows.forEach((row, idx) => {
275
- let usageDecorated = String(row[5]);
276
- if (usageDecorated.includes("file(s)"))
277
- usageDecorated = chalk.red(usageDecorated);
278
- else if (usageDecorated.includes("unused"))
279
- usageDecorated = chalk.green(usageDecorated);
280
- else
281
- usageDecorated = chalk.gray(usageDecorated);
282
- const decorated = [
283
- row[0],
284
- row[1],
285
- formatSeverityLabel(String(row[2])),
286
- formatRelationshipLabel(String(row[3])),
287
- row[4],
288
- usageDecorated,
289
- row[6],
290
- chalk.gray(String(row[7])),
291
- formatPrioritySignal(rowSignals[idx] ?? null),
292
- row[9],
293
- ];
294
- console.log(renderRow(decorated, widths));
295
- });
340
+ for (const row of rows) {
341
+ const cells = renderCells(columns, row);
342
+ if (options?.wrap) {
343
+ for (const outputRow of renderWrappedRow(cells, widths))
344
+ console.log(outputRow);
345
+ }
346
+ else {
347
+ console.log(renderRow(cells, widths));
348
+ }
349
+ }
350
+ if (options?.totalsRow) {
351
+ console.log(line("├", "┼", "┤"));
352
+ console.log(renderRow(renderCells(columns, options.totalsRow), widths));
353
+ }
296
354
  console.log(line("└", "┴", "┘"));
355
+ }
356
+ /**
357
+ * Drops the scope from a root that would otherwise be truncated.
358
+ *
359
+ * The end of the name is what distinguishes "@angular-devkit/build-angular" from
360
+ * "@angular-devkit/build-webpack", so an ellipsis would eat the useful half. Only
361
+ * roots past the cap are shortened, which is what keeps this unambiguous: short
362
+ * scoped roots keep their scope, so "@angular/cli" and "@swc/cli" stay distinct
363
+ * rather than both collapsing to "cli".
364
+ */
365
+ function shortenRootSummary(summary) {
366
+ if (summary.length <= ROOT_COLUMN_CAP)
367
+ return summary;
368
+ const separator = summary.indexOf("/");
369
+ if (!summary.startsWith("@") || separator === -1)
370
+ return summary;
371
+ return summary.slice(separator + 1);
372
+ }
373
+ /** Highest EPSS probability across a finding's advisories, or null when unscored. */
374
+ function bestEpssScore(finding) {
375
+ if (!finding.epssScores || finding.epssScores.length === 0)
376
+ return null;
377
+ return finding.epssScores.slice().sort((a, b) => b.percentile - a.percentile)[0].epss;
378
+ }
379
+ function findingToTableRow(finding, plan, skippedKeys) {
380
+ const isSkipped = !!skippedKeys?.has(`${finding.pkg.name}@${finding.pkg.version}`);
381
+ // Prefer the version the fix plan will actually install. A package that is both
382
+ // a direct finding and the parent of other findings needs a higher version than
383
+ // its own advisory requires, and showing the lower one here contradicted the fix
384
+ // command sitting a few lines above.
385
+ const planTarget = plan ? findFixTargetForFinding(plan, finding)?.targetVersion : undefined;
386
+ const ownFixVersion = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
387
+ const fixVersion = planTarget ?? ownFixVersion ?? null;
388
+ return {
389
+ package: finding.pkg.name,
390
+ version: finding.pkg.version,
391
+ severity: finding.severity,
392
+ relationship: formatRelLabel(finding).replace(" · dev", "\n· dev"),
393
+ root: shortenRootSummary(formatRootDependencySummary(finding)),
394
+ usage: finding.usage ?? null,
395
+ advisoryVersion: finding.firstFixedVersion ?? null,
396
+ target: formatTargetDisplay(finding, fixVersion, isSkipped),
397
+ // These count the versions walked above the installed one while checking the
398
+ // advisory's hint, so they stand on their own even when the fix plan then
399
+ // raises Target higher to cover a package's children. Blanking them whenever
400
+ // that happened hid real validation on most rows of a typical scan.
401
+ scanned: finding.validatedTargetScannedVersions,
402
+ stillVulnerable: finding.validatedTargetKnownVulnerableVersions,
403
+ breaking: !!fixVersion && isBreakingUpgrade(finding.pkg.version, fixVersion),
404
+ epss: bestEpssScore(finding),
405
+ signal: finding.epssScores && finding.epssScores.length > 0
406
+ ? computePrioritySignal(finding.severity, finding.epssScores)
407
+ : null,
408
+ ids: finding.vulnerabilities.map(v => v.id),
409
+ };
410
+ }
411
+ function formatTargetDisplay(finding, fixVersion, isSkipped) {
412
+ if (isSkipped && fixVersion)
413
+ return chalk.gray(`${fixVersion} ⊘`);
414
+ if (fixVersion)
415
+ return fixVersion;
416
+ if (finding.maliciousUnverifiable)
417
+ return chalk.yellow("⚠ Unverifiable (private source)");
418
+ if (finding.maliciousGitSource) {
419
+ return chalk.yellow(finding.maliciousGitSourcePinned ? MAL_GIT_SOURCE_PINNED_DISPLAY : MAL_GIT_SOURCE_FLOATING_DISPLAY);
420
+ }
421
+ if (hasMaliciousAdvisory(finding.vulnerabilities))
422
+ return chalk.yellow("⚠ Malicious");
423
+ return chalk.yellow("⚠ no fix");
424
+ }
425
+ function fixTargetToTableRow(target, context) {
426
+ return {
427
+ package: target.package,
428
+ version: target.currentVersion ?? "-",
429
+ severity: context?.severity ?? null,
430
+ relationship: context?.relationship ?? null,
431
+ root: context?.root ?? null,
432
+ usage: target.usage ?? null,
433
+ advisoryVersion: target.advisoryVersion ?? context?.advisoryVersion ?? null,
434
+ target: chalk.cyan(target.targetVersion),
435
+ // A parent-upgrade target carries no validation counts of its own, but the
436
+ // finding it resolves does, and the action table is a filtered view of the
437
+ // findings table: the same package must read the same on both.
438
+ scanned: target.scannedVersions ?? context?.scanned ?? null,
439
+ stillVulnerable: target.knownVulnerableVersions ?? context?.stillVulnerable ?? null,
440
+ breaking: !!target.currentVersion && isBreakingUpgrade(target.currentVersion, target.targetVersion),
441
+ epss: context?.epss ?? null,
442
+ signal: context?.prioritySignal ?? null,
443
+ ids: context?.ids,
444
+ context: target.reason ?? target.adjustmentNote ?? null,
445
+ };
446
+ }
447
+ /** The bold summary row under a fix table: only the validation counts carry values. */
448
+ function validationTotalsRow(summary) {
449
+ return {
450
+ package: "Total",
451
+ packageDecorated: chalk.bold("Total"),
452
+ version: "-",
453
+ scanned: summary.checked,
454
+ stillVulnerable: summary.vulnerable,
455
+ };
456
+ }
457
+ export function printTable(findings, threshold, skippedKeys, plan) {
458
+ const columns = selectColumns(FINDINGS_TABLE_COLUMNS, findings.some(finding => !!finding.usage));
459
+ const rows = findings.map(finding => findingToTableRow(finding, plan, skippedKeys));
460
+ console.log("");
461
+ // Every other block announces itself (Quick take, Suggested Fix Commands,
462
+ // Coverage notes). This table was the only one arriving unlabelled, so it read
463
+ // as a continuation of the fix plan above it rather than its own section.
464
+ //
465
+ // The filter belongs in the title rather than on its own line: as a separate
466
+ // bold line it read as a second heading stacked under the first.
467
+ console.log(chalk.bold.magenta(`Vulnerability findings${threshold ? ` (${threshold}+)` : ""}`));
468
+ if (threshold) {
469
+ console.log(chalk.gray("Use --all to show every finding."));
470
+ }
471
+ printColumnTable(columns, rows, columnWidths(columns, rows));
297
472
  const maliciousFindings = findings.filter(f => hasMaliciousAdvisory(f.vulnerabilities));
298
473
  if (maliciousFindings.length > 0) {
299
474
  console.log("");
@@ -322,6 +497,26 @@ export function printTable(findings, threshold, skippedKeys) {
322
497
  console.log(chalk.gray("Tip: use --all to include low findings, or --min-severity high to focus only on urgent issues."));
323
498
  }
324
499
  }
500
+ /**
501
+ * Builds the one-sentence verdict both output modes close with.
502
+ *
503
+ * Compact and verbose used to construct this separately, 350 lines apart, and had
504
+ * drifted: compact reported critical+high while verbose reported every finding, so
505
+ * the same scan closed with "7 urgent issues" or "11 vulnerabilities" depending on
506
+ * the flag. Verbose's noun was wrong too - findings are vulnerable packages, and
507
+ * that scan carried 94 advisories across its 11 packages (#1168).
508
+ */
509
+ function buildScanVerdict(findingCount, critical, high) {
510
+ const urgentCount = critical + high;
511
+ const packages = `${findingCount} vulnerable ${pluralize(findingCount, "package")}`;
512
+ // Only name the severities actually present. "(0 critical, 1 high)" reads as noise.
513
+ const breakdown = [
514
+ critical > 0 ? `${critical} critical` : null,
515
+ high > 0 ? `${high} high` : null,
516
+ ].filter(Boolean).join(", ");
517
+ const urgentNote = urgentCount > 0 ? `, ${urgentCount} urgent (${breakdown})` : "";
518
+ return { text: `${packages}${urgentNote}`, urgent: urgentCount > 0 };
519
+ }
325
520
  export function printFinalStatus(findings, overrideCount = 0, completeness) {
326
521
  console.log("");
327
522
  console.log(chalk.gray("────────────────────────────────"));
@@ -346,19 +541,17 @@ export function printFinalStatus(findings, overrideCount = 0, completeness) {
346
541
  else {
347
542
  const criticalCount = findings.filter(f => f.severity === "critical").length;
348
543
  const highCount = findings.filter(f => f.severity === "high").length;
349
- const urgent = criticalCount > 0 || highCount > 0;
350
- const label = `${findings.length} ${pluralize(findings.length, "vulnerability", "vulnerabilities")}`;
544
+ const verdict = buildScanVerdict(findings.length, criticalCount, highCount);
545
+ const action = verdict.urgent ? "Start with the priority fixes above." : "Review the suggested fix plan above.";
546
+ const renderStatus = verdict.urgent ? chalk.redBright : chalk.yellow;
351
547
  if (hasDetectionGap) {
352
- const severityNote = urgent ? ` (${criticalCount} critical, ${highCount} high)` : "";
353
- const action = urgent ? "Start with the priority fixes above." : "Review the suggested fix plan above.";
354
- const renderStatus = urgent ? chalk.redBright : chalk.yellow;
355
- console.log(renderStatus(`⚠ Partial scan: ${label} found${overrideSuffix}${severityNote}. Vulnerability findings may be incomplete. ${action}`));
548
+ console.log(renderStatus(`⚠ Partial scan: ${verdict.text}${overrideSuffix}. Vulnerability findings may be incomplete. ${action}`));
356
549
  }
357
- else if (urgent) {
358
- console.log(chalk.redBright(`✖ Scan complete. ${label}${overrideSuffix} found (${criticalCount} critical, ${highCount} high). Start with the priority fixes above.`));
550
+ else if (verdict.urgent) {
551
+ console.log(chalk.redBright(`✖ Scan complete. ${verdict.text}${overrideSuffix}. ${action}`));
359
552
  }
360
553
  else {
361
- console.log(chalk.yellow(`▲ Scan complete. ${label}${overrideSuffix} found. Review the suggested fix plan above.`));
554
+ console.log(chalk.yellow(`▲ Scan complete. ${verdict.text}${overrideSuffix}. ${action}`));
362
555
  }
363
556
  }
364
557
  if (hasRemediationGap) {
@@ -369,13 +562,38 @@ export function printFinalStatus(findings, overrideCount = 0, completeness) {
369
562
  export function printOverrideHint() {
370
563
  console.log("💡 " + chalk.gray("Tip:") + " override entries detected - run with --check-overrides to audit them for stale or broken overrides.");
371
564
  }
565
+ // A cell may contain newlines, which render as extra physical lines within the
566
+ // same logical row. This is what keeps the table width bounded: a finding with
567
+ // twelve advisory IDs is twelve short lines rather than one 628-character cell
568
+ // that has to be truncated into uselessness.
569
+ // One searchable advisory ID plus a count of the rest. The full list belongs in
570
+ // --json, --sarif and the HTML report, where it is not competing for terminal
571
+ // width and each ID is a link. Joined into the table it ran to 628 characters on
572
+ // a real project, and truncated it left a single usable ID followed by a stump.
573
+ function formatAdvisoryIdFoothold(ids) {
574
+ if (ids.length === 0)
575
+ return "-";
576
+ if (ids.length === 1)
577
+ return ids[0];
578
+ return `${ids[0]} ${chalk.gray(`+${ids.length - 1}`)}`;
579
+ }
372
580
  function renderRow(cells, widths) {
373
- const formatted = cells.map((cell, i) => {
374
- const truncated = truncate(cell, widths[i]);
375
- const visible = stripAnsi(truncated);
376
- return ` ${truncated}${" ".repeat(Math.max(0, widths[i] - visible.length))} `;
377
- });
378
- return "│" + formatted.join("│") + "│";
581
+ const columnLines = cells.map(cell => String(cell).split("\n"));
582
+ const height = Math.max(1, ...columnLines.map(lines => lines.length));
583
+ const physicalLines = [];
584
+ for (let line = 0; line < height; line++) {
585
+ const formatted = columnLines.map((lines, i) => {
586
+ const truncated = truncate(lines[line] ?? "", widths[i]);
587
+ const visible = stripAnsi(truncated);
588
+ return ` ${truncated}${" ".repeat(Math.max(0, widths[i] - visible.length))} `;
589
+ });
590
+ physicalLines.push("│" + formatted.join("│") + "│");
591
+ }
592
+ return physicalLines.join("\n");
593
+ }
594
+ // Width of the longest single line in a cell, not of the whole cell.
595
+ function cellWidth(value) {
596
+ return Math.max(...String(value).split("\n").map(line => stripAnsi(line).length));
379
597
  }
380
598
  function truncate(value, width) {
381
599
  const plain = stripAnsi(value);
@@ -550,7 +768,6 @@ export function printCompactOutput(findings, scanInput, options) {
550
768
  printCooldownWarning(target);
551
769
  }
552
770
  console.log(renderCommandCallout(section.command, section.targets));
553
- printChainProofLines(section.targets);
554
771
  console.log("");
555
772
  }
556
773
  }
@@ -628,25 +845,22 @@ export function printCompactOutput(findings, scanInput, options) {
628
845
  }
629
846
  }
630
847
  if (options?.all) {
631
- printTable(findings, null);
848
+ printTable(findings, null, undefined, plan);
632
849
  }
633
850
  else {
634
851
  console.log("");
635
852
  }
636
853
  // Footer
637
- const urgentCount = counts.critical + counts.high;
854
+ const verdict = buildScanVerdict(findings.length, counts.critical, counts.high);
855
+ const renderStatus = verdict.urgent ? chalk.redBright : chalk.yellow;
638
856
  if (hasDetectionGap) {
639
- const label = urgentCount > 0
640
- ? `${urgentCount} urgent ${pluralize(urgentCount, "issue")} found`
641
- : `${findings.length} ${pluralize(findings.length, "issue")} found`;
642
- const renderStatus = urgentCount > 0 ? chalk.redBright : chalk.yellow;
643
- console.log(renderStatus(`⚠ Partial scan: ${label}. Vulnerability findings may be incomplete.`));
857
+ console.log(renderStatus(`⚠ Partial scan: ${verdict.text}. Vulnerability findings may be incomplete.`));
644
858
  }
645
- else if (urgentCount > 0) {
646
- console.log(chalk.redBright(`✖ Scan complete. ${urgentCount} urgent ${pluralize(urgentCount, "issue")} found.`));
859
+ else if (verdict.urgent) {
860
+ console.log(chalk.redBright(`✖ Scan complete. ${verdict.text}.`));
647
861
  }
648
862
  else {
649
- console.log(chalk.yellow(`▲ Scan complete. ${findings.length} ${pluralize(findings.length, "issue")} found.`));
863
+ console.log(chalk.yellow(`▲ Scan complete. ${verdict.text}.`));
650
864
  }
651
865
  printIncompleteDiagnostics(options?.completeness);
652
866
  if (hasRemediationGap) {
@@ -725,6 +939,8 @@ function formatFixCommandSummary(plan) {
725
939
  const sectionLabel = sectionCount === 1 ? "group" : "groups";
726
940
  return `${sectionCount} command ${sectionLabel} ready across ${packageCount} ${packageLabel}${severitySummary ? ` (${severitySummary})` : ""}.`;
727
941
  }
942
+ // No table carries a Published column, so the publish date rides on the command
943
+ // itself in both verbose and compact output, as it did before the column existed.
728
944
  function renderCommandCallout(command, targets) {
729
945
  const display = targets ? formatFixCommandWithPublishDates(command, targets) : command;
730
946
  return chalk.bold.cyan(`> ${display}`);
@@ -740,151 +956,107 @@ function summarizeAdjustedValidation(targets) {
740
956
  }
741
957
  return { checked, vulnerable };
742
958
  }
743
- function printDirectTargetsTable(targets, remainingNotes, validationSummary, widthsOverride) {
744
- const headers = ["Package", "Current", "Target", "Usage", "Versions scanned", "Still known vulnerable", "Breaking?"];
745
- const rows = targets.map(target => {
746
- if (target.adjustmentNote) {
747
- const isCountedVulnerabilityNote = target.scannedVersions !== null &&
748
- target.scannedVersions !== undefined &&
749
- target.adjustmentNote.includes("is still known vulnerable for");
750
- if (!isCountedVulnerabilityNote) {
751
- remainingNotes.push(target.adjustmentNote);
959
+ function buildFixRowContexts(findings) {
960
+ const byPackage = new Map();
961
+ for (const finding of findings) {
962
+ const list = byPackage.get(finding.pkg.name);
963
+ if (list)
964
+ list.push(finding);
965
+ else
966
+ byPackage.set(finding.pkg.name, [finding]);
967
+ }
968
+ const contexts = new Map();
969
+ for (const [name, group] of byPackage) {
970
+ // The package's own finding describes Type, Root and IDs; fall back to the
971
+ // first of the group when the package only appears as somebody else's parent.
972
+ const own = group.find(f => f.relationship === "direct") ?? group[0];
973
+ const worst = group.reduce((a, b) => (severityOrder[b.severity] > severityOrder[a.severity] ? b : a));
974
+ let bestEpss = null;
975
+ let bestSignal = null;
976
+ for (const finding of group) {
977
+ if (!finding.epssScores || finding.epssScores.length === 0)
978
+ continue;
979
+ const top = finding.epssScores.slice().sort((a, b) => b.percentile - a.percentile)[0];
980
+ if (bestEpss === null || top.epss > bestEpss) {
981
+ bestEpss = top.epss;
982
+ bestSignal = computePrioritySignal(finding.severity, finding.epssScores);
752
983
  }
753
984
  }
754
- const isBreaking = !!target.currentVersion && isBreakingUpgrade(target.currentVersion, target.targetVersion);
755
- let usageText = chalk.gray("n/a");
756
- if (target.usage) {
757
- usageText = target.usage.imported ? chalk.red(`${target.usage.files.length} file(s)`) : chalk.green("unused");
758
- }
759
- return [
760
- target.package,
761
- target.currentVersion ?? "-",
762
- chalk.cyan(target.targetVersion),
763
- usageText,
764
- target.scannedVersions !== null && target.scannedVersions !== undefined
765
- ? chalk.blue(String(target.scannedVersions))
766
- : "-",
767
- target.knownVulnerableVersions !== null && target.knownVulnerableVersions !== undefined
768
- ? target.knownVulnerableVersions > 0
769
- ? chalk.yellow(String(target.knownVulnerableVersions))
770
- : chalk.green(String(target.knownVulnerableVersions))
771
- : "-",
772
- isBreaking ? chalk.yellow("⚠") : "",
773
- ];
774
- });
775
- if (rows.length === 0)
776
- return;
777
- const widths = widthsOverride ?? computeTableWidths(headers, rows);
778
- const line = (left, mid, right) => left + widths.map(w => "─".repeat(w + 2)).join(mid) + right;
779
- console.log(line("┌", "┬", "┐"));
780
- console.log(renderRow(headers, widths));
781
- console.log(line("├", "┼", "┤"));
782
- for (const row of rows) {
783
- console.log(renderRow(row.map(value => String(value)), widths));
784
- }
785
- if (validationSummary) {
786
- console.log(line("├", "┼", "┤"));
787
- console.log(renderRow([
788
- chalk.bold("Total"),
789
- "-",
790
- "-",
791
- "-",
792
- chalk.blue(String(validationSummary.checked)),
793
- validationSummary.vulnerable > 0
794
- ? chalk.yellow(String(validationSummary.vulnerable))
795
- : chalk.green(String(validationSummary.vulnerable)),
796
- "",
797
- ], widths));
985
+ contexts.set(name, {
986
+ severity: worst.severity,
987
+ relationship: formatRelLabel(own),
988
+ root: shortenRootSummary(formatRootDependencySummary(own)),
989
+ epss: bestEpss,
990
+ prioritySignal: bestSignal,
991
+ ids: own.vulnerabilities.map(v => v.id),
992
+ advisoryVersion: own.firstFixedVersion ?? null,
993
+ scanned: own.validatedTargetScannedVersions ?? null,
994
+ stillVulnerable: own.validatedTargetKnownVulnerableVersions ?? null,
995
+ });
798
996
  }
799
- console.log(line("└", "┴", "┘"));
997
+ return contexts;
800
998
  }
801
- function printParentUpgradeTargetsTable(targets, widthsOverride) {
802
- const headers = ["Package", "Current", "Recommended target", "Usage", "Context"];
803
- const rows = targets.map(target => {
804
- let usageText = chalk.gray("n/a");
805
- if (target.usage) {
806
- usageText = target.usage.imported ? chalk.red(`${target.usage.files.length} file(s)`) : chalk.green("unused");
807
- }
808
- return [
809
- target.package,
810
- target.currentVersion ?? "-",
811
- chalk.cyan(target.targetVersion),
812
- usageText,
813
- chalk.gray(target.reason),
814
- ];
999
+ /**
1000
+ * The one remediation table. Every fix-plan section draws exactly this.
1001
+ *
1002
+ * Context is word-wrapped rather than truncated because it is prose, so the whole
1003
+ * table wraps. An adjustment note already represented by the Scanned and Still
1004
+ * vulnerable columns is dropped rather than repeated underneath.
1005
+ */
1006
+ /**
1007
+ * Totals row for a set of rendered rows, or undefined when nothing was scanned.
1008
+ *
1009
+ * Parent upgrades carry no validation counts, so a totals row across only those
1010
+ * would read 0 of 0 and mean nothing.
1011
+ */
1012
+ function summarizeRenderedValidation(rows) {
1013
+ const scanned = rows.filter(row => row.scanned != null);
1014
+ if (scanned.length === 0)
1015
+ return undefined;
1016
+ return validationTotalsRow({
1017
+ checked: scanned.reduce((total, row) => total + (row.scanned ?? 0), 0),
1018
+ vulnerable: scanned.reduce((total, row) => total + (row.stillVulnerable ?? 0), 0),
815
1019
  });
816
- if (rows.length === 0)
817
- return;
818
- // Allow the Context column (index 4) up to 60 chars so reason text is not truncated.
819
- const widths = widthsOverride ?? computeTableWidths(headers, rows, [40, 40, 40, 40, 60]);
820
- const line = (left, mid, right) => left + widths.map(w => "─".repeat(w + 2)).join(mid) + right;
821
- console.log(line("┌", "┬", "┐"));
822
- console.log(renderRow(headers, widths));
823
- console.log(line("├", "┼", "┤"));
824
- for (const row of rows) {
825
- for (const outputRow of renderWrappedRow(row.map(value => String(value)), widths)) {
826
- console.log(outputRow);
827
- }
828
- }
829
- console.log(line("└", "┴", "┘"));
830
1020
  }
831
- function computeTableWidths(headers, rows, columnMaxWidths) {
832
- return headers.map((header, index) => {
833
- const maxWidth = columnMaxWidths?.[index] ?? 40;
834
- return Math.min(maxWidth, Math.max(header.length, ...rows.map(row => stripAnsi(String(row[index])).length)));
835
- });
1021
+ function printActionTargetsTable(targets, remainingNotes, widthsOverride, contexts, showUsage = true) {
1022
+ for (const target of targets) {
1023
+ if (!target.adjustmentNote)
1024
+ continue;
1025
+ const isCountedVulnerabilityNote = target.scannedVersions !== null &&
1026
+ target.scannedVersions !== undefined &&
1027
+ target.adjustmentNote.includes("is still known vulnerable for");
1028
+ if (!isCountedVulnerabilityNote)
1029
+ remainingNotes.push(target.adjustmentNote);
1030
+ }
1031
+ if (targets.length === 0)
1032
+ return;
1033
+ const columns = selectColumns(ACTION_TABLE_COLUMNS, showUsage);
1034
+ const rows = targets.map(target => fixTargetToTableRow(target, contexts?.get(target.package)));
1035
+ // Totalled from the rendered rows, not the raw targets, so the total always adds
1036
+ // up the numbers printed above it. A target with no counts of its own can still
1037
+ // resolve them from its finding, and summing the targets missed exactly those.
1038
+ const totalsRow = summarizeRenderedValidation(rows);
1039
+ const widths = widthsOverride ?? columnWidths(columns, totalsRow ? [...rows, totalsRow] : rows);
1040
+ printColumnTable(columns, rows, widths, { wrap: true, totalsRow });
836
1041
  }
837
- function computeSharedDirectTableWidths(sections) {
838
- const directSections = sections.filter(section => section.kind === "direct" || section.kind === "direct-adjusted");
839
- if (directSections.length === 0)
840
- return undefined;
841
- const headers = ["Package", "Current", "Target", "Usage", "Versions scanned", "Still known vulnerable", "Breaking?"];
842
- const rows = [];
843
- for (const section of directSections) {
844
- for (const target of section.targets) {
845
- const isBreaking = !!target.currentVersion && isBreakingUpgrade(target.currentVersion, target.targetVersion);
846
- let usageText = "n/a";
847
- if (target.usage) {
848
- usageText = target.usage.imported ? `${target.usage.files.length} file(s)` : "unused";
849
- }
850
- rows.push([
851
- target.package,
852
- target.currentVersion ?? "-",
853
- target.targetVersion,
854
- usageText,
855
- target.scannedVersions !== null && target.scannedVersions !== undefined ? String(target.scannedVersions) : "-",
856
- target.knownVulnerableVersions !== null && target.knownVulnerableVersions !== undefined ? String(target.knownVulnerableVersions) : "-",
857
- isBreaking ? "⚠" : "",
858
- ]);
859
- }
860
- const summary = summarizeAdjustedValidation(section.targets);
861
- rows.push(["Total", "-", "-", "-", String(summary.checked), String(summary.vulnerable), ""]);
862
- }
863
- return computeTableWidths(headers, rows);
864
- }
865
- function shouldRenderParentUpgradeTable(targets) {
866
- return targets.length > 0 && targets.every(target => target.kind === "parent-upgrade" || target.kind === "parent-update");
867
- }
868
- function computeSharedParentUpgradeTableWidths(sections) {
869
- const parentSections = sections.filter(section => shouldRenderParentUpgradeTable(section.targets));
870
- if (parentSections.length === 0)
1042
+ /**
1043
+ * One width set for every remediation table in the run.
1044
+ *
1045
+ * Both tables draw the same columns, so they must also be measured together:
1046
+ * sizing them separately produced 134 and 151 in the same Nest report. Every
1047
+ * target is measured regardless of section kind, because the renderer splits by
1048
+ * target kind and anything left unmeasured gets truncated.
1049
+ */
1050
+ function computeSharedActionTableWidths(sections, showUsage, contexts) {
1051
+ const allTargets = sections.flatMap(section => section.targets);
1052
+ if (allTargets.length === 0)
871
1053
  return undefined;
872
- const headers = ["Package", "Current", "Recommended target", "Usage", "Context"];
873
- const rows = [];
874
- for (const section of parentSections) {
875
- for (const target of section.targets) {
876
- let usageText = "n/a";
877
- if (target.usage) {
878
- usageText = target.usage.imported ? `${target.usage.files.length} file(s)` : "unused";
879
- }
880
- rows.push([
881
- target.package,
882
- target.currentVersion ?? "-",
883
- target.targetVersion,
884
- usageText,
885
- target.reason,
886
- ]);
887
- }
888
- }
889
- return computeTableWidths(headers, rows, [40, 40, 40, 40, 60]);
1054
+ const columns = selectColumns(ACTION_TABLE_COLUMNS, showUsage);
1055
+ // Built with the same contexts the renderer uses, so a count resolved from a
1056
+ // finding is measured rather than truncated when it is wider than the target's.
1057
+ const rows = allTargets.map(target => fixTargetToTableRow(target, contexts?.get(target.package)));
1058
+ const totalsRow = summarizeRenderedValidation(rows);
1059
+ if (totalsRow)
1060
+ rows.push(totalsRow);
1061
+ return columnWidths(columns, rows);
890
1062
  }