cve-lite-cli 1.3.0 → 1.5.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.
- package/README.md +85 -21
- package/dist/index.js +159 -146
- package/dist/output/formatters.js +4 -0
- package/dist/output/printers.js +210 -21
- package/dist/remediation/fix-commands.js +165 -10
- package/dist/remediation/npm-registry.js +258 -0
- package/dist/remediation/parent-upgrade.js +2 -19
- package/dist/scanner.js +45 -0
- package/package.json +1 -1
package/dist/output/printers.js
CHANGED
|
@@ -119,24 +119,51 @@ export function printSuggestedFixCommands(findings, scanInput) {
|
|
|
119
119
|
const plan = buildSuggestedFixCommandPlan(findings, scanInput);
|
|
120
120
|
if (!plan)
|
|
121
121
|
return;
|
|
122
|
-
if (
|
|
122
|
+
if (plan.sections.length === 0)
|
|
123
123
|
return;
|
|
124
|
+
const sharedDirectTableWidths = computeSharedDirectTableWidths(plan.sections);
|
|
124
125
|
console.log("");
|
|
125
|
-
console.log(chalk.bold.
|
|
126
|
+
console.log(chalk.bold.yellow("🛠 Copy And Run These Fix Commands"));
|
|
126
127
|
console.log(`${chalk.gray("Detected package manager:")} ${chalk.cyan(plan.packageManager)} ${chalk.gray(`(${plan.sourceLabel})`)}`);
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
console.log(chalk.white(formatFixCommandSummary(plan)));
|
|
129
|
+
for (const section of plan.sections) {
|
|
130
|
+
console.log("");
|
|
131
|
+
console.log(colorFixSectionTitle(section.severity, section.title));
|
|
132
|
+
if (section.kind === "direct" || section.kind === "direct-adjusted") {
|
|
133
|
+
const validationSummary = summarizeAdjustedValidation(section.targets);
|
|
134
|
+
const remainingNotes = [];
|
|
135
|
+
printDirectTargetsTable(section.targets, remainingNotes, validationSummary, sharedDirectTableWidths);
|
|
136
|
+
for (const note of remainingNotes) {
|
|
137
|
+
console.log(chalk.gray(` Note: ${note}`));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
console.log(renderCommandCallout(section.command));
|
|
129
141
|
}
|
|
130
|
-
|
|
131
|
-
|
|
142
|
+
}
|
|
143
|
+
export function printSuggestedFixCommandSkips(findings, scanInput) {
|
|
144
|
+
const plan = buildSuggestedFixCommandPlan(findings, scanInput);
|
|
145
|
+
if (!plan || plan.skipped.length === 0)
|
|
146
|
+
return;
|
|
147
|
+
const unpublishable = plan.skipped.filter(skipped => skipped.reason.includes("not published on npm"));
|
|
148
|
+
const remaining = plan.skipped.filter(skipped => !skipped.reason.includes("not published on npm"));
|
|
149
|
+
if (unpublishable.length > 0) {
|
|
150
|
+
console.log("");
|
|
151
|
+
console.log(chalk.gray("Unpublishable fixed-version hints:"));
|
|
152
|
+
for (const skipped of unpublishable.slice(0, 5)) {
|
|
153
|
+
console.log(`- ${skipped.package}@${skipped.version}: ${skipped.reason}`);
|
|
154
|
+
}
|
|
155
|
+
if (unpublishable.length > 5) {
|
|
156
|
+
console.log(`- ...and ${unpublishable.length - 5} more`);
|
|
157
|
+
}
|
|
132
158
|
}
|
|
133
|
-
if (
|
|
159
|
+
if (remaining.length > 0) {
|
|
160
|
+
console.log("");
|
|
134
161
|
console.log(chalk.gray("Not included automatically:"));
|
|
135
|
-
for (const skipped of
|
|
162
|
+
for (const skipped of remaining.slice(0, 5)) {
|
|
136
163
|
console.log(`- ${skipped.package}@${skipped.version}: ${skipped.reason}`);
|
|
137
164
|
}
|
|
138
|
-
if (
|
|
139
|
-
console.log(`- ...and ${
|
|
165
|
+
if (remaining.length > 5) {
|
|
166
|
+
console.log(`- ...and ${remaining.length - 5} more`);
|
|
140
167
|
}
|
|
141
168
|
}
|
|
142
169
|
}
|
|
@@ -291,11 +318,38 @@ export function printCompactOutput(findings, scanInput) {
|
|
|
291
318
|
}
|
|
292
319
|
console.log("");
|
|
293
320
|
}
|
|
321
|
+
const plan = scanInput ? buildSuggestedFixCommandPlan(findings, scanInput) : null;
|
|
322
|
+
if (plan) {
|
|
323
|
+
if (plan?.sections.length) {
|
|
324
|
+
console.log("────────────────────────────────");
|
|
325
|
+
console.log(chalk.bold.yellow("🛠 Copy And Run These Fix Commands"));
|
|
326
|
+
console.log("────────────────────────────────\n");
|
|
327
|
+
console.log(`${chalk.gray("Detected package manager:")} ${chalk.cyan(plan.packageManager)} ${chalk.gray(`(${plan.sourceLabel})`)}`);
|
|
328
|
+
console.log(formatFixCommandSummary(plan));
|
|
329
|
+
const compactValidationSummary = summarizeAdjustedValidation(plan.targets);
|
|
330
|
+
if (compactValidationSummary.checked > 0) {
|
|
331
|
+
console.log(chalk.gray(`Validation: scanned ${compactValidationSummary.checked} package version${compactValidationSummary.checked === 1 ? "" : "s"}; ${compactValidationSummary.vulnerable} ${compactValidationSummary.vulnerable === 1 ? "is" : "are"} still known vulnerable.`));
|
|
332
|
+
}
|
|
333
|
+
console.log("");
|
|
334
|
+
for (const section of plan.sections.slice(0, 3)) {
|
|
335
|
+
console.log(`${section.title}`);
|
|
336
|
+
if (section.kind === "direct-adjusted") {
|
|
337
|
+
for (const target of section.targets) {
|
|
338
|
+
if (!target.adjustmentNote)
|
|
339
|
+
continue;
|
|
340
|
+
console.log(chalk.gray(` Note: ${target.adjustmentNote}`));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
console.log(renderCommandCallout(section.command));
|
|
344
|
+
console.log("");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
294
348
|
// Top Priority Fix section
|
|
295
349
|
if (urgentFindings.length > 0) {
|
|
296
350
|
const topFinding = urgentFindings[0];
|
|
297
351
|
console.log("────────────────────────────────");
|
|
298
|
-
console.log(chalk.bold("🚀 Top Priority
|
|
352
|
+
console.log(chalk.bold("🚀 Top Priority Issue"));
|
|
299
353
|
console.log("────────────────────────────────\n");
|
|
300
354
|
if (topFinding.relationship === "direct" && topFinding.firstFixedVersion) {
|
|
301
355
|
console.log(`Upgrade ${chalk.whiteBright(topFinding.pkg.name)} → ${topFinding.firstFixedVersion}`);
|
|
@@ -315,17 +369,17 @@ export function printCompactOutput(findings, scanInput) {
|
|
|
315
369
|
console.log(`Upgrade parent chain to resolve ${chalk.whiteBright(topFinding.pkg.name)}`);
|
|
316
370
|
}
|
|
317
371
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
console.log("");
|
|
372
|
+
if (plan) {
|
|
373
|
+
const topFindingCommand = findSuggestedCommandForFinding(plan, topFinding);
|
|
374
|
+
if (topFindingCommand) {
|
|
375
|
+
console.log(chalk.gray("Command:"));
|
|
376
|
+
console.log(renderCommandCallout(topFindingCommand));
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
console.log(chalk.gray("No confident automatic command is available for this issue yet."));
|
|
380
|
+
}
|
|
328
381
|
}
|
|
382
|
+
console.log("");
|
|
329
383
|
}
|
|
330
384
|
// Summary
|
|
331
385
|
console.log("────────────────────────────────");
|
|
@@ -368,3 +422,138 @@ export function printCompactOutput(findings, scanInput) {
|
|
|
368
422
|
console.log(chalk.gray(`Run with ${chalk.whiteBright("--verbose")} for fix plan, paths, and full table.`));
|
|
369
423
|
console.log("");
|
|
370
424
|
}
|
|
425
|
+
function colorFixSectionTitle(severity, title) {
|
|
426
|
+
if (severity === "critical")
|
|
427
|
+
return chalk.redBright(title);
|
|
428
|
+
if (severity === "high")
|
|
429
|
+
return chalk.magenta(title);
|
|
430
|
+
if (severity === "medium")
|
|
431
|
+
return chalk.yellow(title);
|
|
432
|
+
if (severity === "low")
|
|
433
|
+
return chalk.green(title);
|
|
434
|
+
return chalk.gray(title);
|
|
435
|
+
}
|
|
436
|
+
function formatFixCommandSummary(plan) {
|
|
437
|
+
if (!plan)
|
|
438
|
+
return "";
|
|
439
|
+
const packageCount = plan.targets.length;
|
|
440
|
+
const sectionCount = plan.sections.length;
|
|
441
|
+
const severityCounts = new Map();
|
|
442
|
+
for (const section of plan.sections) {
|
|
443
|
+
severityCounts.set(section.severity, (severityCounts.get(section.severity) ?? 0) + 1);
|
|
444
|
+
}
|
|
445
|
+
const severitySummary = ["critical", "high", "medium", "low", "unknown"]
|
|
446
|
+
.filter(severity => (severityCounts.get(severity) ?? 0) > 0)
|
|
447
|
+
.map(severity => `${severityCounts.get(severity)} ${severity}`)
|
|
448
|
+
.join(", ");
|
|
449
|
+
const packageLabel = packageCount === 1 ? "package" : "packages";
|
|
450
|
+
const sectionLabel = sectionCount === 1 ? "group" : "groups";
|
|
451
|
+
return `${sectionCount} command ${sectionLabel} ready across ${packageCount} ${packageLabel}${severitySummary ? ` (${severitySummary})` : ""}.`;
|
|
452
|
+
}
|
|
453
|
+
function renderCommandCallout(command) {
|
|
454
|
+
return chalk.bold.cyan(`> ${command}`);
|
|
455
|
+
}
|
|
456
|
+
function findSuggestedCommandForFinding(plan, finding) {
|
|
457
|
+
const target = plan.targets.find(item => {
|
|
458
|
+
if (finding.recommendedParentUpgrade) {
|
|
459
|
+
return (item.package === finding.recommendedParentUpgrade.package &&
|
|
460
|
+
item.targetVersion === finding.recommendedParentUpgrade.targetVersion);
|
|
461
|
+
}
|
|
462
|
+
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
463
|
+
return item.package === finding.pkg.name && item.targetVersion === directTarget;
|
|
464
|
+
});
|
|
465
|
+
if (!target)
|
|
466
|
+
return null;
|
|
467
|
+
return `${packageManagerCommandPrefix(plan.packageManager)} ${target.package}@${target.targetVersion}`;
|
|
468
|
+
}
|
|
469
|
+
function packageManagerCommandPrefix(packageManager) {
|
|
470
|
+
if (packageManager === "npm")
|
|
471
|
+
return "npm install";
|
|
472
|
+
if (packageManager === "pnpm")
|
|
473
|
+
return "pnpm add";
|
|
474
|
+
return "yarn add";
|
|
475
|
+
}
|
|
476
|
+
function summarizeAdjustedValidation(targets) {
|
|
477
|
+
let checked = 0;
|
|
478
|
+
let vulnerable = 0;
|
|
479
|
+
for (const target of targets) {
|
|
480
|
+
if (target.scannedVersions === null || target.scannedVersions === undefined)
|
|
481
|
+
continue;
|
|
482
|
+
checked += target.scannedVersions;
|
|
483
|
+
vulnerable += target.knownVulnerableVersions ?? 0;
|
|
484
|
+
}
|
|
485
|
+
return { checked, vulnerable };
|
|
486
|
+
}
|
|
487
|
+
function printDirectTargetsTable(targets, remainingNotes, validationSummary, widthsOverride) {
|
|
488
|
+
const headers = ["Package", "Current", "Recommended target", "Versions scanned", "Still known vulnerable"];
|
|
489
|
+
const rows = targets.map(target => {
|
|
490
|
+
if (target.adjustmentNote) {
|
|
491
|
+
const isCountedVulnerabilityNote = target.scannedVersions !== null &&
|
|
492
|
+
target.scannedVersions !== undefined &&
|
|
493
|
+
target.adjustmentNote.includes("is still known vulnerable for");
|
|
494
|
+
if (!isCountedVulnerabilityNote) {
|
|
495
|
+
remainingNotes.push(target.adjustmentNote);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return [
|
|
499
|
+
target.package,
|
|
500
|
+
target.currentVersion ?? "-",
|
|
501
|
+
chalk.cyan(target.targetVersion),
|
|
502
|
+
target.scannedVersions !== null && target.scannedVersions !== undefined
|
|
503
|
+
? chalk.blue(String(target.scannedVersions))
|
|
504
|
+
: "-",
|
|
505
|
+
target.knownVulnerableVersions !== null && target.knownVulnerableVersions !== undefined
|
|
506
|
+
? target.knownVulnerableVersions > 0
|
|
507
|
+
? chalk.yellow(String(target.knownVulnerableVersions))
|
|
508
|
+
: chalk.green(String(target.knownVulnerableVersions))
|
|
509
|
+
: "-",
|
|
510
|
+
];
|
|
511
|
+
});
|
|
512
|
+
if (rows.length === 0)
|
|
513
|
+
return;
|
|
514
|
+
const widths = widthsOverride ?? computeTableWidths(headers, rows);
|
|
515
|
+
const line = (left, mid, right) => left + widths.map(w => "─".repeat(w + 2)).join(mid) + right;
|
|
516
|
+
console.log(line("┌", "┬", "┐"));
|
|
517
|
+
console.log(renderRow(headers, widths));
|
|
518
|
+
console.log(line("├", "┼", "┤"));
|
|
519
|
+
for (const row of rows) {
|
|
520
|
+
console.log(renderRow(row.map(value => String(value)), widths));
|
|
521
|
+
}
|
|
522
|
+
if (validationSummary) {
|
|
523
|
+
console.log(line("├", "┼", "┤"));
|
|
524
|
+
console.log(renderRow([
|
|
525
|
+
chalk.bold("Total"),
|
|
526
|
+
"-",
|
|
527
|
+
"-",
|
|
528
|
+
chalk.blue(String(validationSummary.checked)),
|
|
529
|
+
validationSummary.vulnerable > 0
|
|
530
|
+
? chalk.yellow(String(validationSummary.vulnerable))
|
|
531
|
+
: chalk.green(String(validationSummary.vulnerable)),
|
|
532
|
+
], widths));
|
|
533
|
+
}
|
|
534
|
+
console.log(line("└", "┴", "┘"));
|
|
535
|
+
}
|
|
536
|
+
function computeTableWidths(headers, rows) {
|
|
537
|
+
return headers.map((header, index) => Math.min(40, Math.max(header.length, ...rows.map(row => stripAnsi(String(row[index])).length))));
|
|
538
|
+
}
|
|
539
|
+
function computeSharedDirectTableWidths(sections) {
|
|
540
|
+
const directSections = sections.filter(section => section.kind === "direct" || section.kind === "direct-adjusted");
|
|
541
|
+
if (directSections.length === 0)
|
|
542
|
+
return undefined;
|
|
543
|
+
const headers = ["Package", "Current", "Recommended target", "Versions scanned", "Still known vulnerable"];
|
|
544
|
+
const rows = [];
|
|
545
|
+
for (const section of directSections) {
|
|
546
|
+
for (const target of section.targets) {
|
|
547
|
+
rows.push([
|
|
548
|
+
target.package,
|
|
549
|
+
target.currentVersion ?? "-",
|
|
550
|
+
target.targetVersion,
|
|
551
|
+
target.scannedVersions !== null && target.scannedVersions !== undefined ? String(target.scannedVersions) : "-",
|
|
552
|
+
target.knownVulnerableVersions !== null && target.knownVulnerableVersions !== undefined ? String(target.knownVulnerableVersions) : "-",
|
|
553
|
+
]);
|
|
554
|
+
}
|
|
555
|
+
const summary = summarizeAdjustedValidation(section.targets);
|
|
556
|
+
rows.push(["Total", "-", "-", String(summary.checked), String(summary.vulnerable)]);
|
|
557
|
+
}
|
|
558
|
+
return computeTableWidths(headers, rows);
|
|
559
|
+
}
|
|
@@ -4,7 +4,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
4
4
|
const packageManager = inferPackageManager(scanInput);
|
|
5
5
|
if (!packageManager)
|
|
6
6
|
return null;
|
|
7
|
-
const
|
|
7
|
+
const prioritizedFindings = [...findings]
|
|
8
8
|
.filter(f => f.severity === "critical" || f.severity === "high")
|
|
9
9
|
.sort((a, b) => {
|
|
10
10
|
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
@@ -18,45 +18,119 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
18
18
|
});
|
|
19
19
|
const targetsByPackage = new Map();
|
|
20
20
|
const skippedByKey = new Map();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const orderedFindings = [
|
|
22
|
+
...prioritizedFindings,
|
|
23
|
+
...findings
|
|
24
|
+
.filter(f => f.severity !== "critical" && f.severity !== "high")
|
|
25
|
+
.sort((a, b) => {
|
|
26
|
+
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
27
|
+
if (sevDelta !== 0)
|
|
28
|
+
return sevDelta;
|
|
29
|
+
const relScore = (finding) => finding.relationship === "direct" ? 1 : 0;
|
|
30
|
+
const relDelta = relScore(b) - relScore(a);
|
|
31
|
+
if (relDelta !== 0)
|
|
32
|
+
return relDelta;
|
|
33
|
+
return a.pkg.name.localeCompare(b.pkg.name);
|
|
34
|
+
}),
|
|
35
|
+
];
|
|
36
|
+
for (const finding of orderedFindings) {
|
|
37
|
+
const urgent = finding.severity === "critical" || finding.severity === "high";
|
|
38
|
+
if (finding.relationship === "direct" || finding.relationship === "unknown") {
|
|
39
|
+
const hasValidatedField = Object.prototype.hasOwnProperty.call(finding, "validatedFirstFixedVersion");
|
|
40
|
+
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
41
|
+
if (directTarget &&
|
|
42
|
+
isUpgradeTarget(finding.pkg.version, directTarget) &&
|
|
43
|
+
(!hasValidatedField || finding.validatedFirstFixedVersion !== null)) {
|
|
24
44
|
upsertTarget(targetsByPackage, {
|
|
25
45
|
package: finding.pkg.name,
|
|
26
|
-
|
|
46
|
+
currentVersion: finding.pkg.version,
|
|
47
|
+
targetVersion: directTarget,
|
|
48
|
+
scannedVersions: finding.validatedTargetScannedVersions ?? null,
|
|
49
|
+
knownVulnerableVersions: finding.validatedTargetKnownVulnerableVersions ?? null,
|
|
27
50
|
kind: "direct",
|
|
51
|
+
urgent,
|
|
52
|
+
severity: finding.severity,
|
|
53
|
+
adjusted: Boolean(finding.fixVersionValidationNote &&
|
|
54
|
+
finding.validatedFirstFixedVersion &&
|
|
55
|
+
finding.validatedFirstFixedVersion !== finding.firstFixedVersion),
|
|
56
|
+
adjustmentNote: finding.fixVersionValidationNote &&
|
|
57
|
+
finding.validatedFirstFixedVersion &&
|
|
58
|
+
finding.validatedFirstFixedVersion !== finding.firstFixedVersion
|
|
59
|
+
? finding.fixVersionValidationNote
|
|
60
|
+
: null,
|
|
28
61
|
reason: `Direct upgrade target for ${finding.pkg.name}@${finding.pkg.version}`,
|
|
29
62
|
});
|
|
30
63
|
}
|
|
64
|
+
else if (finding.fixVersionValidationNote) {
|
|
65
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
66
|
+
package: finding.pkg.name,
|
|
67
|
+
version: finding.pkg.version,
|
|
68
|
+
relationship: finding.relationship,
|
|
69
|
+
reason: finding.fixVersionValidationNote,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else if (finding.firstFixedVersion) {
|
|
73
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
74
|
+
package: finding.pkg.name,
|
|
75
|
+
version: finding.pkg.version,
|
|
76
|
+
relationship: finding.relationship,
|
|
77
|
+
reason: `Fixed-version hint ${directTarget} is not an upgrade from installed ${finding.pkg.version}.`,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
31
80
|
else {
|
|
32
81
|
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
33
82
|
package: finding.pkg.name,
|
|
34
83
|
version: finding.pkg.version,
|
|
35
84
|
relationship: finding.relationship,
|
|
36
|
-
reason:
|
|
85
|
+
reason: urgent
|
|
86
|
+
? "No safe upgrade target is known for this urgent direct dependency."
|
|
87
|
+
: "No safe upgrade target is known for this direct dependency.",
|
|
37
88
|
});
|
|
38
89
|
}
|
|
39
90
|
continue;
|
|
40
91
|
}
|
|
41
|
-
if (finding.relationship === "transitive" &&
|
|
92
|
+
if (finding.relationship === "transitive" &&
|
|
93
|
+
finding.recommendedParentUpgrade &&
|
|
94
|
+
isUpgradeTarget(finding.recommendedParentUpgrade.currentVersion, finding.recommendedParentUpgrade.targetVersion)) {
|
|
42
95
|
upsertTarget(targetsByPackage, {
|
|
43
96
|
package: finding.recommendedParentUpgrade.package,
|
|
44
97
|
targetVersion: finding.recommendedParentUpgrade.targetVersion,
|
|
98
|
+
scannedVersions: null,
|
|
99
|
+
knownVulnerableVersions: null,
|
|
45
100
|
kind: "parent-upgrade",
|
|
101
|
+
urgent,
|
|
102
|
+
severity: finding.severity,
|
|
103
|
+
adjusted: false,
|
|
104
|
+
adjustmentNote: null,
|
|
46
105
|
reason: `Parent upgrade for vulnerable ${finding.pkg.name}@${finding.pkg.version}`,
|
|
47
106
|
});
|
|
48
107
|
continue;
|
|
49
108
|
}
|
|
109
|
+
if (finding.relationship === "transitive" && finding.recommendedParentUpgrade) {
|
|
110
|
+
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
111
|
+
package: finding.pkg.name,
|
|
112
|
+
version: finding.pkg.version,
|
|
113
|
+
relationship: finding.relationship,
|
|
114
|
+
reason: `Suggested parent target ${finding.recommendedParentUpgrade.package}@${finding.recommendedParentUpgrade.targetVersion} is not an upgrade from installed ${finding.recommendedParentUpgrade.currentVersion}.`,
|
|
115
|
+
});
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
50
118
|
skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
51
119
|
package: finding.pkg.name,
|
|
52
120
|
version: finding.pkg.version,
|
|
53
121
|
relationship: finding.relationship,
|
|
54
122
|
reason: finding.relationship === "transitive"
|
|
55
|
-
? "No specific parent upgrade target was found for this
|
|
123
|
+
? "No specific parent upgrade target was found for this transitive issue."
|
|
56
124
|
: "No confident automatic fix command could be generated for this issue.",
|
|
57
125
|
});
|
|
58
126
|
}
|
|
59
127
|
const targets = [...targetsByPackage.values()].sort((a, b) => {
|
|
128
|
+
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
129
|
+
if (sevDelta !== 0)
|
|
130
|
+
return sevDelta;
|
|
131
|
+
const urgentDelta = Number(b.urgent) - Number(a.urgent);
|
|
132
|
+
if (urgentDelta !== 0)
|
|
133
|
+
return urgentDelta;
|
|
60
134
|
const kindScore = (target) => target.kind === "direct" ? 1 : 0;
|
|
61
135
|
const kindDelta = kindScore(b) - kindScore(a);
|
|
62
136
|
if (kindDelta !== 0)
|
|
@@ -64,6 +138,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
64
138
|
return a.package.localeCompare(b.package);
|
|
65
139
|
});
|
|
66
140
|
const skipped = [...skippedByKey.values()].sort((a, b) => a.package.localeCompare(b.package));
|
|
141
|
+
const sections = buildSections(targets, packageManager);
|
|
67
142
|
const command = targets.length > 0
|
|
68
143
|
? `${commandPrefix(packageManager)} ${targets.map(target => `${target.package}@${target.targetVersion}`).join(" ")}`
|
|
69
144
|
: null;
|
|
@@ -71,6 +146,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
71
146
|
packageManager,
|
|
72
147
|
sourceLabel: packageManagerSourceLabel(scanInput),
|
|
73
148
|
command,
|
|
149
|
+
sections,
|
|
74
150
|
targets,
|
|
75
151
|
skipped,
|
|
76
152
|
};
|
|
@@ -109,13 +185,92 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
109
185
|
targetsByPackage.set(next.package, next);
|
|
110
186
|
return;
|
|
111
187
|
}
|
|
188
|
+
const merged = {
|
|
189
|
+
...existing,
|
|
190
|
+
urgent: existing.urgent || next.urgent,
|
|
191
|
+
severity: severityOrder[next.severity] > severityOrder[existing.severity] ? next.severity : existing.severity,
|
|
192
|
+
adjusted: existing.adjusted || next.adjusted,
|
|
193
|
+
adjustmentNote: existing.adjustmentNote ?? next.adjustmentNote ?? null,
|
|
194
|
+
kind: existing.kind === "direct" || next.kind === "direct" ? "direct" : "parent-upgrade",
|
|
195
|
+
};
|
|
112
196
|
if (looksLikeVersion(existing.targetVersion) && looksLikeVersion(next.targetVersion)) {
|
|
113
197
|
if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
|
|
114
|
-
|
|
198
|
+
merged.targetVersion = next.targetVersion;
|
|
199
|
+
merged.reason = next.reason;
|
|
200
|
+
merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
|
|
201
|
+
merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
|
|
115
202
|
}
|
|
203
|
+
targetsByPackage.set(next.package, merged);
|
|
116
204
|
return;
|
|
117
205
|
}
|
|
118
206
|
if (next.kind === "direct" && existing.kind !== "direct") {
|
|
119
|
-
|
|
207
|
+
merged.targetVersion = next.targetVersion;
|
|
208
|
+
merged.reason = next.reason;
|
|
209
|
+
merged.adjustmentNote = next.adjustmentNote ?? merged.adjustmentNote;
|
|
210
|
+
merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
|
|
211
|
+
merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
|
|
120
212
|
}
|
|
213
|
+
targetsByPackage.set(next.package, merged);
|
|
214
|
+
}
|
|
215
|
+
function isUpgradeTarget(currentVersion, targetVersion) {
|
|
216
|
+
if (!currentVersion || !targetVersion || currentVersion === targetVersion)
|
|
217
|
+
return false;
|
|
218
|
+
if (looksLikeVersion(currentVersion) && looksLikeVersion(targetVersion)) {
|
|
219
|
+
return compareVersions(targetVersion, currentVersion) > 0;
|
|
220
|
+
}
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
function buildSections(targets, packageManager) {
|
|
224
|
+
const groups = [];
|
|
225
|
+
const commandForTargets = (items) => `${commandPrefix(packageManager)} ${items.map(target => `${target.package}@${target.targetVersion}`).join(" ")}`;
|
|
226
|
+
const sectionOrder = [
|
|
227
|
+
{ kind: "urgent", severity: "critical" },
|
|
228
|
+
{ kind: "urgent", severity: "high" },
|
|
229
|
+
{ kind: "direct", severity: "medium" },
|
|
230
|
+
{ kind: "direct", severity: "low" },
|
|
231
|
+
{ kind: "direct", severity: "unknown" },
|
|
232
|
+
{ kind: "direct-adjusted", severity: "medium" },
|
|
233
|
+
{ kind: "direct-adjusted", severity: "low" },
|
|
234
|
+
{ kind: "direct-adjusted", severity: "unknown" },
|
|
235
|
+
{ kind: "parent-upgrade", severity: "medium" },
|
|
236
|
+
{ kind: "parent-upgrade", severity: "low" },
|
|
237
|
+
{ kind: "parent-upgrade", severity: "unknown" },
|
|
238
|
+
];
|
|
239
|
+
for (const entry of sectionOrder) {
|
|
240
|
+
const sectionTargets = targets.filter(target => {
|
|
241
|
+
const targetKind = target.urgent ? "urgent" : target.adjusted ? "direct-adjusted" : target.kind;
|
|
242
|
+
return targetKind === entry.kind && target.severity === entry.severity;
|
|
243
|
+
});
|
|
244
|
+
if (sectionTargets.length === 0)
|
|
245
|
+
continue;
|
|
246
|
+
groups.push({
|
|
247
|
+
key: `${entry.kind}:${entry.severity}`,
|
|
248
|
+
kind: entry.kind,
|
|
249
|
+
severity: entry.severity,
|
|
250
|
+
title: buildSectionTitle(entry.kind, entry.severity),
|
|
251
|
+
command: commandForTargets(sectionTargets),
|
|
252
|
+
targets: sectionTargets,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return groups;
|
|
256
|
+
}
|
|
257
|
+
function buildSectionTitle(kind, severity) {
|
|
258
|
+
const severityTitle = severity === "unknown"
|
|
259
|
+
? "Unknown severity"
|
|
260
|
+
: `${capitalize(severity)} severity`;
|
|
261
|
+
if (kind === "urgent") {
|
|
262
|
+
return severity === "critical"
|
|
263
|
+
? "Critical severity fix commands"
|
|
264
|
+
: "High severity fix commands";
|
|
265
|
+
}
|
|
266
|
+
if (kind === "direct") {
|
|
267
|
+
return `${severityTitle} direct fixes`;
|
|
268
|
+
}
|
|
269
|
+
if (kind === "direct-adjusted") {
|
|
270
|
+
return `${severityTitle} direct fixes (registry-adjusted)`;
|
|
271
|
+
}
|
|
272
|
+
return `${severityTitle} parent upgrades`;
|
|
273
|
+
}
|
|
274
|
+
function capitalize(value) {
|
|
275
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
121
276
|
}
|