cve-lite-cli 1.7.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -41
- package/dist/cli/args.js +28 -0
- package/dist/cli/help.js +4 -0
- package/dist/index.js +45 -2
- package/dist/output/formatters.js +35 -14
- package/dist/output/html-reporter.js +431 -0
- package/dist/output/logo-base64.js +1 -0
- package/dist/output/owasp-logo-base64.js +1 -0
- package/dist/output/printers.js +81 -29
- package/dist/remediation/fix-commands.js +11 -0
- package/dist/usage/scanner.js +99 -0
- package/package.json +1 -1
package/dist/output/printers.js
CHANGED
|
@@ -61,7 +61,11 @@ export function printPriorityFixes(findings) {
|
|
|
61
61
|
console.log("");
|
|
62
62
|
console.log(chalk.bold.magenta("🚀 Top priority fixes"));
|
|
63
63
|
for (const finding of top) {
|
|
64
|
-
|
|
64
|
+
let usageNote = "";
|
|
65
|
+
if (finding.usage) {
|
|
66
|
+
usageNote = finding.usage.imported ? `, imported in ${finding.usage.files.length} file${finding.usage.files.length === 1 ? "" : "s"}` : `, no direct import found`;
|
|
67
|
+
}
|
|
68
|
+
console.log(`- ${chalk.whiteBright(finding.pkg.name)}@${chalk.white(finding.pkg.version)} (${formatSeverityLabel(finding.severity)}, ${formatRelationshipLabel(finding.relationship)}${usageNote})`);
|
|
65
69
|
console.log(` Risk: ${summarizeRisk(finding)}`);
|
|
66
70
|
const parent = getPrimaryParent(finding);
|
|
67
71
|
if (parent)
|
|
@@ -135,7 +139,7 @@ export function printSuggestedFixCommands(findings, scanInput) {
|
|
|
135
139
|
if (section.kind === "direct" || section.kind === "direct-adjusted" || (section.kind === "urgent" && hasDirectTargets)) {
|
|
136
140
|
const validationSummary = summarizeAdjustedValidation(section.targets);
|
|
137
141
|
const remainingNotes = [];
|
|
138
|
-
// Urgent sections compute their own widths so the
|
|
142
|
+
// Urgent sections compute their own widths so the Breaking? column
|
|
139
143
|
// is not truncated by widths derived from smaller non-urgent sections.
|
|
140
144
|
const tableWidths = section.kind === "urgent" ? undefined : sharedDirectTableWidths;
|
|
141
145
|
printDirectTargetsTable(section.targets, remainingNotes, validationSummary, tableWidths);
|
|
@@ -211,15 +215,22 @@ export function printGroupSummary(findings) {
|
|
|
211
215
|
}
|
|
212
216
|
}
|
|
213
217
|
export function printTable(findings, threshold) {
|
|
214
|
-
const headers = ["Package", "Version", "Severity", "Type", "Fixed", "IDs"];
|
|
215
|
-
const rawRows = findings.map(f =>
|
|
216
|
-
|
|
217
|
-
f.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
218
|
+
const headers = ["Package", "Version", "Severity", "Type", "Usage", "Fixed", "IDs"];
|
|
219
|
+
const rawRows = findings.map(f => {
|
|
220
|
+
let usageText = "n/a";
|
|
221
|
+
if (f.usage) {
|
|
222
|
+
usageText = f.usage.imported ? `${f.usage.files.length} file(s)` : "unused";
|
|
223
|
+
}
|
|
224
|
+
return [
|
|
225
|
+
f.pkg.name,
|
|
226
|
+
f.pkg.version,
|
|
227
|
+
f.severity,
|
|
228
|
+
f.relationship,
|
|
229
|
+
usageText,
|
|
230
|
+
f.firstFixedVersion ?? "-",
|
|
231
|
+
f.vulnerabilities.map(v => v.id).join(", ")
|
|
232
|
+
];
|
|
233
|
+
});
|
|
223
234
|
const widths = headers.map((header, index) => Math.min(40, Math.max(header.length, ...rawRows.map(r => String(r[index]).length))));
|
|
224
235
|
console.log("");
|
|
225
236
|
if (threshold) {
|
|
@@ -230,13 +241,21 @@ export function printTable(findings, threshold) {
|
|
|
230
241
|
console.log(renderRow(headers, widths));
|
|
231
242
|
console.log(line("├", "┼", "┤"));
|
|
232
243
|
for (const row of rawRows) {
|
|
244
|
+
let usageDecorated = String(row[4]);
|
|
245
|
+
if (usageDecorated.includes("file(s)"))
|
|
246
|
+
usageDecorated = chalk.red(usageDecorated);
|
|
247
|
+
else if (usageDecorated.includes("unused"))
|
|
248
|
+
usageDecorated = chalk.green(usageDecorated);
|
|
249
|
+
else
|
|
250
|
+
usageDecorated = chalk.gray(usageDecorated);
|
|
233
251
|
const decorated = [
|
|
234
252
|
row[0],
|
|
235
253
|
row[1],
|
|
236
254
|
formatSeverityLabel(String(row[2])),
|
|
237
255
|
formatRelationshipLabel(String(row[3])),
|
|
238
|
-
|
|
239
|
-
row[5]
|
|
256
|
+
usageDecorated,
|
|
257
|
+
row[5],
|
|
258
|
+
row[6]
|
|
240
259
|
];
|
|
241
260
|
console.log(renderRow(decorated, widths));
|
|
242
261
|
}
|
|
@@ -311,8 +330,17 @@ export function printCompactOutput(findings, scanInput) {
|
|
|
311
330
|
: finding.relationship === "transitive"
|
|
312
331
|
? "Transitive dependency"
|
|
313
332
|
: "Unknown dependency";
|
|
333
|
+
let usageContext = "";
|
|
334
|
+
if (finding.usage) {
|
|
335
|
+
if (finding.usage.imported) {
|
|
336
|
+
usageContext = chalk.red(` (imported in ${finding.usage.files.length} file${finding.usage.files.length === 1 ? "" : "s"})`);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
usageContext = chalk.green(` (no direct import found)`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
314
342
|
console.log(`${formatSeverityLabel(sevLabel)} ${chalk.whiteBright(finding.pkg.name)}@${finding.pkg.version}`);
|
|
315
|
-
console.log(` ${typeLabel}`);
|
|
343
|
+
console.log(` ${typeLabel}${usageContext}`);
|
|
316
344
|
if (finding.recommendedParentUpgrade) {
|
|
317
345
|
console.log(` ${chalk.gray(`Fix: upgrade ${finding.recommendedParentUpgrade.package} to ${finding.recommendedParentUpgrade.targetVersion}`)}`);
|
|
318
346
|
}
|
|
@@ -499,7 +527,7 @@ function summarizeAdjustedValidation(targets) {
|
|
|
499
527
|
return { checked, vulnerable };
|
|
500
528
|
}
|
|
501
529
|
function printDirectTargetsTable(targets, remainingNotes, validationSummary, widthsOverride) {
|
|
502
|
-
const headers = ["Package", "Current", "
|
|
530
|
+
const headers = ["Package", "Current", "Target", "Usage", "Versions scanned", "Still known vulnerable", "Breaking?"];
|
|
503
531
|
const rows = targets.map(target => {
|
|
504
532
|
if (target.adjustmentNote) {
|
|
505
533
|
const isCountedVulnerabilityNote = target.scannedVersions !== null &&
|
|
@@ -510,13 +538,15 @@ function printDirectTargetsTable(targets, remainingNotes, validationSummary, wid
|
|
|
510
538
|
}
|
|
511
539
|
}
|
|
512
540
|
const isBreaking = !!target.currentVersion && isMajorVersionBump(target.currentVersion, target.targetVersion);
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
541
|
+
let usageText = chalk.gray("n/a");
|
|
542
|
+
if (target.usage) {
|
|
543
|
+
usageText = target.usage.imported ? chalk.red(`${target.usage.files.length} file(s)`) : chalk.green("unused");
|
|
544
|
+
}
|
|
516
545
|
return [
|
|
517
546
|
target.package,
|
|
518
547
|
target.currentVersion ?? "-",
|
|
519
|
-
|
|
548
|
+
chalk.cyan(target.targetVersion),
|
|
549
|
+
usageText,
|
|
520
550
|
target.scannedVersions !== null && target.scannedVersions !== undefined
|
|
521
551
|
? chalk.blue(String(target.scannedVersions))
|
|
522
552
|
: "-",
|
|
@@ -525,6 +555,7 @@ function printDirectTargetsTable(targets, remainingNotes, validationSummary, wid
|
|
|
525
555
|
? chalk.yellow(String(target.knownVulnerableVersions))
|
|
526
556
|
: chalk.green(String(target.knownVulnerableVersions))
|
|
527
557
|
: "-",
|
|
558
|
+
isBreaking ? chalk.yellow("⚠") : "",
|
|
528
559
|
];
|
|
529
560
|
});
|
|
530
561
|
if (rows.length === 0)
|
|
@@ -543,22 +574,31 @@ function printDirectTargetsTable(targets, remainingNotes, validationSummary, wid
|
|
|
543
574
|
chalk.bold("Total"),
|
|
544
575
|
"-",
|
|
545
576
|
"-",
|
|
577
|
+
"-",
|
|
546
578
|
chalk.blue(String(validationSummary.checked)),
|
|
547
579
|
validationSummary.vulnerable > 0
|
|
548
580
|
? chalk.yellow(String(validationSummary.vulnerable))
|
|
549
581
|
: chalk.green(String(validationSummary.vulnerable)),
|
|
582
|
+
"",
|
|
550
583
|
], widths));
|
|
551
584
|
}
|
|
552
585
|
console.log(line("└", "┴", "┘"));
|
|
553
586
|
}
|
|
554
587
|
function printParentUpgradeTargetsTable(targets, widthsOverride) {
|
|
555
|
-
const headers = ["Package", "Current", "Recommended target", "Context"];
|
|
556
|
-
const rows = targets.map(target =>
|
|
557
|
-
|
|
558
|
-
target.
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
588
|
+
const headers = ["Package", "Current", "Recommended target", "Usage", "Context"];
|
|
589
|
+
const rows = targets.map(target => {
|
|
590
|
+
let usageText = chalk.gray("n/a");
|
|
591
|
+
if (target.usage) {
|
|
592
|
+
usageText = target.usage.imported ? chalk.red(`${target.usage.files.length} file(s)`) : chalk.green("unused");
|
|
593
|
+
}
|
|
594
|
+
return [
|
|
595
|
+
target.package,
|
|
596
|
+
target.currentVersion ?? "-",
|
|
597
|
+
chalk.cyan(target.targetVersion),
|
|
598
|
+
usageText,
|
|
599
|
+
chalk.gray(target.reason),
|
|
600
|
+
];
|
|
601
|
+
});
|
|
562
602
|
if (rows.length === 0)
|
|
563
603
|
return;
|
|
564
604
|
const widths = widthsOverride ?? computeTableWidths(headers, rows);
|
|
@@ -578,20 +618,27 @@ function computeSharedDirectTableWidths(sections) {
|
|
|
578
618
|
const directSections = sections.filter(section => section.kind === "direct" || section.kind === "direct-adjusted");
|
|
579
619
|
if (directSections.length === 0)
|
|
580
620
|
return undefined;
|
|
581
|
-
const headers = ["Package", "Current", "
|
|
621
|
+
const headers = ["Package", "Current", "Target", "Usage", "Versions scanned", "Still known vulnerable", "Breaking?"];
|
|
582
622
|
const rows = [];
|
|
583
623
|
for (const section of directSections) {
|
|
584
624
|
for (const target of section.targets) {
|
|
625
|
+
const isBreaking = !!target.currentVersion && isMajorVersionBump(target.currentVersion, target.targetVersion);
|
|
626
|
+
let usageText = "n/a";
|
|
627
|
+
if (target.usage) {
|
|
628
|
+
usageText = target.usage.imported ? `${target.usage.files.length} file(s)` : "unused";
|
|
629
|
+
}
|
|
585
630
|
rows.push([
|
|
586
631
|
target.package,
|
|
587
632
|
target.currentVersion ?? "-",
|
|
588
633
|
target.targetVersion,
|
|
634
|
+
usageText,
|
|
589
635
|
target.scannedVersions !== null && target.scannedVersions !== undefined ? String(target.scannedVersions) : "-",
|
|
590
636
|
target.knownVulnerableVersions !== null && target.knownVulnerableVersions !== undefined ? String(target.knownVulnerableVersions) : "-",
|
|
637
|
+
isBreaking ? "⚠" : "",
|
|
591
638
|
]);
|
|
592
639
|
}
|
|
593
640
|
const summary = summarizeAdjustedValidation(section.targets);
|
|
594
|
-
rows.push(["Total", "-", "-", String(summary.checked), String(summary.vulnerable)]);
|
|
641
|
+
rows.push(["Total", "-", "-", "-", String(summary.checked), String(summary.vulnerable), ""]);
|
|
595
642
|
}
|
|
596
643
|
return computeTableWidths(headers, rows);
|
|
597
644
|
}
|
|
@@ -602,14 +649,19 @@ function computeSharedParentUpgradeTableWidths(sections) {
|
|
|
602
649
|
const parentSections = sections.filter(section => shouldRenderParentUpgradeTable(section.targets));
|
|
603
650
|
if (parentSections.length === 0)
|
|
604
651
|
return undefined;
|
|
605
|
-
const headers = ["Package", "Current", "Recommended target", "Context"];
|
|
652
|
+
const headers = ["Package", "Current", "Recommended target", "Usage", "Context"];
|
|
606
653
|
const rows = [];
|
|
607
654
|
for (const section of parentSections) {
|
|
608
655
|
for (const target of section.targets) {
|
|
656
|
+
let usageText = "n/a";
|
|
657
|
+
if (target.usage) {
|
|
658
|
+
usageText = target.usage.imported ? `${target.usage.files.length} file(s)` : "unused";
|
|
659
|
+
}
|
|
609
660
|
rows.push([
|
|
610
661
|
target.package,
|
|
611
662
|
target.currentVersion ?? "-",
|
|
612
663
|
target.targetVersion,
|
|
664
|
+
usageText,
|
|
613
665
|
target.reason,
|
|
614
666
|
]);
|
|
615
667
|
}
|
|
@@ -10,6 +10,10 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
10
10
|
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
11
11
|
if (sevDelta !== 0)
|
|
12
12
|
return sevDelta;
|
|
13
|
+
const usageScore = (finding) => finding.usage?.imported ? 1 : 0;
|
|
14
|
+
const usageDelta = usageScore(b) - usageScore(a);
|
|
15
|
+
if (usageDelta !== 0)
|
|
16
|
+
return usageDelta;
|
|
13
17
|
const relScore = (finding) => finding.relationship === "direct" ? 1 : 0;
|
|
14
18
|
const relDelta = relScore(b) - relScore(a);
|
|
15
19
|
if (relDelta !== 0)
|
|
@@ -26,6 +30,10 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
26
30
|
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
27
31
|
if (sevDelta !== 0)
|
|
28
32
|
return sevDelta;
|
|
33
|
+
const usageScore = (finding) => finding.usage?.imported ? 1 : 0;
|
|
34
|
+
const usageDelta = usageScore(b) - usageScore(a);
|
|
35
|
+
if (usageDelta !== 0)
|
|
36
|
+
return usageDelta;
|
|
29
37
|
const relScore = (finding) => finding.relationship === "direct" ? 1 : 0;
|
|
30
38
|
const relDelta = relScore(b) - relScore(a);
|
|
31
39
|
if (relDelta !== 0)
|
|
@@ -59,6 +67,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
59
67
|
? finding.fixVersionValidationNote
|
|
60
68
|
: null,
|
|
61
69
|
reason: `Direct upgrade target for ${finding.pkg.name}@${finding.pkg.version}`,
|
|
70
|
+
usage: finding.usage ?? null,
|
|
62
71
|
});
|
|
63
72
|
}
|
|
64
73
|
else if (finding.fixVersionValidationNote) {
|
|
@@ -104,6 +113,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
|
|
|
104
113
|
adjusted: false,
|
|
105
114
|
adjustmentNote: null,
|
|
106
115
|
reason: `Parent upgrade for vulnerable ${finding.pkg.name}@${finding.pkg.version}`,
|
|
116
|
+
usage: finding.usage ?? null,
|
|
107
117
|
});
|
|
108
118
|
continue;
|
|
109
119
|
}
|
|
@@ -199,6 +209,7 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
199
209
|
adjusted: existing.adjusted || next.adjusted,
|
|
200
210
|
adjustmentNote: existing.adjustmentNote ?? next.adjustmentNote ?? null,
|
|
201
211
|
kind: existing.kind === "direct" || next.kind === "direct" ? "direct" : "parent-upgrade",
|
|
212
|
+
usage: existing.usage || next.usage,
|
|
202
213
|
};
|
|
203
214
|
if (looksLikeVersion(existing.targetVersion) && looksLikeVersion(next.targetVersion)) {
|
|
204
215
|
if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const IGNORED_DIRS = new Set(["node_modules", ".git", "dist", "build", "coverage"]);
|
|
4
|
+
const ALLOWED_EXTS = new Set([".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"]);
|
|
5
|
+
// Matches:
|
|
6
|
+
// import { foo } from 'pkg'
|
|
7
|
+
// import * as foo from "pkg"
|
|
8
|
+
// export { foo } from 'pkg'
|
|
9
|
+
// import 'pkg'
|
|
10
|
+
// require('pkg')
|
|
11
|
+
// await import('pkg')
|
|
12
|
+
const IMPORT_REQUIRE_REGEX = /(?:(?:import|export)\s+[\w\s{},*]+\s+from\s+['"]([^'"]+)['"]|import\s+['"]([^'"]+)['"]|require\s*\(\s*['"]([^'"]+)['"]\s*\)|import\s*\(\s*['"]([^'"]+)['"]\s*\))/g;
|
|
13
|
+
function getBareModuleName(importPath) {
|
|
14
|
+
if (importPath.startsWith(".") || importPath.startsWith("/")) {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
if (importPath.startsWith("@")) {
|
|
18
|
+
const parts = importPath.split("/");
|
|
19
|
+
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : importPath;
|
|
20
|
+
}
|
|
21
|
+
return importPath.split("/")[0];
|
|
22
|
+
}
|
|
23
|
+
export function scanProjectForPackageUsage(projectPath, packagesToLookFor) {
|
|
24
|
+
const results = {};
|
|
25
|
+
for (const pkg of packagesToLookFor) {
|
|
26
|
+
results[pkg] = [];
|
|
27
|
+
}
|
|
28
|
+
if (packagesToLookFor.size === 0) {
|
|
29
|
+
return results;
|
|
30
|
+
}
|
|
31
|
+
// Cap at 5000 files to prevent performance issues on massive projects
|
|
32
|
+
const MAX_FILES_TO_SCAN = 5000;
|
|
33
|
+
let scannedCount = 0;
|
|
34
|
+
function walk(dir) {
|
|
35
|
+
if (scannedCount >= MAX_FILES_TO_SCAN)
|
|
36
|
+
return;
|
|
37
|
+
let entries;
|
|
38
|
+
try {
|
|
39
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (const entry of entries) {
|
|
45
|
+
if (scannedCount >= MAX_FILES_TO_SCAN)
|
|
46
|
+
return;
|
|
47
|
+
const fullPath = path.join(dir, entry.name);
|
|
48
|
+
if (entry.isDirectory()) {
|
|
49
|
+
if (!IGNORED_DIRS.has(entry.name) && !entry.name.startsWith(".")) {
|
|
50
|
+
walk(fullPath);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else if (entry.isFile()) {
|
|
54
|
+
const ext = path.extname(entry.name);
|
|
55
|
+
if (ALLOWED_EXTS.has(ext)) {
|
|
56
|
+
scanFile(fullPath);
|
|
57
|
+
scannedCount++;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function scanFile(filePath) {
|
|
63
|
+
let content;
|
|
64
|
+
try {
|
|
65
|
+
content = fs.readFileSync(filePath, "utf8");
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Fast path: skip regex if the file doesn't contain any target package names
|
|
71
|
+
let hasPotentialMatch = false;
|
|
72
|
+
for (const pkg of packagesToLookFor) {
|
|
73
|
+
if (content.includes(pkg)) {
|
|
74
|
+
hasPotentialMatch = true;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!hasPotentialMatch)
|
|
79
|
+
return;
|
|
80
|
+
const matches = content.matchAll(IMPORT_REQUIRE_REGEX);
|
|
81
|
+
const foundPackages = new Set();
|
|
82
|
+
for (const match of matches) {
|
|
83
|
+
const importPath = match[1] || match[2] || match[3] || match[4];
|
|
84
|
+
if (importPath) {
|
|
85
|
+
const bare = getBareModuleName(importPath);
|
|
86
|
+
if (bare && packagesToLookFor.has(bare)) {
|
|
87
|
+
foundPackages.add(bare);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const pkg of foundPackages) {
|
|
92
|
+
// Store relative path for cleaner output
|
|
93
|
+
const relPath = path.relative(projectPath, filePath);
|
|
94
|
+
results[pkg].push(relPath);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
walk(projectPath);
|
|
98
|
+
return results;
|
|
99
|
+
}
|