cve-lite-cli 1.27.0 → 1.29.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 +45 -3
- package/dist/advisory/osv-advisory-source.js +5 -3
- package/dist/cli/advisories-init.js +24 -0
- package/dist/cli/args.js +30 -0
- package/dist/cli/help.js +6 -2
- package/dist/cli/validate.js +6 -0
- package/dist/constants.js +1 -0
- package/dist/index.js +67 -7
- package/dist/maintenance/dm001-maintenance-risk.js +122 -0
- package/dist/maintenance/score.js +51 -0
- package/dist/maintenance/types.js +1 -0
- package/dist/osv/cache.js +49 -50
- package/dist/output/formatters.js +10 -4
- package/dist/output/html-reporter.js +163 -14
- package/dist/output/maintenance-findings-html.js +60 -0
- package/dist/output/maintenance-findings-json.js +3 -0
- package/dist/output/maintenance-findings-sarif.js +58 -0
- package/dist/output/maintenance-terminal.js +138 -0
- package/dist/output/multi-folder-html-reporter.js +61 -5
- package/dist/output/multi-folder-printer.js +11 -2
- package/dist/output/override-findings-html.js +22 -32
- package/dist/output/printers.js +95 -22
- package/dist/output/sarif.js +23 -7
- package/dist/output/spinner.js +5 -0
- package/dist/output/write-outputs.js +7 -2
- package/dist/parsers/bun-lock.js +47 -7
- package/dist/parsers/npm-lock-graph.js +90 -12
- package/dist/parsers/pnpm-lock.js +42 -6
- package/dist/parsers/utils.js +0 -15
- package/dist/parsers/yarn-lock.js +140 -58
- package/dist/remediation/cooldown.js +74 -0
- package/dist/remediation/fix-commands.js +42 -2
- package/dist/remediation/npm-registry.js +70 -42
- package/dist/remediation/parent-upgrade.js +114 -18
- package/dist/scan/completeness.js +49 -0
- package/dist/scan/multi-folder-scan.js +193 -13
- package/dist/scanner.js +284 -165
- package/dist/usage/scanner.js +12 -2
- package/dist/utils/network.js +66 -0
- package/dist/utils/vuln.js +16 -0
- package/package.json +2 -2
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { chalk } from "../utils/chalk.js";
|
|
2
|
+
import { formatSeverityLabel, SEVERITY_ORDER } from "../utils/severity.js";
|
|
3
|
+
import { pluralize } from "../utils/string.js";
|
|
4
|
+
const COL_RULE_MAX = 8;
|
|
5
|
+
const COL_PKG_MAX = 30;
|
|
6
|
+
const COL_DET_MAX = 60;
|
|
7
|
+
function pad(s, width) {
|
|
8
|
+
if (s.length >= width)
|
|
9
|
+
return s.slice(0, width);
|
|
10
|
+
return s + " ".repeat(width - s.length);
|
|
11
|
+
}
|
|
12
|
+
function truncate(s, max) {
|
|
13
|
+
return s.length > max ? s.slice(0, max - 1) + "…" : s;
|
|
14
|
+
}
|
|
15
|
+
// Word-wrap a detail line to the column width so the actionable tail (e.g. the
|
|
16
|
+
// "- upgrade to X" target) spills onto a continuation row instead of truncating
|
|
17
|
+
// to a useless "upgrade to 1…". A single word longer than the width is hard-broken.
|
|
18
|
+
function wrap(text, width) {
|
|
19
|
+
const out = [];
|
|
20
|
+
let line = "";
|
|
21
|
+
for (const word of text.split(" ")) {
|
|
22
|
+
let w = word;
|
|
23
|
+
while (w.length > width) {
|
|
24
|
+
if (line.length > 0) {
|
|
25
|
+
out.push(line);
|
|
26
|
+
line = "";
|
|
27
|
+
}
|
|
28
|
+
out.push(w.slice(0, width));
|
|
29
|
+
w = w.slice(width);
|
|
30
|
+
}
|
|
31
|
+
if (w.length === 0) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (line.length === 0) {
|
|
35
|
+
line = w;
|
|
36
|
+
}
|
|
37
|
+
else if (line.length + 1 + w.length <= width) {
|
|
38
|
+
line += " " + w;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
out.push(line);
|
|
42
|
+
line = w;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (line.length > 0) {
|
|
46
|
+
out.push(line);
|
|
47
|
+
}
|
|
48
|
+
return out.length > 0 ? out : [""];
|
|
49
|
+
}
|
|
50
|
+
// Terminal only: reduce a freeform npm deprecation message for a width-capped box
|
|
51
|
+
// cell. Strip URLs (they truncate to a useless "https://gi…"; the full message and
|
|
52
|
+
// URL are kept in the HTML/JSON/SARIF outputs), and only surface the remaining text
|
|
53
|
+
// when it carries actionable guidance - a "use X instead" replacement. A generic
|
|
54
|
+
// "<pkg> has been deprecated" adds nothing over the bare flag.
|
|
55
|
+
function formatDeprecationFlag(message) {
|
|
56
|
+
const cleaned = message
|
|
57
|
+
.replace(/https?:\/\/\S+/g, "")
|
|
58
|
+
.replace(/[,;]?\s*(see|at)\s*$/i, "")
|
|
59
|
+
.replace(/\s+/g, " ")
|
|
60
|
+
.trim()
|
|
61
|
+
.replace(/[.,;:]+$/, "");
|
|
62
|
+
const hasGuidance = /\b(instead|use\s|replaced|migrate|switch to)\b/i.test(cleaned);
|
|
63
|
+
if (hasGuidance && cleaned.length > 0) {
|
|
64
|
+
return `Deprecated: ${cleaned}`;
|
|
65
|
+
}
|
|
66
|
+
return "Deprecated";
|
|
67
|
+
}
|
|
68
|
+
function buildDetailLines(finding) {
|
|
69
|
+
const lines = [];
|
|
70
|
+
for (const d of finding.drag ?? []) {
|
|
71
|
+
lines.push(`Drags ${d.constrainedPackage}@${d.installedVersion} below fix ${d.fixVersion} - upgrade to ${d.parentTargetVersion}`);
|
|
72
|
+
}
|
|
73
|
+
if (finding.deprecated) {
|
|
74
|
+
lines.push(formatDeprecationFlag(finding.deprecated.message));
|
|
75
|
+
}
|
|
76
|
+
if (finding.staleness) {
|
|
77
|
+
const year = new Date(finding.staleness.lastPublish).getUTCFullYear();
|
|
78
|
+
lines.push(`Last release: ${year} (${finding.staleness.ageYears} years ago)`);
|
|
79
|
+
}
|
|
80
|
+
if (lines.length === 0) {
|
|
81
|
+
lines.push(finding.message);
|
|
82
|
+
}
|
|
83
|
+
return lines;
|
|
84
|
+
}
|
|
85
|
+
export function renderMaintenanceFindings(findings, options) {
|
|
86
|
+
const lines = [];
|
|
87
|
+
if (options?.verbose) {
|
|
88
|
+
lines.push(chalk.bold.cyan("🔧 Maintenance Risk"));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
lines.push("────────────────────────────────");
|
|
92
|
+
lines.push(chalk.bold("🔧 Maintenance Risk"));
|
|
93
|
+
lines.push("────────────────────────────────");
|
|
94
|
+
}
|
|
95
|
+
lines.push("");
|
|
96
|
+
if (findings.length === 0) {
|
|
97
|
+
lines.push(chalk.greenBright("✔ No maintenance risk findings."));
|
|
98
|
+
return lines.join("\n");
|
|
99
|
+
}
|
|
100
|
+
const grouped = new Map();
|
|
101
|
+
for (const sev of SEVERITY_ORDER)
|
|
102
|
+
grouped.set(sev, []);
|
|
103
|
+
for (const f of findings)
|
|
104
|
+
grouped.get(f.severity)?.push(f);
|
|
105
|
+
for (const sev of SEVERITY_ORDER) {
|
|
106
|
+
const bucket = grouped.get(sev) ?? [];
|
|
107
|
+
if (bucket.length === 0)
|
|
108
|
+
continue;
|
|
109
|
+
lines.push(`${formatSeverityLabel(sev.toUpperCase())} (${bucket.length})`);
|
|
110
|
+
const sorted = [...bucket].sort((a, b) => a.package.name.localeCompare(b.package.name));
|
|
111
|
+
const detailsByFinding = sorted.map(f => buildDetailLines(f).flatMap(l => wrap(l, COL_DET_MAX)));
|
|
112
|
+
const allDetailLines = detailsByFinding.flat();
|
|
113
|
+
const pkgWidth = Math.min(COL_PKG_MAX, Math.max(7, ...sorted.map(f => `${f.package.name}@${f.package.version}`.length)));
|
|
114
|
+
const detWidth = Math.min(COL_DET_MAX, Math.max(7, ...allDetailLines.map(l => l.length)));
|
|
115
|
+
const ruleWidth = COL_RULE_MAX;
|
|
116
|
+
const hr = (l, m, r) => l + "─".repeat(ruleWidth + 2) + m + "─".repeat(pkgWidth + 2) + m + "─".repeat(detWidth + 2) + r;
|
|
117
|
+
const row = (rule, pkg, det) => `│ ${pad(rule, ruleWidth)} │ ${pad(pkg, pkgWidth)} │ ${pad(det, detWidth)} │`;
|
|
118
|
+
lines.push(hr("┌", "┬", "┐"));
|
|
119
|
+
lines.push(row("Rule", "Package", "Details"));
|
|
120
|
+
lines.push(hr("├", "┼", "┤"));
|
|
121
|
+
sorted.forEach((finding, idx) => {
|
|
122
|
+
const pkgLabel = truncate(`${finding.package.name}@${finding.package.version}`, pkgWidth);
|
|
123
|
+
const detailLines = detailsByFinding[idx] ?? [];
|
|
124
|
+
lines.push(row("DM001", pkgLabel, detailLines[0] ?? ""));
|
|
125
|
+
for (let i = 1; i < detailLines.length; i++) {
|
|
126
|
+
lines.push(row("", "", detailLines[i] ?? ""));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
lines.push(hr("└", "┴", "┘"));
|
|
130
|
+
lines.push("");
|
|
131
|
+
}
|
|
132
|
+
const worstSev = SEVERITY_ORDER.find(s => (grouped.get(s) ?? []).length > 0);
|
|
133
|
+
const footerColor = worstSev === "critical" || worstSev === "high" ? chalk.redBright : chalk.yellow;
|
|
134
|
+
lines.push(footerColor(`${findings.length} maintenance risk ${pluralize(findings.length, "issue")} found.`));
|
|
135
|
+
lines.push("");
|
|
136
|
+
lines.push(chalk.gray("────────────────────────────────"));
|
|
137
|
+
return lines.join("\n");
|
|
138
|
+
}
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { aggregateMultiFolderCompleteness } from "../scan/completeness.js";
|
|
4
|
+
import { REPORT_STYLES, escapeHtml, openInBrowser, renderFindingRow, renderFixPlan, renderCompletenessBanner, serializeHtmlFinding, } from "./html-reporter.js";
|
|
5
|
+
import { renderOverrideFindingsHtml } from "./override-findings-html.js";
|
|
6
|
+
import { renderMaintenanceFindingsHtml } from "./maintenance-findings-html.js";
|
|
4
7
|
import { loadLogoDataUri } from "./logos.js";
|
|
5
8
|
import { pluralize } from "../utils/string.js";
|
|
9
|
+
export function buildMultiFolderReportData(params) {
|
|
10
|
+
const findings = params.results.flatMap((r, i) => params.serializedByFolder[i].map(f => ({
|
|
11
|
+
...f,
|
|
12
|
+
subfolder: r.subfolder,
|
|
13
|
+
})));
|
|
14
|
+
return {
|
|
15
|
+
multiFolder: true,
|
|
16
|
+
projectPath: params.projectPath,
|
|
17
|
+
scannedAt: new Date().toISOString(),
|
|
18
|
+
cliVersion: params.cliVersion,
|
|
19
|
+
folders: params.results.map(r => r.subfolder),
|
|
20
|
+
findings,
|
|
21
|
+
...(params.includeOverrides
|
|
22
|
+
? {
|
|
23
|
+
overrideFindings: params.results.flatMap(r => r.overrideFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
24
|
+
}
|
|
25
|
+
: {}),
|
|
26
|
+
...(params.includeMaintenance
|
|
27
|
+
? {
|
|
28
|
+
maintenanceFindings: params.results.flatMap(r => r.maintenanceFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
29
|
+
}
|
|
30
|
+
: {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
6
33
|
function summaryCounts(results) {
|
|
7
34
|
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
|
|
8
35
|
for (const r of results) {
|
|
@@ -23,7 +50,7 @@ function renderFolderNotices(coverage) {
|
|
|
23
50
|
<div class="scan-notes-body"><ul>${items}</ul></div>
|
|
24
51
|
</div>`;
|
|
25
52
|
}
|
|
26
|
-
function renderFolderSection(result, folderIdx, idxOffset, serialized) {
|
|
53
|
+
function renderFolderSection(result, folderIdx, idxOffset, serialized, projectRoot, includeOverrides, includeMaintenance) {
|
|
27
54
|
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0 };
|
|
28
55
|
for (const f of result.sorted) {
|
|
29
56
|
const sev = f.severity;
|
|
@@ -40,16 +67,28 @@ function renderFolderSection(result, folderIdx, idxOffset, serialized) {
|
|
|
40
67
|
const findingRowsHtml = serialized.map((f, i) => renderFindingRow(f, idxOffset + i)).join("\n");
|
|
41
68
|
const fixPlanHtml = renderFixPlan(result.suggestedFixCommands);
|
|
42
69
|
const noticesHtml = renderFolderNotices(result.coverage);
|
|
70
|
+
const completenessBannerHtml = renderCompletenessBanner(result.completeness);
|
|
71
|
+
const folderAbs = path.join(projectRoot, result.subfolder);
|
|
72
|
+
const overrideHtml = includeOverrides
|
|
73
|
+
? renderOverrideFindingsHtml(result.overrideFindings, folderAbs)
|
|
74
|
+
: "";
|
|
75
|
+
const maintenanceHtml = includeMaintenance
|
|
76
|
+
? renderMaintenanceFindingsHtml(result.maintenanceFindings)
|
|
77
|
+
: "";
|
|
43
78
|
const emptyRow = result.sorted.length === 0
|
|
44
79
|
? `<tr><td colspan="6" style="text-align:center;padding:24px;color:#8b949e">No findings</td></tr>`
|
|
45
80
|
: "";
|
|
46
81
|
return `
|
|
47
82
|
<details class="folder-section"${isOpen ? " open" : ""}>
|
|
48
83
|
<summary class="folder-summary">
|
|
84
|
+
<svg class="chevron" width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
85
|
+
<path fill-rule="evenodd" d="M6.22 3.22a.75.75 0 011.06 0l4.25 4.25a.75.75 0 010 1.06l-4.25 4.25a.75.75 0 01-1.06-1.06L9.94 8 6.22 4.28a.75.75 0 010-1.06z"></path>
|
|
86
|
+
</svg>
|
|
49
87
|
<span class="folder-name">${escapeHtml(result.subfolder)}/</span>
|
|
50
88
|
<span class="folder-counts">${escapeHtml(summaryText)}</span>
|
|
51
89
|
</summary>
|
|
52
90
|
<div class="folder-body">
|
|
91
|
+
${completenessBannerHtml}
|
|
53
92
|
${fixPlanHtml}
|
|
54
93
|
${noticesHtml}
|
|
55
94
|
<div class="findings-section" style="margin:16px 32px 32px">
|
|
@@ -83,6 +122,8 @@ function renderFolderSection(result, folderIdx, idxOffset, serialized) {
|
|
|
83
122
|
</tbody>
|
|
84
123
|
</table>
|
|
85
124
|
</div>
|
|
125
|
+
${overrideHtml}
|
|
126
|
+
${maintenanceHtml}
|
|
86
127
|
</div>
|
|
87
128
|
</details>`;
|
|
88
129
|
}
|
|
@@ -94,8 +135,18 @@ export async function writeMultiFolderHtmlReport(params) {
|
|
|
94
135
|
const totalFindings = params.results.reduce((sum, r) => sum + r.sorted.length, 0);
|
|
95
136
|
const totalCVEs = params.results.reduce((sum, r) => sum + r.sorted.reduce((s, f) => s + f.cveAliases.length, 0), 0);
|
|
96
137
|
const folderCount = params.results.length;
|
|
138
|
+
const aggregateCompleteness = aggregateMultiFolderCompleteness(params.results);
|
|
139
|
+
const aggregateBannerHtml = renderCompletenessBanner(aggregateCompleteness);
|
|
97
140
|
// Pre-serialize findings once per folder for both HTML rendering and JS filter/sort
|
|
98
141
|
const allSerialized = params.results.map(r => r.sorted.map(f => serializeHtmlFinding(f, r.suggestedFixCommands)));
|
|
142
|
+
const reportData = buildMultiFolderReportData({
|
|
143
|
+
results: params.results,
|
|
144
|
+
serializedByFolder: allSerialized,
|
|
145
|
+
projectPath: params.projectPath,
|
|
146
|
+
cliVersion: params.cliVersion,
|
|
147
|
+
includeOverrides: params.includeOverrides,
|
|
148
|
+
includeMaintenance: params.includeMaintenance,
|
|
149
|
+
});
|
|
99
150
|
// Compact per-folder findings for JavaScript (only fields needed for filter/sort/search)
|
|
100
151
|
const folderFindingsJson = JSON.stringify(allSerialized.map(findings => findings.map(f => ({
|
|
101
152
|
package: f.package,
|
|
@@ -111,7 +162,7 @@ export async function writeMultiFolderHtmlReport(params) {
|
|
|
111
162
|
let idxOffset = 0;
|
|
112
163
|
const folderSectionsHtml = params.results
|
|
113
164
|
.map((r, fi) => {
|
|
114
|
-
const html = renderFolderSection(r, fi, idxOffset, allSerialized[fi]);
|
|
165
|
+
const html = renderFolderSection(r, fi, idxOffset, allSerialized[fi], params.projectPath, params.includeOverrides, params.includeMaintenance);
|
|
115
166
|
idxOffset += r.sorted.length;
|
|
116
167
|
return html;
|
|
117
168
|
})
|
|
@@ -129,12 +180,13 @@ ${REPORT_STYLES}
|
|
|
129
180
|
.folder-section{margin:0 32px 16px;background:#161b22;border:1px solid #30363d;border-radius:8px;overflow:hidden}
|
|
130
181
|
.folder-summary{display:flex;align-items:center;gap:12px;padding:12px 18px;cursor:pointer;user-select:none;list-style:none;background:#1c2128;border-bottom:1px solid #30363d}
|
|
131
182
|
.folder-summary::-webkit-details-marker{display:none}
|
|
132
|
-
.folder-summary
|
|
133
|
-
details[open] .folder-summary
|
|
183
|
+
.folder-summary .chevron{transition:transform .15s;flex-shrink:0;color:#8b949e}
|
|
184
|
+
details[open] > .folder-summary .chevron{transform:rotate(90deg)}
|
|
134
185
|
.folder-name{font-size:13px;font-weight:600;color:#e6edf3;font-family:'SF Mono','Cascadia Code','Fira Code',monospace}
|
|
135
186
|
.folder-counts{font-size:11px;color:#8b949e;margin-left:auto}
|
|
136
187
|
.folder-body{padding:0}
|
|
137
188
|
.folder-body .fix-plan{margin:24px 32px 0}
|
|
189
|
+
.folder-body .override-hygiene,.folder-body .maintenance-risk{margin:0 32px 24px}
|
|
138
190
|
</style>
|
|
139
191
|
</head>
|
|
140
192
|
<body>
|
|
@@ -178,6 +230,8 @@ details[open] .folder-summary::before{transform:rotate(90deg)}
|
|
|
178
230
|
<div class="sev-card total"><span class="count">${totalCVEs}</span><span class="label">CVEs</span></div>
|
|
179
231
|
</div>
|
|
180
232
|
|
|
233
|
+
${aggregateBannerHtml}
|
|
234
|
+
|
|
181
235
|
${folderSectionsHtml}
|
|
182
236
|
|
|
183
237
|
<div class="report-footer">
|
|
@@ -314,6 +368,8 @@ document.addEventListener('click', function(e) {
|
|
|
314
368
|
</body>
|
|
315
369
|
</html>`;
|
|
316
370
|
const indexPath = path.join(params.outputDir, "index.html");
|
|
371
|
+
const jsonPath = path.join(params.outputDir, "report.json");
|
|
372
|
+
fs.writeFileSync(jsonPath, JSON.stringify(reportData, null, 2), "utf8");
|
|
317
373
|
fs.writeFileSync(indexPath, html, "utf8");
|
|
318
374
|
if (params.autoOpen)
|
|
319
375
|
openInBrowser(indexPath);
|
|
@@ -30,17 +30,26 @@ export function printMultiFolderResults(results, options) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
printCoverage([...result.scanInput.notes, ...result.coverage]);
|
|
33
|
-
printFinalStatus(result.sorted);
|
|
33
|
+
printFinalStatus(result.sorted, 0, result.completeness);
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
printCompactOutput(result.sorted, result.scanInput, { offline, all: !!options.all, subfolder: result.subfolder });
|
|
36
|
+
printCompactOutput(result.sorted, result.scanInput, { offline, all: !!options.all, subfolder: result.subfolder, completeness: result.completeness });
|
|
37
37
|
}
|
|
38
38
|
if (i < results.length - 1) {
|
|
39
39
|
console.log(chalk.gray("\n" + "─".repeat(50)));
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
const totalFindings = results.reduce((sum, r) => sum + r.sorted.length, 0);
|
|
43
|
+
const totalSuppressed = results.reduce((sum, r) => sum + (r.suppressedCount ?? 0), 0);
|
|
43
44
|
const folderNames = results.map(r => `${r.subfolder}/`).join(", ");
|
|
44
45
|
console.log(chalk.gray(`\nScanned ${results.length} ${pluralize(results.length, "folder")}: ${folderNames}`));
|
|
45
46
|
console.log(chalk.gray(`${totalFindings} total ${pluralize(totalFindings, "finding")} across all folders`));
|
|
47
|
+
if (totalSuppressed > 0) {
|
|
48
|
+
if (totalFindings === 0) {
|
|
49
|
+
console.log(chalk.green(`No new findings above baseline - ${totalSuppressed} existing ${pluralize(totalSuppressed, "finding")} suppressed`));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log(chalk.yellow(`${totalFindings} new ${pluralize(totalFindings, "finding")} above baseline - ${totalSuppressed} existing ${pluralize(totalSuppressed, "finding")} suppressed`));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
46
55
|
}
|
|
@@ -22,43 +22,33 @@ export function renderOverrideFindingsHtml(findings, projectPath) {
|
|
|
22
22
|
</section>
|
|
23
23
|
`;
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
? `<div class="fix-cmd-inline" style="margin-top:6px"><code>${esc(runnableCmd)}</code><button class="copy-btn" data-cmd="${esc(runnableCmd)}">Copy</button></div>`
|
|
47
|
-
: "";
|
|
48
|
-
rows.push(` <tr class="finding ${esc(f.severity)}">` +
|
|
49
|
-
`<td>${esc(f.ruleId)}</td>` +
|
|
50
|
-
`<td>${esc(f.package.name)}</td>` +
|
|
51
|
-
`<td>${location}</td>` +
|
|
52
|
-
`<td>${esc(f.message)}${fixHtml}</td>` +
|
|
53
|
-
`</tr>`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
25
|
+
const sorted = [...findings].sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity));
|
|
26
|
+
const rows = sorted.map(f => {
|
|
27
|
+
const location = f.location.jsonPath
|
|
28
|
+
? `${esc(f.location.file)} › ${esc(f.location.jsonPath)}`
|
|
29
|
+
: esc(f.location.file);
|
|
30
|
+
const relPath = projectPath ? relative(process.cwd(), projectPath) : "";
|
|
31
|
+
const projectInfix = relPath && relPath !== "." ? ` ${relPath}` : "";
|
|
32
|
+
const runnableCmd = f.fix?.runnableCommand && projectInfix
|
|
33
|
+
? f.fix.runnableCommand.replace("cve-lite overrides", `cve-lite${projectInfix} overrides`)
|
|
34
|
+
: f.fix?.runnableCommand;
|
|
35
|
+
const fixHtml = runnableCmd
|
|
36
|
+
? `<div class="fix-cmd-inline" style="margin-top:6px"><code>${esc(runnableCmd)}</code><button class="copy-btn" data-cmd="${esc(runnableCmd)}">Copy</button></div>`
|
|
37
|
+
: "";
|
|
38
|
+
return (` <tr class="finding ${esc(f.severity)}">` +
|
|
39
|
+
`<td><span class="dep-node">${esc(f.ruleId)}</span></td>` +
|
|
40
|
+
`<td><div class="pkg-name">${esc(f.package.name)}</div></td>` +
|
|
41
|
+
`<td><span class="sev-badge ${esc(f.severity)}">${esc(f.severity)}</span></td>` +
|
|
42
|
+
`<td>${location}</td>` +
|
|
43
|
+
`<td>${esc(f.message)}${fixHtml}</td>` +
|
|
44
|
+
`</tr>`);
|
|
45
|
+
});
|
|
56
46
|
return `
|
|
57
47
|
<section class="override-hygiene">
|
|
58
48
|
<h2>Override hygiene</h2>
|
|
59
49
|
<table>
|
|
60
50
|
<thead>
|
|
61
|
-
<tr><th>Rule</th><th>Package</th><th>Location</th><th>Message</th></tr>
|
|
51
|
+
<tr><th>Rule</th><th>Package</th><th>Severity</th><th>Location</th><th>Message</th></tr>
|
|
62
52
|
</thead>
|
|
63
53
|
<tbody>
|
|
64
54
|
${rows.join("\n")}
|
package/dist/output/printers.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { chalk, stripAnsi } from "../utils/chalk.js";
|
|
2
|
-
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
2
|
+
import { buildSuggestedFixCommandPlan, UNVERIFIED_PARENT_UPGRADE_NOTE } from "../remediation/fix-commands.js";
|
|
3
3
|
import { isMajorVersionBump } from "../utils/version.js";
|
|
4
4
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
5
|
-
import { countUniqueAdvisories, formatRelationshipLabel, formatRelLabel, formatFixCommandWithPublishDates, } from "./formatters.js";
|
|
5
|
+
import { countUniqueAdvisories, formatRelationshipLabel, formatRelLabel, formatFixCommandWithPublishDates, formatCooldownWarning, } from "./formatters.js";
|
|
6
6
|
import { formatSeverityLabel } from "../utils/severity.js";
|
|
7
7
|
import { pluralize } from "../utils/string.js";
|
|
8
|
+
import { hasMaliciousAdvisory } from "../utils/vuln.js";
|
|
8
9
|
import { selectFindingsForCompact } from "./finding-display.js";
|
|
10
|
+
import { getCompletenessImpact } from "../scan/completeness.js";
|
|
9
11
|
import { MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE, MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, MAL_GIT_SOURCE_COMPACT_MESSAGE, MAL_GIT_SOURCE_LEGEND_MESSAGE, MAL_GIT_SOURCE_PINNED_DISPLAY, MAL_GIT_SOURCE_FLOATING_DISPLAY, } from "../constants.js";
|
|
10
12
|
export function printSummary(findings, packageCount, scanInput) {
|
|
11
13
|
if (findings.length === 0) {
|
|
@@ -56,6 +58,16 @@ export function printActionSummary(findings, overrideCount = 0, packageManager)
|
|
|
56
58
|
console.log(`- ${chalk.yellow(String(overrideCount))} override hygiene ${pluralize(overrideCount, "issue")} found. Run ${chalk.white("cve-lite overrides --fix")} to address ${pluralize(overrideCount, "it", "them")}.`);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
61
|
+
function printCooldownWarning(target) {
|
|
62
|
+
if (target.cooldownWarning) {
|
|
63
|
+
console.log(chalk.yellow(` ⚠ ${formatCooldownWarning(target.cooldownWarning)}`));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function printUnverifiedParentUpgradeWarning(target) {
|
|
67
|
+
if (target.confidence === "unverified") {
|
|
68
|
+
console.log(chalk.yellow(` ${UNVERIFIED_PARENT_UPGRADE_NOTE}`));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
59
71
|
function printChainProofLines(targets) {
|
|
60
72
|
for (const target of targets) {
|
|
61
73
|
if (!target.chainProof || !target.chainSafeVersion)
|
|
@@ -112,6 +124,10 @@ export function printSuggestedFixCommands(findings, scanInput, options) {
|
|
|
112
124
|
else if (shouldRenderParentUpgradeTable(section.targets)) {
|
|
113
125
|
printParentUpgradeTargetsTable(section.targets, sharedParentUpgradeTableWidths);
|
|
114
126
|
}
|
|
127
|
+
for (const target of section.targets) {
|
|
128
|
+
printCooldownWarning(target);
|
|
129
|
+
printUnverifiedParentUpgradeWarning(target);
|
|
130
|
+
}
|
|
115
131
|
console.log(renderCommandCallout(section.command, section.targets));
|
|
116
132
|
printChainProofLines(section.targets);
|
|
117
133
|
}
|
|
@@ -198,7 +214,7 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
198
214
|
else if (f.maliciousGitSource) {
|
|
199
215
|
fixedDisplay = chalk.yellow(f.maliciousGitSourcePinned ? MAL_GIT_SOURCE_PINNED_DISPLAY : MAL_GIT_SOURCE_FLOATING_DISPLAY);
|
|
200
216
|
}
|
|
201
|
-
else if (f.vulnerabilities
|
|
217
|
+
else if (hasMaliciousAdvisory(f.vulnerabilities)) {
|
|
202
218
|
fixedDisplay = chalk.yellow("⚠ Malicious");
|
|
203
219
|
}
|
|
204
220
|
else {
|
|
@@ -243,7 +259,7 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
243
259
|
console.log(renderRow(decorated, widths));
|
|
244
260
|
}
|
|
245
261
|
console.log(line("└", "┴", "┘"));
|
|
246
|
-
const maliciousFindings = findings.filter(f => f.vulnerabilities
|
|
262
|
+
const maliciousFindings = findings.filter(f => hasMaliciousAdvisory(f.vulnerabilities));
|
|
247
263
|
if (maliciousFindings.length > 0) {
|
|
248
264
|
console.log("");
|
|
249
265
|
console.log(chalk.bold.red("⚠ Malicious package advisory:"));
|
|
@@ -271,28 +287,49 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
271
287
|
console.log(chalk.gray("Tip: use --all to include low findings, or --min-severity high to focus only on urgent issues."));
|
|
272
288
|
}
|
|
273
289
|
}
|
|
274
|
-
export function printFinalStatus(findings, overrideCount = 0) {
|
|
290
|
+
export function printFinalStatus(findings, overrideCount = 0, completeness) {
|
|
275
291
|
console.log("");
|
|
276
292
|
console.log(chalk.gray("────────────────────────────────"));
|
|
293
|
+
const { hasDetectionGap, hasRemediationGap } = getCompletenessImpact(completeness);
|
|
277
294
|
const overrideSuffix = overrideCount > 0
|
|
278
295
|
? `, ${overrideCount} override hygiene ${pluralize(overrideCount, "issue")}`
|
|
279
296
|
: "";
|
|
280
297
|
if (findings.length === 0) {
|
|
281
|
-
if (
|
|
298
|
+
if (hasDetectionGap) {
|
|
299
|
+
const overrideNote = overrideCount > 0
|
|
300
|
+
? ` ${overrideCount} override hygiene ${pluralize(overrideCount, "issue")} detected.`
|
|
301
|
+
: "";
|
|
302
|
+
console.log(chalk.yellow(`⚠ Partial scan: vulnerability findings may be incomplete.${overrideNote}`));
|
|
303
|
+
}
|
|
304
|
+
else if (overrideCount > 0) {
|
|
282
305
|
console.log(chalk.yellow(`▲ Scan complete. No known vulnerabilities found, but ${overrideCount} override hygiene ${pluralize(overrideCount, "issue")} detected.`));
|
|
283
306
|
}
|
|
284
307
|
else {
|
|
285
308
|
console.log(chalk.greenBright("✔ Scan complete. No known vulnerabilities found."));
|
|
286
309
|
}
|
|
287
|
-
return;
|
|
288
310
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
311
|
+
else {
|
|
312
|
+
const criticalCount = findings.filter(f => f.severity === "critical").length;
|
|
313
|
+
const highCount = findings.filter(f => f.severity === "high").length;
|
|
314
|
+
const urgent = criticalCount > 0 || highCount > 0;
|
|
315
|
+
const label = `${findings.length} ${pluralize(findings.length, "vulnerability", "vulnerabilities")}`;
|
|
316
|
+
if (hasDetectionGap) {
|
|
317
|
+
const severityNote = urgent ? ` (${criticalCount} critical, ${highCount} high)` : "";
|
|
318
|
+
const action = urgent ? "Start with the priority fixes above." : "Review the suggested fix plan above.";
|
|
319
|
+
const renderStatus = urgent ? chalk.redBright : chalk.yellow;
|
|
320
|
+
console.log(renderStatus(`⚠ Partial scan: ${label} found${overrideSuffix}${severityNote}. Vulnerability findings may be incomplete. ${action}`));
|
|
321
|
+
}
|
|
322
|
+
else if (urgent) {
|
|
323
|
+
console.log(chalk.redBright(`✖ Scan complete. ${label}${overrideSuffix} found (${criticalCount} critical, ${highCount} high). Start with the priority fixes above.`));
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
console.log(chalk.yellow(`▲ Scan complete. ${label}${overrideSuffix} found. Review the suggested fix plan above.`));
|
|
327
|
+
}
|
|
294
328
|
}
|
|
295
|
-
|
|
329
|
+
if (hasRemediationGap) {
|
|
330
|
+
console.log(chalk.yellow("⚠ Remediation guidance is incomplete."));
|
|
331
|
+
}
|
|
332
|
+
printIncompleteDiagnostics(completeness);
|
|
296
333
|
}
|
|
297
334
|
export function printOverrideHint() {
|
|
298
335
|
console.log("💡 " + chalk.gray("Tip:") + " override entries detected - run with --check-overrides to audit them for stale or broken overrides.");
|
|
@@ -347,12 +384,26 @@ function wrapCell(value, width) {
|
|
|
347
384
|
}
|
|
348
385
|
export function printCompactOutput(findings, scanInput, options) {
|
|
349
386
|
console.log("");
|
|
387
|
+
const { hasDetectionGap, hasRemediationGap } = getCompletenessImpact(options?.completeness);
|
|
350
388
|
if (options?.packageManager) {
|
|
351
389
|
console.log(chalk.gray("Package manager: ") + options.packageManager);
|
|
352
390
|
}
|
|
353
391
|
if (findings.length === 0) {
|
|
354
|
-
|
|
355
|
-
|
|
392
|
+
if (hasDetectionGap) {
|
|
393
|
+
console.log(chalk.yellow("⚠ Partial scan: vulnerability findings may be incomplete."));
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
console.log(chalk.greenBright("✔ Scan complete. No known vulnerabilities found."));
|
|
397
|
+
}
|
|
398
|
+
if (hasRemediationGap) {
|
|
399
|
+
console.log(chalk.yellow("⚠ Remediation guidance is incomplete."));
|
|
400
|
+
}
|
|
401
|
+
if (options?.completeness?.complete === false) {
|
|
402
|
+
printIncompleteDiagnostics(options.completeness);
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
console.log("");
|
|
406
|
+
}
|
|
356
407
|
return;
|
|
357
408
|
}
|
|
358
409
|
// Vulnerabilities found section
|
|
@@ -380,7 +431,7 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
380
431
|
}
|
|
381
432
|
console.log(`${formatSeverityLabel(sevLabel)} ${chalk.whiteBright(finding.pkg.name)}@${finding.pkg.version}`);
|
|
382
433
|
console.log(` ${typeLabel}${usageContext}`);
|
|
383
|
-
const isMalicious = finding.vulnerabilities
|
|
434
|
+
const isMalicious = hasMaliciousAdvisory(finding.vulnerabilities);
|
|
384
435
|
if (isMalicious) {
|
|
385
436
|
if (finding.maliciousUnverifiable) {
|
|
386
437
|
console.log(` ${chalk.yellow(`⚠ Unverifiable (private source) - ${MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE}`)}`);
|
|
@@ -446,12 +497,11 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
446
497
|
console.log("");
|
|
447
498
|
for (const section of plan.sections.slice(0, 3)) {
|
|
448
499
|
console.log(`${section.title}`);
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
if (!target.adjustmentNote)
|
|
452
|
-
continue;
|
|
500
|
+
for (const target of section.targets) {
|
|
501
|
+
if (section.kind === "direct-adjusted" && target.adjustmentNote) {
|
|
453
502
|
console.log(chalk.gray(` Note: ${target.adjustmentNote}`));
|
|
454
503
|
}
|
|
504
|
+
printCooldownWarning(target);
|
|
455
505
|
}
|
|
456
506
|
console.log(renderCommandCallout(section.command, section.targets));
|
|
457
507
|
printChainProofLines(section.targets);
|
|
@@ -493,7 +543,7 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
493
543
|
console.log(`${chalk.cyan(String(direct))} ${chalk.white("direct")}` +
|
|
494
544
|
`${chalk.gray(" · ")}` +
|
|
495
545
|
`${chalk.cyan(String(transitive))} ${chalk.white("transitive")}`);
|
|
496
|
-
const maliciousCompact = findings.filter(f => f.vulnerabilities
|
|
546
|
+
const maliciousCompact = findings.filter(f => hasMaliciousAdvisory(f.vulnerabilities));
|
|
497
547
|
if (maliciousCompact.length > 0 && !options?.all) {
|
|
498
548
|
console.log("");
|
|
499
549
|
console.log(chalk.bold.red("⚠ Malicious package advisory:"));
|
|
@@ -520,7 +570,14 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
520
570
|
}
|
|
521
571
|
// Footer
|
|
522
572
|
const urgentCount = counts.critical + counts.high;
|
|
523
|
-
if (
|
|
573
|
+
if (hasDetectionGap) {
|
|
574
|
+
const label = urgentCount > 0
|
|
575
|
+
? `${urgentCount} urgent ${pluralize(urgentCount, "issue")} found`
|
|
576
|
+
: `${findings.length} ${pluralize(findings.length, "issue")} found`;
|
|
577
|
+
const renderStatus = urgentCount > 0 ? chalk.redBright : chalk.yellow;
|
|
578
|
+
console.log(renderStatus(`⚠ Partial scan: ${label}. Vulnerability findings may be incomplete.`));
|
|
579
|
+
}
|
|
580
|
+
else if (urgentCount > 0) {
|
|
524
581
|
console.log(chalk.redBright(`✖ Scan complete. ${urgentCount} urgent ${pluralize(urgentCount, "issue")} found.`));
|
|
525
582
|
}
|
|
526
583
|
else {
|
|
@@ -529,7 +586,23 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
529
586
|
if (!options?.all) {
|
|
530
587
|
console.log(chalk.gray(`Run with ${chalk.whiteBright("--verbose")} for fix plan, paths, and full table.`));
|
|
531
588
|
}
|
|
589
|
+
if (hasRemediationGap) {
|
|
590
|
+
console.log(chalk.yellow("⚠ Remediation guidance is incomplete."));
|
|
591
|
+
}
|
|
592
|
+
printIncompleteDiagnostics(options?.completeness);
|
|
593
|
+
if (options?.completeness?.complete !== false) {
|
|
594
|
+
console.log("");
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
export function printIncompleteDiagnostics(completeness) {
|
|
598
|
+
if (!completeness || completeness.complete)
|
|
599
|
+
return;
|
|
532
600
|
console.log("");
|
|
601
|
+
for (const diag of completeness.diagnostics) {
|
|
602
|
+
const prefix = diag.impact === "detection" ? chalk.yellow(" ·") : chalk.gray(" ·");
|
|
603
|
+
console.log(prefix + " " + chalk.gray(diag.message));
|
|
604
|
+
}
|
|
605
|
+
console.log(chalk.gray(" Resolve the issues above and re-run the scan."));
|
|
533
606
|
}
|
|
534
607
|
function renderSeverityTable(counts) {
|
|
535
608
|
const labels = ["Critical", "High", "Medium", "Low", "Unknown"];
|