cve-lite-cli 1.34.0 → 1.35.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 (37) hide show
  1. package/dist/cli/advisories-init.js +13 -0
  2. package/dist/cli/advisories-sync.js +30 -0
  3. package/dist/cli/config-command.js +15 -0
  4. package/dist/cli/config.js +29 -0
  5. package/dist/cli/help.js +4 -4
  6. package/dist/cli/overrides.js +10 -1
  7. package/dist/constants.js +52 -0
  8. package/dist/index.js +25 -719
  9. package/dist/output/cyclonedx.js +12 -0
  10. package/dist/output/html-reporter.js +73 -38
  11. package/dist/output/multi-folder-html-reporter.js +16 -10
  12. package/dist/output/multi-folder-printer.js +1 -1
  13. package/dist/output/override-findings-sarif.js +1 -0
  14. package/dist/output/printers.js +427 -270
  15. package/dist/output/sarif.js +17 -1
  16. package/dist/output/sbom-dependency-edges.js +29 -19
  17. package/dist/overrides/admitted-scan.js +158 -0
  18. package/dist/overrides/api.js +16 -0
  19. package/dist/overrides/context-builder.js +4 -0
  20. package/dist/overrides/context.js +8 -1
  21. package/dist/overrides/detectors/index.js +2 -0
  22. package/dist/overrides/detectors/oa010-vulnerable-floor.js +123 -0
  23. package/dist/overrides/parsing/registry.js +53 -0
  24. package/dist/parsers/bun-lock-graph.js +182 -0
  25. package/dist/parsers/bun-lock.js +93 -132
  26. package/dist/parsers/index.js +75 -149
  27. package/dist/parsers/multi-package.js +5 -6
  28. package/dist/parsers/pnpm-lock-graph.js +94 -0
  29. package/dist/parsers/pnpm-lock.js +5 -5
  30. package/dist/parsers/yarn-lock-graph.js +148 -0
  31. package/dist/parsers/yarn-lock.js +3 -3
  32. package/dist/remediation/fix-commands.js +48 -7
  33. package/dist/scan/completeness.js +1 -1
  34. package/dist/scan/single-scan.js +643 -0
  35. package/dist/utils/file.js +11 -14
  36. package/dist/utils/version.js +10 -0
  37. package/package.json +1 -1
@@ -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("");
@@ -369,13 +544,38 @@ export function printFinalStatus(findings, overrideCount = 0, completeness) {
369
544
  export function printOverrideHint() {
370
545
  console.log("💡 " + chalk.gray("Tip:") + " override entries detected - run with --check-overrides to audit them for stale or broken overrides.");
371
546
  }
547
+ // A cell may contain newlines, which render as extra physical lines within the
548
+ // same logical row. This is what keeps the table width bounded: a finding with
549
+ // twelve advisory IDs is twelve short lines rather than one 628-character cell
550
+ // that has to be truncated into uselessness.
551
+ // One searchable advisory ID plus a count of the rest. The full list belongs in
552
+ // --json, --sarif and the HTML report, where it is not competing for terminal
553
+ // width and each ID is a link. Joined into the table it ran to 628 characters on
554
+ // a real project, and truncated it left a single usable ID followed by a stump.
555
+ function formatAdvisoryIdFoothold(ids) {
556
+ if (ids.length === 0)
557
+ return "-";
558
+ if (ids.length === 1)
559
+ return ids[0];
560
+ return `${ids[0]} ${chalk.gray(`+${ids.length - 1}`)}`;
561
+ }
372
562
  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("│") + "│";
563
+ const columnLines = cells.map(cell => String(cell).split("\n"));
564
+ const height = Math.max(1, ...columnLines.map(lines => lines.length));
565
+ const physicalLines = [];
566
+ for (let line = 0; line < height; line++) {
567
+ const formatted = columnLines.map((lines, i) => {
568
+ const truncated = truncate(lines[line] ?? "", widths[i]);
569
+ const visible = stripAnsi(truncated);
570
+ return ` ${truncated}${" ".repeat(Math.max(0, widths[i] - visible.length))} `;
571
+ });
572
+ physicalLines.push("│" + formatted.join("│") + "│");
573
+ }
574
+ return physicalLines.join("\n");
575
+ }
576
+ // Width of the longest single line in a cell, not of the whole cell.
577
+ function cellWidth(value) {
578
+ return Math.max(...String(value).split("\n").map(line => stripAnsi(line).length));
379
579
  }
380
580
  function truncate(value, width) {
381
581
  const plain = stripAnsi(value);
@@ -550,7 +750,6 @@ export function printCompactOutput(findings, scanInput, options) {
550
750
  printCooldownWarning(target);
551
751
  }
552
752
  console.log(renderCommandCallout(section.command, section.targets));
553
- printChainProofLines(section.targets);
554
753
  console.log("");
555
754
  }
556
755
  }
@@ -628,7 +827,7 @@ export function printCompactOutput(findings, scanInput, options) {
628
827
  }
629
828
  }
630
829
  if (options?.all) {
631
- printTable(findings, null);
830
+ printTable(findings, null, undefined, plan);
632
831
  }
633
832
  else {
634
833
  console.log("");
@@ -725,6 +924,8 @@ function formatFixCommandSummary(plan) {
725
924
  const sectionLabel = sectionCount === 1 ? "group" : "groups";
726
925
  return `${sectionCount} command ${sectionLabel} ready across ${packageCount} ${packageLabel}${severitySummary ? ` (${severitySummary})` : ""}.`;
727
926
  }
927
+ // No table carries a Published column, so the publish date rides on the command
928
+ // itself in both verbose and compact output, as it did before the column existed.
728
929
  function renderCommandCallout(command, targets) {
729
930
  const display = targets ? formatFixCommandWithPublishDates(command, targets) : command;
730
931
  return chalk.bold.cyan(`> ${display}`);
@@ -740,151 +941,107 @@ function summarizeAdjustedValidation(targets) {
740
941
  }
741
942
  return { checked, vulnerable };
742
943
  }
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);
944
+ function buildFixRowContexts(findings) {
945
+ const byPackage = new Map();
946
+ for (const finding of findings) {
947
+ const list = byPackage.get(finding.pkg.name);
948
+ if (list)
949
+ list.push(finding);
950
+ else
951
+ byPackage.set(finding.pkg.name, [finding]);
952
+ }
953
+ const contexts = new Map();
954
+ for (const [name, group] of byPackage) {
955
+ // The package's own finding describes Type, Root and IDs; fall back to the
956
+ // first of the group when the package only appears as somebody else's parent.
957
+ const own = group.find(f => f.relationship === "direct") ?? group[0];
958
+ const worst = group.reduce((a, b) => (severityOrder[b.severity] > severityOrder[a.severity] ? b : a));
959
+ let bestEpss = null;
960
+ let bestSignal = null;
961
+ for (const finding of group) {
962
+ if (!finding.epssScores || finding.epssScores.length === 0)
963
+ continue;
964
+ const top = finding.epssScores.slice().sort((a, b) => b.percentile - a.percentile)[0];
965
+ if (bestEpss === null || top.epss > bestEpss) {
966
+ bestEpss = top.epss;
967
+ bestSignal = computePrioritySignal(finding.severity, finding.epssScores);
752
968
  }
753
969
  }
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));
970
+ contexts.set(name, {
971
+ severity: worst.severity,
972
+ relationship: formatRelLabel(own),
973
+ root: shortenRootSummary(formatRootDependencySummary(own)),
974
+ epss: bestEpss,
975
+ prioritySignal: bestSignal,
976
+ ids: own.vulnerabilities.map(v => v.id),
977
+ advisoryVersion: own.firstFixedVersion ?? null,
978
+ scanned: own.validatedTargetScannedVersions ?? null,
979
+ stillVulnerable: own.validatedTargetKnownVulnerableVersions ?? null,
980
+ });
798
981
  }
799
- console.log(line("└", "┴", "┘"));
982
+ return contexts;
800
983
  }
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
- ];
984
+ /**
985
+ * The one remediation table. Every fix-plan section draws exactly this.
986
+ *
987
+ * Context is word-wrapped rather than truncated because it is prose, so the whole
988
+ * table wraps. An adjustment note already represented by the Scanned and Still
989
+ * vulnerable columns is dropped rather than repeated underneath.
990
+ */
991
+ /**
992
+ * Totals row for a set of rendered rows, or undefined when nothing was scanned.
993
+ *
994
+ * Parent upgrades carry no validation counts, so a totals row across only those
995
+ * would read 0 of 0 and mean nothing.
996
+ */
997
+ function summarizeRenderedValidation(rows) {
998
+ const scanned = rows.filter(row => row.scanned != null);
999
+ if (scanned.length === 0)
1000
+ return undefined;
1001
+ return validationTotalsRow({
1002
+ checked: scanned.reduce((total, row) => total + (row.scanned ?? 0), 0),
1003
+ vulnerable: scanned.reduce((total, row) => total + (row.stillVulnerable ?? 0), 0),
815
1004
  });
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
1005
  }
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
- });
1006
+ function printActionTargetsTable(targets, remainingNotes, widthsOverride, contexts, showUsage = true) {
1007
+ for (const target of targets) {
1008
+ if (!target.adjustmentNote)
1009
+ continue;
1010
+ const isCountedVulnerabilityNote = target.scannedVersions !== null &&
1011
+ target.scannedVersions !== undefined &&
1012
+ target.adjustmentNote.includes("is still known vulnerable for");
1013
+ if (!isCountedVulnerabilityNote)
1014
+ remainingNotes.push(target.adjustmentNote);
1015
+ }
1016
+ if (targets.length === 0)
1017
+ return;
1018
+ const columns = selectColumns(ACTION_TABLE_COLUMNS, showUsage);
1019
+ const rows = targets.map(target => fixTargetToTableRow(target, contexts?.get(target.package)));
1020
+ // Totalled from the rendered rows, not the raw targets, so the total always adds
1021
+ // up the numbers printed above it. A target with no counts of its own can still
1022
+ // resolve them from its finding, and summing the targets missed exactly those.
1023
+ const totalsRow = summarizeRenderedValidation(rows);
1024
+ const widths = widthsOverride ?? columnWidths(columns, totalsRow ? [...rows, totalsRow] : rows);
1025
+ printColumnTable(columns, rows, widths, { wrap: true, totalsRow });
836
1026
  }
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)
1027
+ /**
1028
+ * One width set for every remediation table in the run.
1029
+ *
1030
+ * Both tables draw the same columns, so they must also be measured together:
1031
+ * sizing them separately produced 134 and 151 in the same Nest report. Every
1032
+ * target is measured regardless of section kind, because the renderer splits by
1033
+ * target kind and anything left unmeasured gets truncated.
1034
+ */
1035
+ function computeSharedActionTableWidths(sections, showUsage, contexts) {
1036
+ const allTargets = sections.flatMap(section => section.targets);
1037
+ if (allTargets.length === 0)
871
1038
  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]);
1039
+ const columns = selectColumns(ACTION_TABLE_COLUMNS, showUsage);
1040
+ // Built with the same contexts the renderer uses, so a count resolved from a
1041
+ // finding is measured rather than truncated when it is wider than the target's.
1042
+ const rows = allTargets.map(target => fixTargetToTableRow(target, contexts?.get(target.package)));
1043
+ const totalsRow = summarizeRenderedValidation(rows);
1044
+ if (totalsRow)
1045
+ rows.push(totalsRow);
1046
+ return columnWidths(columns, rows);
890
1047
  }