cve-lite-cli 1.28.0 → 1.30.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 +30 -4
- package/dist/advisory/osv-advisory-source.js +3 -0
- package/dist/cli/help.js +3 -2
- package/dist/cli/validate.js +6 -0
- package/dist/constants.js +1 -0
- package/dist/index.js +50 -7
- package/dist/maintenance/dm001-maintenance-risk.js +74 -15
- package/dist/maintenance/score.js +51 -0
- package/dist/output/formatters.js +21 -8
- package/dist/output/html-reporter.js +133 -12
- package/dist/output/maintenance-findings-html.js +4 -0
- package/dist/output/maintenance-findings-sarif.js +58 -0
- package/dist/output/maintenance-terminal.js +63 -5
- package/dist/output/multi-folder-html-reporter.js +64 -7
- package/dist/output/multi-folder-printer.js +11 -2
- package/dist/output/override-findings-html.js +6 -5
- package/dist/output/override-findings-terminal.js +2 -1
- package/dist/output/printers.js +92 -30
- package/dist/output/sarif.js +23 -7
- package/dist/output/write-outputs.js +4 -1
- package/dist/overrides/detectors/oa001-orphaned-target.js +2 -1
- package/dist/overrides/detectors/oa002-floating-tag.js +2 -1
- package/dist/overrides/detectors/oa003-wrong-section.js +2 -1
- package/dist/overrides/detectors/oa004-surpassed-pin.js +2 -1
- package/dist/overrides/detectors/oa005-nested-ineffective.js +2 -1
- package/dist/overrides/detectors/oa006-coupled-platform-binary.js +2 -1
- package/dist/overrides/detectors/oa007-frozen-latest.js +2 -1
- package/dist/overrides/detectors/oa009-stale-floor.js +2 -1
- package/dist/parsers/bun-lock.js +47 -7
- package/dist/parsers/npm-lock-graph.js +90 -12
- package/dist/parsers/pnpm-lock.js +60 -10
- package/dist/parsers/utils.js +0 -15
- package/dist/parsers/yarn-lock.js +140 -58
- package/dist/remediation/fix-commands.js +43 -12
- package/dist/remediation/npm-registry.js +69 -52
- package/dist/remediation/npm-transitive-resolution.js +5 -6
- package/dist/remediation/package-path-lookup.js +29 -0
- package/dist/remediation/parent-upgrade.js +2 -22
- package/dist/scan/completeness.js +49 -0
- package/dist/scan/multi-folder-scan.js +183 -15
- package/dist/scanner.js +210 -155
- package/dist/usage/scanner.js +12 -2
- package/dist/utils/finding.js +28 -0
- package/dist/utils/fix-runner.js +87 -50
- package/dist/utils/version.js +13 -4
- package/dist/utils/vuln.js +16 -0
- package/package.json +3 -3
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import process from "node:process";
|
|
3
4
|
import { EXIT_OK, EXIT_FINDINGS, EXIT_ERROR } from "../types.js";
|
|
4
5
|
import { loadMultiplePackages } from "../parsers/multi-package.js";
|
|
5
6
|
import { scanPackages, buildCoverageNotes } from "../scanner.js";
|
|
6
|
-
import { sortFindingsForOutput } from "../output/formatters.js";
|
|
7
|
+
import { sortFindingsForOutput, serializeFinding, logInfo } from "../output/formatters.js";
|
|
7
8
|
import { normalizeSeverity } from "../osv/severity.js";
|
|
8
9
|
import { selectFindingsForTable } from "../output/finding-display.js";
|
|
9
10
|
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
10
11
|
import { readDirectDependencyNames, hasOverrideEntries } from "../utils/package-json.js";
|
|
11
|
-
import { DEFAULT_SEARCH_DEPTH, severityOrder } from "../constants.js";
|
|
12
|
+
import { DEFAULT_SEARCH_DEPTH, severityOrder, OVERRIDES_COMMAND } from "../constants.js";
|
|
12
13
|
import { printMultiFolderResults } from "../output/multi-folder-printer.js";
|
|
13
14
|
import { printOverrideHint } from "../output/printers.js";
|
|
14
15
|
import { writeMultiFolderHtmlReport } from "../output/multi-folder-html-reporter.js";
|
|
@@ -18,6 +19,10 @@ import { buildOverrideContext, audit } from "../overrides/index.js";
|
|
|
18
19
|
import { NULL_AUDIT_LOG } from "../audit-log/index.js";
|
|
19
20
|
import { detectDM001 } from "../maintenance/dm001-maintenance-risk.js";
|
|
20
21
|
import { reachesFailOn } from "../utils/severity.js";
|
|
22
|
+
import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "../utils/baseline.js";
|
|
23
|
+
import { pluralize } from "../utils/string.js";
|
|
24
|
+
import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, } from "./completeness.js";
|
|
25
|
+
import { scanProjectForPackageUsage } from "../usage/scanner.js";
|
|
21
26
|
export async function runMultiFolderScan(params) {
|
|
22
27
|
const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
23
28
|
const folders = loadMultiplePackages(params.projectRoot, !!params.options.prodOnly, searchDepth);
|
|
@@ -26,36 +31,70 @@ export async function runMultiFolderScan(params) {
|
|
|
26
31
|
for (const { scanInput, subfolder } of folders) {
|
|
27
32
|
if (scanInput.packages.length === 0)
|
|
28
33
|
continue;
|
|
29
|
-
if (!params.options.json) {
|
|
34
|
+
if (!params.options.json && !params.options.ratchet) {
|
|
30
35
|
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${subfolder}/`)}\n`);
|
|
31
36
|
}
|
|
32
37
|
const subfolderAbs = path.join(params.projectRoot, subfolder);
|
|
33
38
|
const directDependencyNames = readDirectDependencyNames(subfolderAbs, !!params.options.prodOnly);
|
|
34
|
-
const findings = await scanPackages(scanInput.packages, params.batchSize, params.options, {
|
|
39
|
+
const { findings, completeness } = await scanPackages(scanInput.packages, params.batchSize, params.options, {
|
|
35
40
|
directDependencyNames,
|
|
36
41
|
scanSource: scanInput.source,
|
|
37
42
|
scanFilePath: scanInput.filePath,
|
|
38
43
|
}, undefined, params.fetchImpl);
|
|
39
|
-
|
|
44
|
+
// Mirror single-folder scanProject: annotate / filter by source imports per subfolder.
|
|
45
|
+
if (params.options.usage) {
|
|
46
|
+
logInfo(`Scanning ${subfolder}/ source for usage hints...`, params.options);
|
|
47
|
+
const pkgNames = new Set(findings.map(f => f.pkg.name));
|
|
48
|
+
const usageData = scanProjectForPackageUsage(subfolderAbs, pkgNames);
|
|
49
|
+
for (const finding of findings) {
|
|
50
|
+
const files = usageData[finding.pkg.name];
|
|
51
|
+
if (files) {
|
|
52
|
+
finding.usage = {
|
|
53
|
+
imported: files.length > 0,
|
|
54
|
+
files,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let finalFindings = findings;
|
|
60
|
+
if (params.options.onlyUsed) {
|
|
61
|
+
finalFindings = finalFindings.filter(f => f.usage?.imported);
|
|
62
|
+
}
|
|
63
|
+
let sorted = sortFindingsForOutput(finalFindings);
|
|
64
|
+
let suppressedCount = 0;
|
|
65
|
+
// Non-ratchet: auto-apply an existing per-folder baseline before fix plan,
|
|
66
|
+
// table selection, and maintenance (mirrors single-folder index.ts).
|
|
67
|
+
// --ratchet keeps the full set so handleMultiFolderScan can save or gate.
|
|
68
|
+
if (!params.options.ratchet) {
|
|
69
|
+
const baseline = readBaseline(subfolderAbs);
|
|
70
|
+
if (baseline) {
|
|
71
|
+
const filtered = filterNewFindings(sorted, baseline);
|
|
72
|
+
sorted = filtered.newFindings;
|
|
73
|
+
suppressedCount = filtered.suppressedCount;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
40
76
|
const coverage = buildCoverageNotes(scanInput, offline);
|
|
41
77
|
const minSeverity = normalizeSeverity(params.options.minSeverity || "medium");
|
|
42
78
|
const tableFindings = params.options.all ? sorted : selectFindingsForTable(sorted, minSeverity);
|
|
43
79
|
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, scanInput, { offline, subfolder });
|
|
44
|
-
// Override hygiene
|
|
80
|
+
// Override hygiene is independent of the CVE ratchet/baseline. A --ratchet
|
|
81
|
+
// run skips the override audit entirely (same boundary as single-folder).
|
|
45
82
|
let overrideFindings = [];
|
|
46
|
-
if (params.options.checkOverrides) {
|
|
83
|
+
if (params.options.checkOverrides && !params.options.ratchet) {
|
|
47
84
|
const overrideCtx = buildOverrideContext(subfolderAbs, {
|
|
48
|
-
auditLog: NULL_AUDIT_LOG,
|
|
85
|
+
auditLog: params.auditLog ?? NULL_AUDIT_LOG,
|
|
49
86
|
logger: { info: () => { }, warn: () => { }, error: () => { }, debug: () => { } },
|
|
50
87
|
checkNetwork: !!params.options.checkNetwork,
|
|
51
88
|
});
|
|
52
89
|
const overrideAudit = await audit(overrideCtx, { checkNetwork: !!params.options.checkNetwork });
|
|
53
90
|
overrideFindings = overrideAudit.findings;
|
|
54
91
|
}
|
|
55
|
-
// Maintenance
|
|
92
|
+
// Maintenance from the baseline-filtered set. Skipped under --ratchet because
|
|
93
|
+
// that path always early-exits on CVE save/gate (same as single-folder).
|
|
56
94
|
let maintenanceFindings = [];
|
|
57
|
-
if (params.options.checkMaintenance) {
|
|
58
|
-
|
|
95
|
+
if (params.options.checkMaintenance && !params.options.ratchet) {
|
|
96
|
+
const directDependencies = scanInput.packages.filter(p => directDependencyNames?.has(p.name));
|
|
97
|
+
maintenanceFindings = await detectDM001(sorted, directDependencies, offline);
|
|
59
98
|
}
|
|
60
99
|
results.push({
|
|
61
100
|
subfolder,
|
|
@@ -66,32 +105,143 @@ export async function runMultiFolderScan(params) {
|
|
|
66
105
|
minSeverity,
|
|
67
106
|
tableFindings,
|
|
68
107
|
allPackages: scanInput.packages,
|
|
108
|
+
completeness,
|
|
69
109
|
overrideFindings,
|
|
70
110
|
maintenanceFindings,
|
|
111
|
+
suppressedCount,
|
|
71
112
|
});
|
|
72
113
|
}
|
|
73
114
|
return results;
|
|
74
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Per-subfolder --ratchet: each folder gets its own `.cve-lite/baseline.json`.
|
|
118
|
+
* Folders without a baseline are saved; folders with a baseline are gated.
|
|
119
|
+
* Exit 1 if any gated folder has findings above its baseline.
|
|
120
|
+
*/
|
|
121
|
+
function handleMultiFolderRatchet(results, projectRoot, options) {
|
|
122
|
+
let anyNewFindings = false;
|
|
123
|
+
let hasDetectionGaps = false;
|
|
124
|
+
for (const r of results) {
|
|
125
|
+
const { hasDetectionGap } = getCompletenessImpact(r.completeness);
|
|
126
|
+
if (hasDetectionGap) {
|
|
127
|
+
hasDetectionGaps = true;
|
|
128
|
+
console.log(chalk.red(`${r.subfolder}/: Scan data is incomplete. Refusing to create or evaluate a baseline from partial detection data.`));
|
|
129
|
+
for (const diagnostic of r.completeness.diagnostics) {
|
|
130
|
+
if (diagnostic.impact !== "detection")
|
|
131
|
+
continue;
|
|
132
|
+
console.log(chalk.red(` ${formatDiagnosticMessage(diagnostic.code, diagnostic.count, diagnostic.affectedPackageCount)}`));
|
|
133
|
+
}
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const subfolderAbs = path.join(projectRoot, r.subfolder);
|
|
137
|
+
const baseline = readBaseline(subfolderAbs);
|
|
138
|
+
const outcome = ratchetOutcome(baseline, r.sorted);
|
|
139
|
+
if (outcome.action === "save") {
|
|
140
|
+
writeBaseline(subfolderAbs, r.sorted);
|
|
141
|
+
const count = r.sorted.length;
|
|
142
|
+
console.log(chalk.green(`✓ ${r.subfolder}/: Baseline saved to .cve-lite/baseline.json with ${count} ${pluralize(count, "finding")}. Future scans will only report findings above this baseline.`));
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const { newFindings, suppressedCount } = outcome;
|
|
146
|
+
const suppressedLabel = `${suppressedCount} existing ${pluralize(suppressedCount, "finding")} suppressed`;
|
|
147
|
+
if (newFindings.length === 0) {
|
|
148
|
+
console.log(chalk.green(`✓ ${r.subfolder}/: No new findings above baseline - ${suppressedLabel}`));
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
anyNewFindings = true;
|
|
152
|
+
console.log(chalk.red(`${r.subfolder}/: ${newFindings.length} new ${pluralize(newFindings.length, "finding")} above baseline - ${suppressedLabel}`));
|
|
153
|
+
for (const f of newFindings) {
|
|
154
|
+
const ids = f.vulnerabilities.map(v => v.id).join(", ");
|
|
155
|
+
console.log(` ${chalk.yellow(f.severity)} ${f.pkg.name}@${f.pkg.version}${ids ? ` (${ids})` : ""}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (hasDetectionGaps) {
|
|
159
|
+
return EXIT_ERROR;
|
|
160
|
+
}
|
|
161
|
+
if (options.checkOverrides) {
|
|
162
|
+
console.log(chalk.gray(`Note: override hygiene (--check-overrides) is not part of the ratchet baseline; run \`${OVERRIDES_COMMAND}\` to audit overrides.`));
|
|
163
|
+
}
|
|
164
|
+
if (anyNewFindings) {
|
|
165
|
+
console.log(chalk.gray("To accept these, re-baseline intentionally by deleting the folder's .cve-lite/baseline.json and re-running --ratchet."));
|
|
166
|
+
return EXIT_FINDINGS;
|
|
167
|
+
}
|
|
168
|
+
return EXIT_OK;
|
|
169
|
+
}
|
|
75
170
|
export async function handleMultiFolderScan(params) {
|
|
171
|
+
const auditLog = params.auditLog ?? NULL_AUDIT_LOG;
|
|
172
|
+
const scanStartedAt = Date.now();
|
|
76
173
|
const results = await runMultiFolderScan(params);
|
|
174
|
+
const scanFinishedAt = Date.now();
|
|
175
|
+
const first = results[0];
|
|
176
|
+
auditLog.emit({
|
|
177
|
+
ts: new Date(scanStartedAt).toISOString(),
|
|
178
|
+
type: "scan.started",
|
|
179
|
+
schemaVersion: 1,
|
|
180
|
+
projectPath: params.projectRoot,
|
|
181
|
+
mode: first?.scanInput.mode ?? "resolved-lockfile",
|
|
182
|
+
source: first?.scanInput.source ?? "package-lock",
|
|
183
|
+
flags: {
|
|
184
|
+
fix: params.options.fix === true,
|
|
185
|
+
json: params.options.json === true,
|
|
186
|
+
prodOnly: params.options.prodOnly === true,
|
|
187
|
+
offline: params.options.offline === true,
|
|
188
|
+
checkOverrides: params.options.checkOverrides === true,
|
|
189
|
+
checkMaintenance: params.options.checkMaintenance === true,
|
|
190
|
+
folderCount: String(results.length),
|
|
191
|
+
},
|
|
192
|
+
});
|
|
77
193
|
if (results.length === 0) {
|
|
78
194
|
console.log(chalk.yellow("No scannable packages found in any subfolder."));
|
|
195
|
+
auditLog.emit({
|
|
196
|
+
ts: new Date(scanFinishedAt).toISOString(),
|
|
197
|
+
type: "scan.finished",
|
|
198
|
+
schemaVersion: 1,
|
|
199
|
+
durationMs: scanFinishedAt - scanStartedAt,
|
|
200
|
+
findingsCount: 0,
|
|
201
|
+
exitCode: EXIT_OK,
|
|
202
|
+
});
|
|
79
203
|
return EXIT_OK;
|
|
80
204
|
}
|
|
81
205
|
if (params.options.fix) {
|
|
82
206
|
console.error(chalk.yellow("--fix is not yet supported in multi-folder mode. Run cve-lite . from each subfolder individually."));
|
|
207
|
+
auditLog.emit({
|
|
208
|
+
ts: new Date().toISOString(),
|
|
209
|
+
type: "scan.finished",
|
|
210
|
+
schemaVersion: 1,
|
|
211
|
+
durationMs: Date.now() - scanStartedAt,
|
|
212
|
+
findingsCount: results.reduce((count, result) => count + result.sorted.length, 0),
|
|
213
|
+
exitCode: EXIT_ERROR,
|
|
214
|
+
});
|
|
83
215
|
return EXIT_ERROR;
|
|
84
216
|
}
|
|
85
217
|
if (params.options.sarif || params.options.cdx) {
|
|
86
218
|
console.error(chalk.yellow("--sarif and --cdx are not yet supported in multi-folder mode."));
|
|
219
|
+
auditLog.emit({
|
|
220
|
+
ts: new Date().toISOString(),
|
|
221
|
+
type: "scan.finished",
|
|
222
|
+
schemaVersion: 1,
|
|
223
|
+
durationMs: Date.now() - scanStartedAt,
|
|
224
|
+
findingsCount: results.reduce((count, result) => count + result.sorted.length, 0),
|
|
225
|
+
exitCode: EXIT_ERROR,
|
|
226
|
+
});
|
|
87
227
|
return EXIT_ERROR;
|
|
88
228
|
}
|
|
229
|
+
if (params.options.ratchet) {
|
|
230
|
+
return handleMultiFolderRatchet(results, params.projectRoot, params.options);
|
|
231
|
+
}
|
|
89
232
|
if (params.options.json) {
|
|
90
|
-
|
|
233
|
+
// Match single-folder writeOutputs: timestamped file in cwd, not stdout dump.
|
|
234
|
+
// Help text and CI both treat --json as "save a JSON file".
|
|
91
235
|
const allFindings = results.flatMap(r => r.sorted.map(f => ({ ...serializeFinding(f, r.suggestedFixCommands), subfolder: r.subfolder })));
|
|
92
|
-
|
|
236
|
+
const completeness = aggregateMultiFolderCompleteness(results);
|
|
237
|
+
const payload = {
|
|
93
238
|
multiFolder: true,
|
|
239
|
+
projectPath: params.projectRoot,
|
|
94
240
|
folders: results.map(r => r.subfolder),
|
|
241
|
+
findingCount: allFindings.length,
|
|
242
|
+
status: completeness.complete ? "ok" : "partial",
|
|
243
|
+
complete: completeness.complete,
|
|
244
|
+
diagnostics: completeness.diagnostics,
|
|
95
245
|
findings: allFindings,
|
|
96
246
|
...(params.options.checkOverrides
|
|
97
247
|
? {
|
|
@@ -104,7 +254,12 @@ export async function handleMultiFolderScan(params) {
|
|
|
104
254
|
}
|
|
105
255
|
: {}),
|
|
106
256
|
scannedAt: new Date().toISOString(),
|
|
107
|
-
}
|
|
257
|
+
};
|
|
258
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
259
|
+
const jsonFilename = `cve-lite-scan-${ts}.json`;
|
|
260
|
+
const jsonOutputPath = path.join(process.cwd(), jsonFilename);
|
|
261
|
+
fs.writeFileSync(jsonOutputPath, JSON.stringify(payload, null, 2));
|
|
262
|
+
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
|
|
108
263
|
}
|
|
109
264
|
else {
|
|
110
265
|
printMultiFolderResults(results, params.options);
|
|
@@ -141,6 +296,10 @@ export async function handleMultiFolderScan(params) {
|
|
|
141
296
|
projectPath: params.projectRoot,
|
|
142
297
|
cliVersion,
|
|
143
298
|
autoOpen: !params.options.noOpen,
|
|
299
|
+
// Same undefined-vs-[] contract as single-folder buildReportData: pass the
|
|
300
|
+
// flag so empty panels render when the check ran with no hits.
|
|
301
|
+
includeOverrides: !!params.options.checkOverrides,
|
|
302
|
+
includeMaintenance: !!params.options.checkMaintenance,
|
|
144
303
|
});
|
|
145
304
|
console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
|
|
146
305
|
}
|
|
@@ -154,5 +313,14 @@ export async function handleMultiFolderScan(params) {
|
|
|
154
313
|
const shouldFail = allSorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]) ||
|
|
155
314
|
reachesFailOn(allOverrideFindings, params.options.failOn) ||
|
|
156
315
|
reachesFailOn(allMaintenanceFindings, params.options.failOn);
|
|
157
|
-
|
|
316
|
+
const exitCode = shouldFail ? EXIT_FINDINGS : EXIT_OK;
|
|
317
|
+
auditLog.emit({
|
|
318
|
+
ts: new Date(scanFinishedAt).toISOString(),
|
|
319
|
+
type: "scan.finished",
|
|
320
|
+
schemaVersion: 1,
|
|
321
|
+
durationMs: scanFinishedAt - scanStartedAt,
|
|
322
|
+
findingsCount: allSorted.length,
|
|
323
|
+
exitCode,
|
|
324
|
+
});
|
|
325
|
+
return exitCode;
|
|
158
326
|
}
|