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
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
2
|
import { fetchPackument } from "./npm-registry.js";
|
|
3
|
+
export function isVerifiedUpgrade(confidence) {
|
|
4
|
+
return confidence === "verified";
|
|
5
|
+
}
|
|
3
6
|
export async function resolveRecommendedParentUpgrade(finding, packages, directDependencyNames, options) {
|
|
4
7
|
if (finding.relationship !== "transitive")
|
|
5
8
|
return null;
|
|
@@ -28,9 +31,9 @@ export async function resolveRecommendedParentUpgrade(finding, packages, directD
|
|
|
28
31
|
viaPath,
|
|
29
32
|
});
|
|
30
33
|
}
|
|
31
|
-
//
|
|
34
|
+
// Deeper chains: verify along the path before recommending.
|
|
32
35
|
// Use the immediate child of the direct parent (not the immediate parent of the vulnerable
|
|
33
|
-
// package)
|
|
36
|
+
// package) - that's what the direct parent actually lists in its own dependencies.
|
|
34
37
|
const directParentIdx = viaPath.indexOf(directParentName);
|
|
35
38
|
if (directParentIdx < 0)
|
|
36
39
|
return null;
|
|
@@ -41,6 +44,8 @@ export async function resolveRecommendedParentUpgrade(finding, packages, directD
|
|
|
41
44
|
immediateChildName,
|
|
42
45
|
immediateChildInstalledVersion: findPackageVersion(packages, immediateChildName, viaPath.slice(0, directParentIdx + 2)) ?? "",
|
|
43
46
|
vulnerableName,
|
|
47
|
+
vulnerableFixedVersion: finding.validatedFirstFixedVersion ?? finding.firstFixedVersion,
|
|
48
|
+
pathAfterParent: viaPath.slice(directParentIdx + 1),
|
|
44
49
|
viaPath,
|
|
45
50
|
});
|
|
46
51
|
}
|
|
@@ -102,6 +107,48 @@ function startsWithPath(path, prefix) {
|
|
|
102
107
|
}
|
|
103
108
|
return true;
|
|
104
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Highest published, non-prerelease version of `name` that satisfies `range`,
|
|
112
|
+
* or null if none do (or the packument cannot be fetched).
|
|
113
|
+
*/
|
|
114
|
+
export async function resolveHighestSatisfying(name, range) {
|
|
115
|
+
const packument = await fetchPackument(name);
|
|
116
|
+
const versions = Object.keys(packument?.versions ?? {})
|
|
117
|
+
.filter(looksLikeVersion)
|
|
118
|
+
.filter(v => !isPreReleaseVersion(v))
|
|
119
|
+
.filter(version => versionSatisfiesRange(version, range))
|
|
120
|
+
.sort(compareVersions);
|
|
121
|
+
return versions.at(-1) ?? null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Walk `pathNames` (in order, ending with `vulnerableName`) starting from
|
|
125
|
+
* `startManifest`, resolving each declared range to its highest published
|
|
126
|
+
* version to find what the vulnerable package would actually resolve to.
|
|
127
|
+
*
|
|
128
|
+
* - A dep dropped mid-path means the vulnerable package is no longer pulled
|
|
129
|
+
* via this path: `{ terminalVersion: null, resolvable: true }`.
|
|
130
|
+
* - A range that cannot be resolved to any published version means the walk
|
|
131
|
+
* cannot be verified: `{ terminalVersion: null, resolvable: false }`.
|
|
132
|
+
*/
|
|
133
|
+
export async function resolvePathTerminalVersion(startManifest, pathNames, vulnerableName) {
|
|
134
|
+
let currentManifest = startManifest;
|
|
135
|
+
for (const nextName of pathNames) {
|
|
136
|
+
const range = currentManifest.dependencies?.[nextName] ?? currentManifest.optionalDependencies?.[nextName];
|
|
137
|
+
if (range === undefined) {
|
|
138
|
+
return { terminalVersion: null, resolvable: true };
|
|
139
|
+
}
|
|
140
|
+
const resolved = await resolveHighestSatisfying(nextName, range);
|
|
141
|
+
if (resolved === null) {
|
|
142
|
+
return { terminalVersion: null, resolvable: false };
|
|
143
|
+
}
|
|
144
|
+
if (nextName === vulnerableName) {
|
|
145
|
+
return { terminalVersion: resolved, resolvable: true };
|
|
146
|
+
}
|
|
147
|
+
const nextPackument = await fetchPackument(nextName);
|
|
148
|
+
currentManifest = nextPackument?.versions?.[resolved] ?? {};
|
|
149
|
+
}
|
|
150
|
+
return { terminalVersion: null, resolvable: true };
|
|
151
|
+
}
|
|
105
152
|
async function findUpgradeForExactDirectChild(args) {
|
|
106
153
|
const packument = await fetchPackument(args.directParentName);
|
|
107
154
|
const versions = Object.keys(packument?.versions ?? {})
|
|
@@ -126,13 +173,17 @@ async function findUpgradeForExactDirectChild(args) {
|
|
|
126
173
|
targetVersion: version,
|
|
127
174
|
viaPath: args.viaPath,
|
|
128
175
|
vulnerablePackage: args.vulnerableName,
|
|
129
|
-
confidence: "
|
|
176
|
+
confidence: "verified",
|
|
130
177
|
reason: `${args.directParentName}@${version} no longer allows ${args.vulnerableName}@${args.vulnerableInstalledVersion}${args.vulnerableFixedVersion ? ` and allows ${args.vulnerableFixedVersion}+` : ""}`,
|
|
131
178
|
};
|
|
132
179
|
}
|
|
133
180
|
}
|
|
134
181
|
return null;
|
|
135
182
|
}
|
|
183
|
+
// Bound how many candidate parent versions we resolve the full path for, to keep
|
|
184
|
+
// network cost reasonable. Packuments are process-cached, so shared path prefixes
|
|
185
|
+
// across candidates are cheap, but the terminal walk still fetches per link.
|
|
186
|
+
const MAX_CANDIDATE_PARENT_VERSIONS = 25;
|
|
136
187
|
async function findUpgradeForImmediateIntermediate(args) {
|
|
137
188
|
if (!args.immediateChildInstalledVersion || !looksLikeVersion(args.immediateChildInstalledVersion)) {
|
|
138
189
|
return null;
|
|
@@ -142,25 +193,70 @@ async function findUpgradeForImmediateIntermediate(args) {
|
|
|
142
193
|
.filter(looksLikeVersion)
|
|
143
194
|
.filter(v => !isPreReleaseVersion(v))
|
|
144
195
|
.filter(version => compareVersions(version, args.directParentVersion) > 0)
|
|
145
|
-
.sort(compareVersions)
|
|
196
|
+
.sort(compareVersions)
|
|
197
|
+
.slice(0, MAX_CANDIDATE_PARENT_VERSIONS);
|
|
198
|
+
// Three outcomes:
|
|
199
|
+
// 1. A candidate whose subtree resolves the vulnerable package to a fixed
|
|
200
|
+
// version (or drops it entirely) -> recommend it, verified.
|
|
201
|
+
// 2. Every candidate is resolvable but none reaches a fixed version -> null
|
|
202
|
+
// (honest: no parent upgrade currently resolves this).
|
|
203
|
+
// 3. Some candidate could not be verified (a range/packument we could not
|
|
204
|
+
// resolve) -> fall back to the old "no longer allows the installed child"
|
|
205
|
+
// heuristic, but label it unverified.
|
|
206
|
+
let sawUnverifiable = false;
|
|
207
|
+
let heuristicFallback = null;
|
|
146
208
|
for (const version of versions) {
|
|
147
209
|
const manifest = packument?.versions?.[version];
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
210
|
+
if (!manifest)
|
|
211
|
+
continue;
|
|
212
|
+
const walk = await resolvePathTerminalVersion(manifest, args.pathAfterParent, args.vulnerableName);
|
|
213
|
+
if (walk.resolvable) {
|
|
214
|
+
const isFixed = walk.terminalVersion === null ||
|
|
215
|
+
(args.vulnerableFixedVersion != null &&
|
|
216
|
+
compareVersions(walk.terminalVersion, args.vulnerableFixedVersion) >= 0);
|
|
217
|
+
if (isFixed) {
|
|
218
|
+
// "verified" means verified against declared dependency ranges along this
|
|
219
|
+
// path (each link resolved to its highest published satisfying version),
|
|
220
|
+
// not an install-level guarantee - npm dedup/hoisting can still land a
|
|
221
|
+
// lower version. This is the honest upper bound we can compute without
|
|
222
|
+
// reimplementing npm's resolver.
|
|
223
|
+
const reason = walk.terminalVersion === null
|
|
224
|
+
? `${args.directParentName}@${version} no longer pulls ${args.vulnerableName} on this path`
|
|
225
|
+
: `${args.directParentName}@${version} resolves ${args.vulnerableName} to ${walk.terminalVersion}${args.vulnerableFixedVersion ? `, at or above the fix ${args.vulnerableFixedVersion}` : ""}`;
|
|
226
|
+
return {
|
|
227
|
+
package: args.directParentName,
|
|
228
|
+
currentVersion: args.directParentVersion,
|
|
229
|
+
targetVersion: version,
|
|
230
|
+
viaPath: args.viaPath,
|
|
231
|
+
vulnerablePackage: args.vulnerableName,
|
|
232
|
+
confidence: "verified",
|
|
233
|
+
reason,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
151
236
|
continue;
|
|
152
|
-
const stillAllowsInstalledChild = versionSatisfiesRange(args.immediateChildInstalledVersion, depRange);
|
|
153
|
-
if (!stillAllowsInstalledChild) {
|
|
154
|
-
return {
|
|
155
|
-
package: args.directParentName,
|
|
156
|
-
currentVersion: args.directParentVersion,
|
|
157
|
-
targetVersion: version,
|
|
158
|
-
viaPath: args.viaPath,
|
|
159
|
-
vulnerablePackage: args.vulnerableName,
|
|
160
|
-
confidence: "best-effort",
|
|
161
|
-
reason: `${args.directParentName}@${version} no longer allows ${args.immediateChildName}@${args.immediateChildInstalledVersion} in the current path`,
|
|
162
|
-
};
|
|
163
237
|
}
|
|
238
|
+
// Could not verify this candidate's subtree. Remember the first candidate that
|
|
239
|
+
// also satisfies the old heuristic (parent no longer allows the installed
|
|
240
|
+
// immediate child) as an explicitly-unverified fallback.
|
|
241
|
+
sawUnverifiable = true;
|
|
242
|
+
if (!heuristicFallback) {
|
|
243
|
+
const depRange = manifest.dependencies?.[args.immediateChildName] ??
|
|
244
|
+
manifest.optionalDependencies?.[args.immediateChildName];
|
|
245
|
+
if (depRange && !versionSatisfiesRange(args.immediateChildInstalledVersion, depRange)) {
|
|
246
|
+
heuristicFallback = {
|
|
247
|
+
package: args.directParentName,
|
|
248
|
+
currentVersion: args.directParentVersion,
|
|
249
|
+
targetVersion: version,
|
|
250
|
+
viaPath: args.viaPath,
|
|
251
|
+
vulnerablePackage: args.vulnerableName,
|
|
252
|
+
confidence: "unverified",
|
|
253
|
+
reason: `${args.directParentName}@${version} may resolve ${args.vulnerableName}, but this could not be verified; rescan after upgrading to confirm`,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (sawUnverifiable && heuristicFallback) {
|
|
259
|
+
return heuristicFallback;
|
|
164
260
|
}
|
|
165
261
|
return null;
|
|
166
262
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { pluralize } from "../utils/string.js";
|
|
2
|
+
export function getCompletenessImpact(completeness) {
|
|
3
|
+
const diagnostics = completeness?.diagnostics ?? [];
|
|
4
|
+
return {
|
|
5
|
+
hasDetectionGap: diagnostics.some(diagnostic => diagnostic.impact === "detection"),
|
|
6
|
+
hasRemediationGap: diagnostics.some(diagnostic => diagnostic.impact === "remediation"),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function formatDiagnosticMessage(code, count, affectedPackageCount) {
|
|
10
|
+
switch (code) {
|
|
11
|
+
case "OSV_DETAIL_TRANSIENT_FAILURE":
|
|
12
|
+
return `${count} advisory detail ${pluralize(count, "lookup")} failed with a transient error — re-run to retry.`;
|
|
13
|
+
case "OSV_DETAIL_OFFLINE_MISSING":
|
|
14
|
+
return `${count} advisory detail ${pluralize(count, "record")} ${pluralize(count, "is", "are")} missing from the local advisory database — refresh to sync.`;
|
|
15
|
+
case "OSV_DETAIL_CONFIRMED_MISSING":
|
|
16
|
+
return `${count} advisory detail ${pluralize(count, "record")} ${pluralize(count, "is", "are")} confirmed missing from the OSV API — affected findings lack detail data.`;
|
|
17
|
+
case "PACKUMENT_FETCH_FAILURE":
|
|
18
|
+
return `${count} packument ${pluralize(count, "fetch", "fetches")} failed — remediation guidance may be incomplete.`;
|
|
19
|
+
case "REMEDIATION_FAILURE":
|
|
20
|
+
if (affectedPackageCount !== undefined) {
|
|
21
|
+
return `${count} transitive remediation ${pluralize(count, "attempt")} failed across ${affectedPackageCount} ${pluralize(affectedPackageCount, "package")} — some fix recommendations may be missing.`;
|
|
22
|
+
}
|
|
23
|
+
return `${count} transitive remediation ${pluralize(count, "attempt")} failed — some fix recommendations may be missing.`;
|
|
24
|
+
case "CHAIN_RESOLUTION_FAILURE":
|
|
25
|
+
return `${count} chain resolution ${pluralize(count, "attempt")} failed — some validated upgrade chains may be missing.`;
|
|
26
|
+
default:
|
|
27
|
+
return `${count} unknown diagnostic occurred.`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function aggregateMultiFolderCompleteness(results) {
|
|
31
|
+
const deduped = new Map();
|
|
32
|
+
for (const result of results) {
|
|
33
|
+
for (const diagnostic of result.completeness.diagnostics) {
|
|
34
|
+
const existing = deduped.get(diagnostic.code);
|
|
35
|
+
if (existing) {
|
|
36
|
+
existing.count += diagnostic.count;
|
|
37
|
+
if (diagnostic.affectedPackageCount !== undefined) {
|
|
38
|
+
existing.affectedPackageCount =
|
|
39
|
+
(existing.affectedPackageCount ?? 0) + diagnostic.affectedPackageCount;
|
|
40
|
+
}
|
|
41
|
+
existing.message = formatDiagnosticMessage(diagnostic.code, existing.count, existing.affectedPackageCount);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
deduped.set(diagnostic.code, { ...diagnostic });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { complete: deduped.size === 0, diagnostics: [...deduped.values()] };
|
|
49
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
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";
|
|
@@ -16,6 +17,12 @@ import { chalk } from "../utils/chalk.js";
|
|
|
16
17
|
import { getCliVersion } from "../utils/version-info.js";
|
|
17
18
|
import { buildOverrideContext, audit } from "../overrides/index.js";
|
|
18
19
|
import { NULL_AUDIT_LOG } from "../audit-log/index.js";
|
|
20
|
+
import { detectDM001 } from "../maintenance/dm001-maintenance-risk.js";
|
|
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 } from "./completeness.js";
|
|
25
|
+
import { scanProjectForPackageUsage } from "../usage/scanner.js";
|
|
19
26
|
export async function runMultiFolderScan(params) {
|
|
20
27
|
const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
21
28
|
const folders = loadMultiplePackages(params.projectRoot, !!params.options.prodOnly, searchDepth);
|
|
@@ -24,32 +31,71 @@ export async function runMultiFolderScan(params) {
|
|
|
24
31
|
for (const { scanInput, subfolder } of folders) {
|
|
25
32
|
if (scanInput.packages.length === 0)
|
|
26
33
|
continue;
|
|
27
|
-
if (!params.options.json) {
|
|
34
|
+
if (!params.options.json && !params.options.ratchet) {
|
|
28
35
|
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${subfolder}/`)}\n`);
|
|
29
36
|
}
|
|
30
37
|
const subfolderAbs = path.join(params.projectRoot, subfolder);
|
|
31
38
|
const directDependencyNames = readDirectDependencyNames(subfolderAbs, !!params.options.prodOnly);
|
|
32
|
-
const findings = await scanPackages(scanInput.packages, params.batchSize, params.options, {
|
|
39
|
+
const { findings, completeness } = await scanPackages(scanInput.packages, params.batchSize, params.options, {
|
|
33
40
|
directDependencyNames,
|
|
34
41
|
scanSource: scanInput.source,
|
|
35
42
|
scanFilePath: scanInput.filePath,
|
|
36
|
-
});
|
|
37
|
-
|
|
43
|
+
}, undefined, params.fetchImpl);
|
|
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
|
+
}
|
|
38
76
|
const coverage = buildCoverageNotes(scanInput, offline);
|
|
39
77
|
const minSeverity = normalizeSeverity(params.options.minSeverity || "medium");
|
|
40
78
|
const tableFindings = params.options.all ? sorted : selectFindingsForTable(sorted, minSeverity);
|
|
41
79
|
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, scanInput, { offline, subfolder });
|
|
42
|
-
// 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).
|
|
43
82
|
let overrideFindings = [];
|
|
44
|
-
if (params.options.checkOverrides) {
|
|
83
|
+
if (params.options.checkOverrides && !params.options.ratchet) {
|
|
45
84
|
const overrideCtx = buildOverrideContext(subfolderAbs, {
|
|
46
|
-
auditLog: NULL_AUDIT_LOG,
|
|
85
|
+
auditLog: params.auditLog ?? NULL_AUDIT_LOG,
|
|
47
86
|
logger: { info: () => { }, warn: () => { }, error: () => { }, debug: () => { } },
|
|
48
87
|
checkNetwork: !!params.options.checkNetwork,
|
|
49
88
|
});
|
|
50
89
|
const overrideAudit = await audit(overrideCtx, { checkNetwork: !!params.options.checkNetwork });
|
|
51
90
|
overrideFindings = overrideAudit.findings;
|
|
52
91
|
}
|
|
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).
|
|
94
|
+
let maintenanceFindings = [];
|
|
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);
|
|
98
|
+
}
|
|
53
99
|
results.push({
|
|
54
100
|
subfolder,
|
|
55
101
|
scanInput,
|
|
@@ -59,39 +105,146 @@ export async function runMultiFolderScan(params) {
|
|
|
59
105
|
minSeverity,
|
|
60
106
|
tableFindings,
|
|
61
107
|
allPackages: scanInput.packages,
|
|
108
|
+
completeness,
|
|
62
109
|
overrideFindings,
|
|
110
|
+
maintenanceFindings,
|
|
111
|
+
suppressedCount,
|
|
63
112
|
});
|
|
64
113
|
}
|
|
65
114
|
return results;
|
|
66
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
|
+
for (const r of results) {
|
|
124
|
+
const subfolderAbs = path.join(projectRoot, r.subfolder);
|
|
125
|
+
const baseline = readBaseline(subfolderAbs);
|
|
126
|
+
const outcome = ratchetOutcome(baseline, r.sorted);
|
|
127
|
+
if (outcome.action === "save") {
|
|
128
|
+
writeBaseline(subfolderAbs, r.sorted);
|
|
129
|
+
const count = r.sorted.length;
|
|
130
|
+
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.`));
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const { newFindings, suppressedCount } = outcome;
|
|
134
|
+
const suppressedLabel = `${suppressedCount} existing ${pluralize(suppressedCount, "finding")} suppressed`;
|
|
135
|
+
if (newFindings.length === 0) {
|
|
136
|
+
console.log(chalk.green(`✓ ${r.subfolder}/: No new findings above baseline - ${suppressedLabel}`));
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
anyNewFindings = true;
|
|
140
|
+
console.log(chalk.red(`${r.subfolder}/: ${newFindings.length} new ${pluralize(newFindings.length, "finding")} above baseline - ${suppressedLabel}`));
|
|
141
|
+
for (const f of newFindings) {
|
|
142
|
+
const ids = f.vulnerabilities.map(v => v.id).join(", ");
|
|
143
|
+
console.log(` ${chalk.yellow(f.severity)} ${f.pkg.name}@${f.pkg.version}${ids ? ` (${ids})` : ""}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (options.checkOverrides) {
|
|
147
|
+
console.log(chalk.gray("Note: override hygiene (--check-overrides) is not part of the ratchet baseline; run `cve-lite overrides` to audit overrides."));
|
|
148
|
+
}
|
|
149
|
+
if (anyNewFindings) {
|
|
150
|
+
console.log(chalk.gray("To accept these, re-baseline intentionally by deleting the folder's .cve-lite/baseline.json and re-running --ratchet."));
|
|
151
|
+
return EXIT_FINDINGS;
|
|
152
|
+
}
|
|
153
|
+
return EXIT_OK;
|
|
154
|
+
}
|
|
67
155
|
export async function handleMultiFolderScan(params) {
|
|
156
|
+
const auditLog = params.auditLog ?? NULL_AUDIT_LOG;
|
|
157
|
+
const scanStartedAt = Date.now();
|
|
68
158
|
const results = await runMultiFolderScan(params);
|
|
159
|
+
const scanFinishedAt = Date.now();
|
|
160
|
+
const first = results[0];
|
|
161
|
+
auditLog.emit({
|
|
162
|
+
ts: new Date(scanStartedAt).toISOString(),
|
|
163
|
+
type: "scan.started",
|
|
164
|
+
schemaVersion: 1,
|
|
165
|
+
projectPath: params.projectRoot,
|
|
166
|
+
mode: first?.scanInput.mode ?? "resolved-lockfile",
|
|
167
|
+
source: first?.scanInput.source ?? "package-lock",
|
|
168
|
+
flags: {
|
|
169
|
+
fix: params.options.fix === true,
|
|
170
|
+
json: params.options.json === true,
|
|
171
|
+
prodOnly: params.options.prodOnly === true,
|
|
172
|
+
offline: params.options.offline === true,
|
|
173
|
+
checkOverrides: params.options.checkOverrides === true,
|
|
174
|
+
checkMaintenance: params.options.checkMaintenance === true,
|
|
175
|
+
folderCount: String(results.length),
|
|
176
|
+
},
|
|
177
|
+
});
|
|
69
178
|
if (results.length === 0) {
|
|
70
179
|
console.log(chalk.yellow("No scannable packages found in any subfolder."));
|
|
180
|
+
auditLog.emit({
|
|
181
|
+
ts: new Date(scanFinishedAt).toISOString(),
|
|
182
|
+
type: "scan.finished",
|
|
183
|
+
schemaVersion: 1,
|
|
184
|
+
durationMs: scanFinishedAt - scanStartedAt,
|
|
185
|
+
findingsCount: 0,
|
|
186
|
+
exitCode: EXIT_OK,
|
|
187
|
+
});
|
|
71
188
|
return EXIT_OK;
|
|
72
189
|
}
|
|
73
190
|
if (params.options.fix) {
|
|
74
191
|
console.error(chalk.yellow("--fix is not yet supported in multi-folder mode. Run cve-lite . from each subfolder individually."));
|
|
192
|
+
auditLog.emit({
|
|
193
|
+
ts: new Date().toISOString(),
|
|
194
|
+
type: "scan.finished",
|
|
195
|
+
schemaVersion: 1,
|
|
196
|
+
durationMs: Date.now() - scanStartedAt,
|
|
197
|
+
findingsCount: results.reduce((count, result) => count + result.sorted.length, 0),
|
|
198
|
+
exitCode: EXIT_ERROR,
|
|
199
|
+
});
|
|
75
200
|
return EXIT_ERROR;
|
|
76
201
|
}
|
|
77
202
|
if (params.options.sarif || params.options.cdx) {
|
|
78
203
|
console.error(chalk.yellow("--sarif and --cdx are not yet supported in multi-folder mode."));
|
|
204
|
+
auditLog.emit({
|
|
205
|
+
ts: new Date().toISOString(),
|
|
206
|
+
type: "scan.finished",
|
|
207
|
+
schemaVersion: 1,
|
|
208
|
+
durationMs: Date.now() - scanStartedAt,
|
|
209
|
+
findingsCount: results.reduce((count, result) => count + result.sorted.length, 0),
|
|
210
|
+
exitCode: EXIT_ERROR,
|
|
211
|
+
});
|
|
79
212
|
return EXIT_ERROR;
|
|
80
213
|
}
|
|
214
|
+
if (params.options.ratchet) {
|
|
215
|
+
return handleMultiFolderRatchet(results, params.projectRoot, params.options);
|
|
216
|
+
}
|
|
81
217
|
if (params.options.json) {
|
|
82
|
-
|
|
218
|
+
// Match single-folder writeOutputs: timestamped file in cwd, not stdout dump.
|
|
219
|
+
// Help text and CI both treat --json as "save a JSON file".
|
|
83
220
|
const allFindings = results.flatMap(r => r.sorted.map(f => ({ ...serializeFinding(f, r.suggestedFixCommands), subfolder: r.subfolder })));
|
|
84
|
-
|
|
221
|
+
const completeness = aggregateMultiFolderCompleteness(results);
|
|
222
|
+
const payload = {
|
|
85
223
|
multiFolder: true,
|
|
224
|
+
projectPath: params.projectRoot,
|
|
86
225
|
folders: results.map(r => r.subfolder),
|
|
226
|
+
findingCount: allFindings.length,
|
|
227
|
+
status: completeness.complete ? "ok" : "partial",
|
|
228
|
+
complete: completeness.complete,
|
|
229
|
+
diagnostics: completeness.diagnostics,
|
|
87
230
|
findings: allFindings,
|
|
88
231
|
...(params.options.checkOverrides
|
|
89
232
|
? {
|
|
90
233
|
overrideFindings: results.flatMap(r => r.overrideFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
91
234
|
}
|
|
92
235
|
: {}),
|
|
236
|
+
...(params.options.checkMaintenance
|
|
237
|
+
? {
|
|
238
|
+
maintenanceFindings: results.flatMap(r => r.maintenanceFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
239
|
+
}
|
|
240
|
+
: {}),
|
|
93
241
|
scannedAt: new Date().toISOString(),
|
|
94
|
-
}
|
|
242
|
+
};
|
|
243
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
244
|
+
const jsonFilename = `cve-lite-scan-${ts}.json`;
|
|
245
|
+
const jsonOutputPath = path.join(process.cwd(), jsonFilename);
|
|
246
|
+
fs.writeFileSync(jsonOutputPath, JSON.stringify(payload, null, 2));
|
|
247
|
+
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
|
|
95
248
|
}
|
|
96
249
|
else {
|
|
97
250
|
printMultiFolderResults(results, params.options);
|
|
@@ -102,6 +255,13 @@ export async function handleMultiFolderScan(params) {
|
|
|
102
255
|
console.log(renderOverrideFindings(r.overrideFindings, { verbose: !!params.options.verbose, projectPath: path.join(params.projectRoot, r.subfolder) }));
|
|
103
256
|
}
|
|
104
257
|
}
|
|
258
|
+
if (params.options.checkMaintenance) {
|
|
259
|
+
const { renderMaintenanceFindings } = await import("../output/maintenance-terminal.js");
|
|
260
|
+
for (const r of results) {
|
|
261
|
+
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray("maintenance risk")}\n`);
|
|
262
|
+
console.log(renderMaintenanceFindings(r.maintenanceFindings, { verbose: !!params.options.verbose }));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
105
265
|
if (!params.options.checkOverrides && !params.options.ratchet) {
|
|
106
266
|
for (const r of results) {
|
|
107
267
|
const subfolderPath = path.join(params.projectRoot, r.subfolder);
|
|
@@ -121,11 +281,31 @@ export async function handleMultiFolderScan(params) {
|
|
|
121
281
|
projectPath: params.projectRoot,
|
|
122
282
|
cliVersion,
|
|
123
283
|
autoOpen: !params.options.noOpen,
|
|
284
|
+
// Same undefined-vs-[] contract as single-folder buildReportData: pass the
|
|
285
|
+
// flag so empty panels render when the check ran with no hits.
|
|
286
|
+
includeOverrides: !!params.options.checkOverrides,
|
|
287
|
+
includeMaintenance: !!params.options.checkMaintenance,
|
|
124
288
|
});
|
|
125
289
|
console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
|
|
126
290
|
}
|
|
127
291
|
const failLevel = normalizeSeverity(params.options.failOn);
|
|
128
292
|
const allSorted = results.flatMap(r => r.sorted);
|
|
129
|
-
const
|
|
130
|
-
|
|
293
|
+
const allOverrideFindings = results.flatMap(r => r.overrideFindings);
|
|
294
|
+
const allMaintenanceFindings = results.flatMap(r => r.maintenanceFindings);
|
|
295
|
+
// Mirror single-folder exit policy in src/index.ts: CVE + override + maintenance
|
|
296
|
+
// all count toward --fail-on. Without overrides here, multi-folder CI using
|
|
297
|
+
// --check-overrides --fail-on high would exit 0 despite high OA findings.
|
|
298
|
+
const shouldFail = allSorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]) ||
|
|
299
|
+
reachesFailOn(allOverrideFindings, params.options.failOn) ||
|
|
300
|
+
reachesFailOn(allMaintenanceFindings, params.options.failOn);
|
|
301
|
+
const exitCode = shouldFail ? EXIT_FINDINGS : EXIT_OK;
|
|
302
|
+
auditLog.emit({
|
|
303
|
+
ts: new Date(scanFinishedAt).toISOString(),
|
|
304
|
+
type: "scan.finished",
|
|
305
|
+
schemaVersion: 1,
|
|
306
|
+
durationMs: scanFinishedAt - scanStartedAt,
|
|
307
|
+
findingsCount: allSorted.length,
|
|
308
|
+
exitCode,
|
|
309
|
+
});
|
|
310
|
+
return exitCode;
|
|
131
311
|
}
|