cve-lite-cli 1.40.0 → 1.41.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 +17 -11
- package/dist/advisory/local-advisory-source.js +9 -5
- package/dist/advisory/local-db.js +91 -13
- package/dist/advisory/osv-sync.js +187 -56
- package/dist/advisory/staging-directory.js +112 -0
- package/dist/cli/advisories-sync.js +16 -2
- package/dist/cli/args.js +46 -35
- package/dist/cli/config.js +4 -1
- package/dist/cli/help.js +4 -3
- package/dist/cli/validate.js +23 -1
- package/dist/constants.js +11 -25
- package/dist/index.js +8 -3
- package/dist/output/cyclonedx.js +23 -14
- package/dist/output/debug.js +68 -18
- package/dist/output/formatters.js +33 -5
- package/dist/output/html-reporter.js +55 -5
- package/dist/output/multi-folder-html-reporter.js +59 -3
- package/dist/output/output-dir.js +193 -7
- package/dist/output/printers.js +16 -5
- package/dist/output/sarif.js +131 -48
- package/dist/output/sbom-dependency-edges.js +16 -10
- package/dist/output/sbom-file.js +14 -6
- package/dist/output/scan-json.js +21 -3
- package/dist/output/spdx.js +61 -23
- package/dist/output/spinner.js +2 -1
- package/dist/output/write-outputs.js +142 -52
- package/dist/overrides/context-builder.js +23 -70
- package/dist/parsers/bun-lock.js +1 -2
- package/dist/parsers/index.js +22 -1
- package/dist/parsers/npm-lock-graph.js +39 -1
- package/dist/parsers/package-lock.js +25 -5
- package/dist/parsers/pnpm-lock.js +3 -2
- package/dist/parsers/utils.js +5 -3
- package/dist/parsers/yarn-lock-graph.js +5 -2
- package/dist/parsers/yarn-lock.js +1 -2
- package/dist/remediation/fix-commands.js +105 -44
- package/dist/remediation/npm-transitive-graph.js +30 -72
- package/dist/remediation/npm-transitive-resolution.js +24 -77
- package/dist/remediation/parent-upgrade-blockers.js +51 -0
- package/dist/remediation/parent-upgrade.js +5 -79
- package/dist/remediation/registry-parent-ranges.js +21 -0
- package/dist/remediation/transitive-chain-resolver.js +3 -3
- package/dist/scan/completeness.js +10 -4
- package/dist/scan/multi-folder-scan.js +133 -58
- package/dist/scan/single-scan.js +41 -25
- package/dist/scanner.js +257 -58
- package/dist/usage/scanner.js +19 -8
- package/dist/utils/array.js +11 -3
- package/dist/utils/debug-bundle.js +118 -0
- package/dist/utils/debug-project.js +102 -0
- package/dist/utils/debug-redaction.js +117 -0
- package/dist/utils/file.js +2 -1
- package/dist/utils/fix-runner.js +95 -13
- package/dist/utils/import-type-queries.js +322 -0
- package/dist/utils/network.js +13 -9
- package/dist/utils/npm-lockfile.js +12 -0
- package/dist/utils/osv-fetch.js +70 -0
- package/dist/utils/package-identity.js +43 -0
- package/dist/utils/package-manager-source.js +24 -0
- package/dist/utils/purl.js +37 -0
- package/dist/utils/registry-config.js +1 -16
- package/dist/utils/string.js +8 -0
- package/dist/utils/validate-url.js +1 -1
- package/dist/utils/version.js +30 -7
- package/dist/utils/versions/osv-range.js +191 -0
- package/dist/utils/versions/pep440.js +246 -0
- package/dist/utils/versions/scheme.js +10 -0
- package/package.json +3 -2
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import process from "node:process";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { EXIT_OK, EXIT_FINDINGS, EXIT_ERROR } from "../types.js";
|
|
5
6
|
import { loadMultiplePackages } from "../parsers/multi-package.js";
|
|
6
7
|
import { scanPackages, buildCoverageNotes } from "../scanner.js";
|
|
7
8
|
import { sortFindingsForOutput, logInfo } from "../output/formatters.js";
|
|
8
9
|
import { buildMultiFolderScanJson } from "../output/scan-json.js";
|
|
9
|
-
import {
|
|
10
|
+
import { resolveOutputTarget, displayOutputPath, checkFormatExtensionMismatch, isOutputStdout, drainStdout } from "../output/output-dir.js";
|
|
10
11
|
import { normalizeSeverity } from "../osv/severity.js";
|
|
11
12
|
import { selectFindingsForTable } from "../output/finding-display.js";
|
|
12
13
|
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
@@ -27,6 +28,7 @@ import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "
|
|
|
27
28
|
import { pluralize } from "../utils/string.js";
|
|
28
29
|
import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, shouldFailForIncompleteScan, } from "./completeness.js";
|
|
29
30
|
import { scanProjectForPackageUsage, usageScanTruncationWarning } from "../usage/scanner.js";
|
|
31
|
+
import { isNpmLockSource } from "../utils/package-manager-source.js";
|
|
30
32
|
export async function runMultiFolderScan(params) {
|
|
31
33
|
const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
32
34
|
const folders = loadMultiplePackages(params.projectRoot, !!params.options.prodOnly, searchDepth);
|
|
@@ -35,7 +37,7 @@ export async function runMultiFolderScan(params) {
|
|
|
35
37
|
for (const { scanInput, subfolder } of folders) {
|
|
36
38
|
if (scanInput.packages.length === 0)
|
|
37
39
|
continue;
|
|
38
|
-
if (!params.options.json && !params.options.ratchet) {
|
|
40
|
+
if (!params.options.json && !params.options.ratchet && !isOutputStdout(params.options.output)) {
|
|
39
41
|
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${subfolder}/`)}\n`);
|
|
40
42
|
}
|
|
41
43
|
const subfolderAbs = path.join(params.projectRoot, subfolder);
|
|
@@ -44,7 +46,7 @@ export async function runMultiFolderScan(params) {
|
|
|
44
46
|
directDependencyNames,
|
|
45
47
|
scanSource: scanInput.source,
|
|
46
48
|
scanFilePath: scanInput.filePath,
|
|
47
|
-
},
|
|
49
|
+
}, params.debugLog, params.fetchImpl);
|
|
48
50
|
// Mirror single-folder scanProject: annotate / filter by source imports per subfolder.
|
|
49
51
|
let usageTruncated = false;
|
|
50
52
|
if (params.options.usage) {
|
|
@@ -115,6 +117,8 @@ export async function runMultiFolderScan(params) {
|
|
|
115
117
|
});
|
|
116
118
|
overrideFindings = outcome.findings;
|
|
117
119
|
overrideSkipped = outcome.skipped;
|
|
120
|
+
if (overrideSkipped.length > 0)
|
|
121
|
+
params.debugLog?.("Rules skipped", { projectPath: subfolderAbs, rules: overrideSkipped });
|
|
118
122
|
}
|
|
119
123
|
// Maintenance from the baseline-filtered set. Skipped under --ratchet because
|
|
120
124
|
// that path always early-exits on CVE save/gate (same as single-folder).
|
|
@@ -127,7 +131,7 @@ export async function runMultiFolderScan(params) {
|
|
|
127
131
|
let licenseLimitedToDirectOnly = false;
|
|
128
132
|
if (params.options.checkLicenses && !params.options.ratchet) {
|
|
129
133
|
const directDeps = scanInput.packages.filter(p => directDependencyNames?.has(p.name));
|
|
130
|
-
const isNpm = scanInput.source
|
|
134
|
+
const isNpm = isNpmLockSource(scanInput.source);
|
|
131
135
|
const licenseResult = await detectLicenseIssues({
|
|
132
136
|
lockfilePath: scanInput.filePath,
|
|
133
137
|
directDeps,
|
|
@@ -167,18 +171,24 @@ function handleMultiFolderRatchet(results, projectRoot, options) {
|
|
|
167
171
|
let anyFirstRunGateFailure = false;
|
|
168
172
|
let hasDetectionGaps = false;
|
|
169
173
|
const baselinesToCommit = [];
|
|
174
|
+
const isStdout = isOutputStdout(options.output);
|
|
170
175
|
for (const r of results) {
|
|
171
|
-
|
|
172
|
-
|
|
176
|
+
if (!isStdout) {
|
|
177
|
+
for (const warning of r.scanInput.warnings) {
|
|
178
|
+
console.log(chalk.yellow(warning));
|
|
179
|
+
}
|
|
173
180
|
}
|
|
174
181
|
const { hasDetectionGap } = getCompletenessImpact(r.completeness);
|
|
175
182
|
if (hasDetectionGap) {
|
|
176
183
|
hasDetectionGaps = true;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
184
|
+
r.acceptedFindings = [];
|
|
185
|
+
if (!isStdout) {
|
|
186
|
+
console.log(chalk.red(`${r.subfolder}/: Scan data is incomplete. Refusing to create or evaluate a baseline from partial detection data.`));
|
|
187
|
+
for (const diagnostic of r.completeness.diagnostics) {
|
|
188
|
+
if (diagnostic.impact !== "detection")
|
|
189
|
+
continue;
|
|
190
|
+
console.log(chalk.red(` ${formatDiagnosticMessage(diagnostic.code, diagnostic.count, diagnostic.affectedPackageCount)}`));
|
|
191
|
+
}
|
|
182
192
|
}
|
|
183
193
|
continue;
|
|
184
194
|
}
|
|
@@ -187,12 +197,15 @@ function handleMultiFolderRatchet(results, projectRoot, options) {
|
|
|
187
197
|
const outcome = ratchetOutcome(baseline, r.sorted);
|
|
188
198
|
if (outcome.action === "save") {
|
|
189
199
|
writeBaseline(subfolderAbs, r.sorted);
|
|
200
|
+
r.acceptedFindings = [];
|
|
190
201
|
const count = r.sorted.length;
|
|
191
|
-
|
|
202
|
+
if (!isStdout) {
|
|
203
|
+
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.`));
|
|
204
|
+
}
|
|
192
205
|
const gateLine = failingGateSummary([{ label: GATE_CLASS_LABELS.vulnerability, findings: r.sorted }], options.failOn);
|
|
193
206
|
if (gateLine) {
|
|
194
207
|
anyFirstRunGateFailure = true;
|
|
195
|
-
if (!options.json) {
|
|
208
|
+
if (!options.json && !isStdout) {
|
|
196
209
|
console.log(chalk.red(`${r.subfolder}/: ${gateLine}`));
|
|
197
210
|
}
|
|
198
211
|
}
|
|
@@ -203,38 +216,102 @@ function handleMultiFolderRatchet(results, projectRoot, options) {
|
|
|
203
216
|
}
|
|
204
217
|
const { newFindings, suppressedCount } = outcome;
|
|
205
218
|
const suppressedLabel = `${suppressedCount} existing ${pluralize(suppressedCount, "finding")} suppressed`;
|
|
219
|
+
r.acceptedFindings = r.sorted.filter(f => !newFindings.includes(f));
|
|
220
|
+
r.sorted = newFindings;
|
|
221
|
+
r.suppressedCount = suppressedCount;
|
|
206
222
|
if (newFindings.length === 0) {
|
|
207
|
-
|
|
223
|
+
if (!isStdout) {
|
|
224
|
+
console.log(chalk.green(`✓ ${r.subfolder}/: No new findings above baseline - ${suppressedLabel}`));
|
|
225
|
+
}
|
|
208
226
|
continue;
|
|
209
227
|
}
|
|
210
228
|
anyNewFindings = true;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
229
|
+
if (!isStdout) {
|
|
230
|
+
console.log(chalk.red(`${r.subfolder}/: ${newFindings.length} new ${pluralize(newFindings.length, "finding")} above baseline - ${suppressedLabel}`));
|
|
231
|
+
for (const f of newFindings) {
|
|
232
|
+
const ids = f.vulnerabilities.map(v => v.id).join(", ");
|
|
233
|
+
console.log(` ${chalk.yellow(f.severity)} ${f.pkg.name}@${f.pkg.version}${ids ? ` (${ids})` : ""}`);
|
|
234
|
+
}
|
|
215
235
|
}
|
|
216
236
|
}
|
|
217
237
|
// One hint for every saved baseline that carries debt, rather than one per folder.
|
|
218
|
-
if (baselinesToCommit.length > 0 && !options.json) {
|
|
238
|
+
if (baselinesToCommit.length > 0 && !options.json && !isStdout) {
|
|
219
239
|
console.log(chalk.gray(`Commit ${baselinesToCommit.join(", ")} ${RATCHET_BASELINE_COMMIT_HINT}`));
|
|
220
240
|
}
|
|
221
241
|
if (hasDetectionGaps) {
|
|
222
242
|
return EXIT_ERROR;
|
|
223
243
|
}
|
|
224
|
-
if (options.checkOverrides) {
|
|
244
|
+
if (options.checkOverrides && !isStdout) {
|
|
225
245
|
console.log(chalk.gray(`Note: override hygiene (--check-overrides) is not part of the ratchet baseline; run \`${OVERRIDES_COMMAND}\` to audit overrides.`));
|
|
226
246
|
}
|
|
227
247
|
if (anyNewFindings) {
|
|
228
|
-
|
|
248
|
+
if (!isStdout) {
|
|
249
|
+
console.log(chalk.gray("To accept these, re-baseline intentionally by deleting the folder's .cve-lite/baseline.json and re-running --ratchet."));
|
|
250
|
+
}
|
|
229
251
|
return EXIT_FINDINGS;
|
|
230
252
|
}
|
|
231
253
|
return anyFirstRunGateFailure ? EXIT_FINDINGS : EXIT_OK;
|
|
232
254
|
}
|
|
255
|
+
async function writeMultiFolderJson(results, projectRoot, options, onScanJsonPath) {
|
|
256
|
+
// Match single-folder writeOutputs: timestamped file in cwd, not stdout dump.
|
|
257
|
+
// Help text and CI both treat --json as "save a JSON file".
|
|
258
|
+
const payload = buildMultiFolderScanJson({
|
|
259
|
+
results,
|
|
260
|
+
projectPath: projectRoot,
|
|
261
|
+
includeOverrides: !!options.checkOverrides,
|
|
262
|
+
includeMaintenance: !!options.checkMaintenance,
|
|
263
|
+
includeLicenses: !!options.checkLicenses,
|
|
264
|
+
// Saved-artifact provenance for the --json payload (#1296).
|
|
265
|
+
provenance: { cliVersion: getCliVersion(), options },
|
|
266
|
+
});
|
|
267
|
+
const target = resolveOutputTarget(options.output);
|
|
268
|
+
const jsonContent = JSON.stringify(payload, null, 2);
|
|
269
|
+
if (target.isStdout) {
|
|
270
|
+
process.stdout.write(jsonContent + "\n");
|
|
271
|
+
await drainStdout();
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
275
|
+
const jsonFilename = target.isFile && target.filename ? target.filename : `cve-lite-scan-${ts}.json`;
|
|
276
|
+
const jsonOutputPath = path.join(target.dir, jsonFilename);
|
|
277
|
+
if (target.isFile && target.filename) {
|
|
278
|
+
const warning = checkFormatExtensionMismatch(target.filename, "json");
|
|
279
|
+
if (warning) {
|
|
280
|
+
console.warn(chalk.yellow(`Warning: ${warning}`));
|
|
281
|
+
}
|
|
282
|
+
const tempFilename = `.${target.filename}.${randomUUID()}.tmp`;
|
|
283
|
+
const tempPath = path.join(target.dir, tempFilename);
|
|
284
|
+
try {
|
|
285
|
+
fs.writeFileSync(tempPath, jsonContent);
|
|
286
|
+
fs.renameSync(tempPath, jsonOutputPath);
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
try {
|
|
290
|
+
fs.rmSync(tempPath, { force: true });
|
|
291
|
+
}
|
|
292
|
+
catch { /* best-effort cleanup */ }
|
|
293
|
+
throw err;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
fs.writeFileSync(jsonOutputPath, jsonContent);
|
|
298
|
+
}
|
|
299
|
+
onScanJsonPath?.(jsonOutputPath);
|
|
300
|
+
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(displayOutputPath(jsonOutputPath))}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
233
303
|
export async function handleMultiFolderScan(params) {
|
|
234
304
|
const auditLog = params.auditLog ?? NULL_AUDIT_LOG;
|
|
235
305
|
const scanStartedAt = Date.now();
|
|
236
306
|
const results = await runMultiFolderScan(params);
|
|
237
307
|
const scanFinishedAt = Date.now();
|
|
308
|
+
params.debugLog?.("Scan finished", {
|
|
309
|
+
packages: results.reduce((sum, result) => sum + result.allPackages.length, 0),
|
|
310
|
+
});
|
|
311
|
+
params.debugLog?.("Findings classified", {
|
|
312
|
+
direct: results.reduce((sum, result) => sum + result.sorted.filter(f => f.relationship === "direct").length, 0),
|
|
313
|
+
transitive: results.reduce((sum, result) => sum + result.sorted.filter(f => f.relationship === "transitive").length, 0),
|
|
314
|
+
});
|
|
238
315
|
const first = results[0];
|
|
239
316
|
auditLog.emit({
|
|
240
317
|
ts: new Date(scanStartedAt).toISOString(),
|
|
@@ -254,7 +331,12 @@ export async function handleMultiFolderScan(params) {
|
|
|
254
331
|
},
|
|
255
332
|
});
|
|
256
333
|
if (results.length === 0) {
|
|
257
|
-
|
|
334
|
+
if (params.options.json) {
|
|
335
|
+
await writeMultiFolderJson(results, params.projectRoot, params.options, params.onScanJsonPath);
|
|
336
|
+
}
|
|
337
|
+
else if (!isOutputStdout(params.options.output)) {
|
|
338
|
+
console.log(chalk.yellow("No scannable packages found in any subfolder."));
|
|
339
|
+
}
|
|
258
340
|
auditLog.emit({
|
|
259
341
|
ts: new Date(scanFinishedAt).toISOString(),
|
|
260
342
|
type: "scan.finished",
|
|
@@ -277,8 +359,8 @@ export async function handleMultiFolderScan(params) {
|
|
|
277
359
|
});
|
|
278
360
|
return EXIT_ERROR;
|
|
279
361
|
}
|
|
280
|
-
if (params.options.sarif || params.options.cdx) {
|
|
281
|
-
console.error(chalk.yellow("--sarif and --
|
|
362
|
+
if (params.options.sarif || params.options.cdx || params.options.sbom) {
|
|
363
|
+
console.error(chalk.yellow("--sarif, --cdx and --sbom are not yet supported in multi-folder mode. Run cve-lite . from each subfolder individually, or drop the flag to scan all folders."));
|
|
282
364
|
auditLog.emit({
|
|
283
365
|
ts: new Date().toISOString(),
|
|
284
366
|
type: "scan.finished",
|
|
@@ -289,34 +371,20 @@ export async function handleMultiFolderScan(params) {
|
|
|
289
371
|
});
|
|
290
372
|
return EXIT_ERROR;
|
|
291
373
|
}
|
|
374
|
+
let ratchetExitCode;
|
|
292
375
|
if (params.options.ratchet) {
|
|
293
|
-
|
|
376
|
+
ratchetExitCode = handleMultiFolderRatchet(results, params.projectRoot, params.options);
|
|
294
377
|
}
|
|
295
378
|
const aggregatedCompleteness = aggregateMultiFolderCompleteness(results);
|
|
296
379
|
if (params.options.json) {
|
|
297
|
-
|
|
298
|
-
// Help text and CI both treat --json as "save a JSON file".
|
|
299
|
-
const payload = buildMultiFolderScanJson({
|
|
300
|
-
results,
|
|
301
|
-
projectPath: params.projectRoot,
|
|
302
|
-
includeOverrides: !!params.options.checkOverrides,
|
|
303
|
-
includeMaintenance: !!params.options.checkMaintenance,
|
|
304
|
-
includeLicenses: !!params.options.checkLicenses,
|
|
305
|
-
// Saved-artifact provenance for the --json payload (#1296).
|
|
306
|
-
provenance: { cliVersion: getCliVersion(), options: params.options },
|
|
307
|
-
});
|
|
308
|
-
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
309
|
-
const jsonFilename = `cve-lite-scan-${ts}.json`;
|
|
310
|
-
const jsonOutputPath = path.join(resolveOutputDir(params.options.output), jsonFilename);
|
|
311
|
-
fs.writeFileSync(jsonOutputPath, JSON.stringify(payload, null, 2));
|
|
312
|
-
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(displayOutputPath(jsonOutputPath))}`);
|
|
380
|
+
await writeMultiFolderJson(results, params.projectRoot, params.options, params.onScanJsonPath);
|
|
313
381
|
}
|
|
314
|
-
else {
|
|
382
|
+
else if (!params.options.ratchet && !isOutputStdout(params.options.output)) {
|
|
315
383
|
printMultiFolderResults(results, params.options);
|
|
316
384
|
if (params.options.checkOverrides) {
|
|
317
385
|
const { renderOverrideFindings, renderSkippedOverrideRules } = await import("../output/override-findings-terminal.js");
|
|
318
386
|
for (const r of results) {
|
|
319
|
-
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray(
|
|
387
|
+
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray(GATE_CLASS_LABELS.overrideHygiene)}\n`);
|
|
320
388
|
console.log(renderOverrideFindings(r.overrideFindings, { verbose: !!params.options.verbose, projectPath: path.join(params.projectRoot, r.subfolder), rulesSkipped: r.overrideSkipped.length > 0 }));
|
|
321
389
|
if (r.overrideSkipped.length > 0) {
|
|
322
390
|
console.log(renderSkippedOverrideRules(r.overrideSkipped));
|
|
@@ -326,7 +394,7 @@ export async function handleMultiFolderScan(params) {
|
|
|
326
394
|
if (params.options.checkMaintenance) {
|
|
327
395
|
const { renderMaintenanceFindings } = await import("../output/maintenance-terminal.js");
|
|
328
396
|
for (const r of results) {
|
|
329
|
-
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray(
|
|
397
|
+
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray(GATE_CLASS_LABELS.maintenanceRisk)}\n`);
|
|
330
398
|
console.log(renderMaintenanceFindings(r.maintenanceFindings, { verbose: !!params.options.verbose }));
|
|
331
399
|
}
|
|
332
400
|
}
|
|
@@ -370,20 +438,27 @@ export async function handleMultiFolderScan(params) {
|
|
|
370
438
|
// Mirror single-folder exit policy in src/scan/single-scan.ts: CVE + override +
|
|
371
439
|
// maintenance all count toward --fail-on. Without overrides here, multi-folder CI
|
|
372
440
|
// using --check-overrides --fail-on high would exit 0 despite high OA findings.
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
441
|
+
let exitCode;
|
|
442
|
+
if (params.options.ratchet) {
|
|
443
|
+
exitCode = ratchetExitCode;
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
const gateLine = failingGateSummary([
|
|
447
|
+
{ label: GATE_CLASS_LABELS.vulnerability, findings: allSorted },
|
|
448
|
+
{ label: GATE_CLASS_LABELS.overrideHygiene, findings: allOverrideFindings },
|
|
449
|
+
{ label: GATE_CLASS_LABELS.maintenanceRisk, findings: allMaintenanceFindings },
|
|
450
|
+
], params.options.failOn);
|
|
451
|
+
const shouldFail = gateLine !== null;
|
|
452
|
+
const incompleteFailure = shouldFailForIncompleteScan(aggregatedCompleteness, params.options.incompletePolicy);
|
|
453
|
+
exitCode = incompleteFailure
|
|
454
|
+
? EXIT_ERROR
|
|
455
|
+
: shouldFail
|
|
456
|
+
? EXIT_FINDINGS
|
|
457
|
+
: EXIT_OK;
|
|
458
|
+
if (gateLine && !params.options.json && !isOutputStdout(params.options.output)) {
|
|
459
|
+
console.log(chalk.red(gateLine));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
387
462
|
auditLog.emit({
|
|
388
463
|
ts: new Date(scanFinishedAt).toISOString(),
|
|
389
464
|
type: "scan.finished",
|
package/dist/scan/single-scan.js
CHANGED
|
@@ -15,6 +15,7 @@ import { GATE_CLASS_LABELS, countBySeverity, failingGateSummary } from "../utils
|
|
|
15
15
|
import { buildReportData, writeHtmlReport } from "../output/html-reporter.js";
|
|
16
16
|
import { buildScanJson } from "../output/scan-json.js";
|
|
17
17
|
import { writeOutputs } from "../output/write-outputs.js";
|
|
18
|
+
import { isOutputStdout } from "../output/output-dir.js";
|
|
18
19
|
import { selectFindingsForTable } from "../output/finding-display.js";
|
|
19
20
|
import { printActionSummary, printCompactOutput, printCoverage, printFinalStatus, printOverrideHint, printSkippedDependencies, printSuggestedFixCommands, printSuggestedFixCommandSkips, printSummary, printTable, } from "../output/printers.js";
|
|
20
21
|
import { renderOverrideFindings, renderSkippedOverrideRules } from "../output/override-findings-terminal.js";
|
|
@@ -30,8 +31,9 @@ import { buildCveFixAppliedEvent } from "../audit-log/events.js";
|
|
|
30
31
|
import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "../utils/baseline.js";
|
|
31
32
|
import { formatDiagnosticMessage, getCompletenessImpact, shouldFailForIncompleteScan } from "./completeness.js";
|
|
32
33
|
import { packageManagerForSource, resolveRegistryConfig } from "../utils/registry-config.js";
|
|
34
|
+
import { isNpmLockSource } from "../utils/package-manager-source.js";
|
|
33
35
|
export async function handleSingleFolderScan(params) {
|
|
34
|
-
const { projectPath, projectArg, batchSize, searchDepth, options, debugLog, fetchImpl, auditLog, scanStartedAt, cliVersion, } = params;
|
|
36
|
+
const { projectPath, projectArg, batchSize, searchDepth, options, debugLog, fetchImpl, auditLog, scanStartedAt, cliVersion, onScanJsonPath, } = params;
|
|
35
37
|
let advisorySourceLine = "";
|
|
36
38
|
let advisoryDbFreshnessLine = null;
|
|
37
39
|
let advisoryDbWarning = null;
|
|
@@ -67,7 +69,7 @@ export async function handleSingleFolderScan(params) {
|
|
|
67
69
|
}
|
|
68
70
|
throw error;
|
|
69
71
|
}
|
|
70
|
-
if (!options.json && !options.ratchet) {
|
|
72
|
+
if (!options.json && !options.ratchet && !isOutputStdout(options.output)) {
|
|
71
73
|
if (options.offline || options.offlineDb) {
|
|
72
74
|
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
73
75
|
}
|
|
@@ -89,7 +91,7 @@ export async function handleSingleFolderScan(params) {
|
|
|
89
91
|
projectPath,
|
|
90
92
|
packageManager: packageManagerForSource(scanInput.source),
|
|
91
93
|
});
|
|
92
|
-
if (reportedRegistry.sourceFile && !options.json && !options.ratchet) {
|
|
94
|
+
if (reportedRegistry.sourceFile && !options.json && !options.ratchet && !isOutputStdout(options.output)) {
|
|
93
95
|
console.log(`${chalk.gray("Package registry:")} ${reportedRegistry.registry} ${chalk.gray(`(from ${reportedRegistry.sourceFile})`)}`);
|
|
94
96
|
}
|
|
95
97
|
if (scanInput.filePath) {
|
|
@@ -141,7 +143,7 @@ export async function handleSingleFolderScan(params) {
|
|
|
141
143
|
});
|
|
142
144
|
return 0;
|
|
143
145
|
}
|
|
144
|
-
if (!options.json && !options.ratchet)
|
|
146
|
+
if (!options.json && !options.ratchet && !isOutputStdout(options.output))
|
|
145
147
|
console.log();
|
|
146
148
|
let scanState = await scanProject({
|
|
147
149
|
scanInput,
|
|
@@ -181,6 +183,9 @@ export async function handleSingleFolderScan(params) {
|
|
|
181
183
|
});
|
|
182
184
|
overrideFindings = outcome.findings;
|
|
183
185
|
overrideSkipped = outcome.skipped;
|
|
186
|
+
if (overrideSkipped.length > 0) {
|
|
187
|
+
debugLog("Rules skipped", { rules: overrideSkipped });
|
|
188
|
+
}
|
|
184
189
|
}
|
|
185
190
|
let maintenanceFindings = [];
|
|
186
191
|
let licenseFindings = [];
|
|
@@ -387,13 +392,16 @@ export async function handleSingleFolderScan(params) {
|
|
|
387
392
|
return exitCode;
|
|
388
393
|
};
|
|
389
394
|
if (options.ratchet) {
|
|
395
|
+
const isStdout = isOutputStdout(options.output);
|
|
390
396
|
const { hasDetectionGap } = getCompletenessImpact(scanState.completeness);
|
|
391
397
|
if (hasDetectionGap) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
398
|
+
if (!isStdout) {
|
|
399
|
+
console.log(chalk.red("Scan data is incomplete. Refusing to create or evaluate a baseline from partial detection data."));
|
|
400
|
+
for (const diagnostic of scanState.completeness.diagnostics) {
|
|
401
|
+
if (diagnostic.impact !== "detection")
|
|
402
|
+
continue;
|
|
403
|
+
console.log(chalk.red(` ${formatDiagnosticMessage(diagnostic.code, diagnostic.count, diagnostic.affectedPackageCount)}`));
|
|
404
|
+
}
|
|
397
405
|
}
|
|
398
406
|
// Writes the requested artefact too, and accepts nothing: the baseline was never
|
|
399
407
|
// evaluated, so claiming anything is accepted would be a lie. This is the path where
|
|
@@ -405,16 +413,18 @@ export async function handleSingleFolderScan(params) {
|
|
|
405
413
|
if (outcome.action === "save") {
|
|
406
414
|
writeBaseline(projectArg ?? ".", scanState.sorted);
|
|
407
415
|
const count = scanState.sorted.length;
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
416
|
+
if (!isStdout) {
|
|
417
|
+
console.log(chalk.green(`✓ Baseline saved to .cve-lite/baseline.json with ${count} ${count === 1 ? "finding" : "findings"}. Future scans will only report findings above this baseline.`));
|
|
418
|
+
if (options.checkOverrides) {
|
|
419
|
+
console.log(chalk.gray(`Note: override hygiene (--check-overrides) is not part of the ratchet baseline; run \`${OVERRIDES_COMMAND}\` to audit overrides.`));
|
|
420
|
+
}
|
|
411
421
|
}
|
|
412
422
|
// A missing baseline accepts no debt, including on fresh CI checkouts.
|
|
413
423
|
const gateLine = failingGateSummary([{ label: GATE_CLASS_LABELS.vulnerability, findings: scanState.sorted }], options.failOn);
|
|
414
|
-
if (gateLine && !options.json && !options.fix) {
|
|
424
|
+
if (gateLine && !options.json && !isStdout && !options.fix) {
|
|
415
425
|
console.log(chalk.red(gateLine));
|
|
416
426
|
}
|
|
417
|
-
if (count > 0 && !options.json) {
|
|
427
|
+
if (count > 0 && !options.json && !isStdout) {
|
|
418
428
|
console.log(chalk.gray(`Commit .cve-lite/baseline.json ${RATCHET_BASELINE_COMMIT_HINT}`));
|
|
419
429
|
}
|
|
420
430
|
const exitCode = gateLine && !options.fix ? 1 : 0;
|
|
@@ -424,17 +434,21 @@ export async function handleSingleFolderScan(params) {
|
|
|
424
434
|
const { newFindings, suppressedCount: sc } = outcome;
|
|
425
435
|
const suppressedLabel = `${sc} existing ${sc === 1 ? "finding" : "findings"} suppressed`;
|
|
426
436
|
if (newFindings.length === 0) {
|
|
427
|
-
|
|
437
|
+
if (!isStdout) {
|
|
438
|
+
console.log(chalk.green(`No new findings above baseline - ${suppressedLabel}`));
|
|
439
|
+
}
|
|
428
440
|
// Nothing actionable, so the artefact carries an empty finding set and records what the
|
|
429
441
|
// baseline is holding. Writing no file at all is what made accepted debt look resolved.
|
|
430
442
|
return finishRatchetRun([], scanState.sorted, 0);
|
|
431
443
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
|
|
444
|
+
if (!isStdout) {
|
|
445
|
+
console.log(chalk.red(`${newFindings.length} new ${newFindings.length === 1 ? "finding" : "findings"} above baseline - ${suppressedLabel}`));
|
|
446
|
+
for (const f of newFindings) {
|
|
447
|
+
const ids = f.vulnerabilities.map(v => v.id).join(", ");
|
|
448
|
+
console.log(` ${chalk.yellow(f.severity)} ${f.pkg.name}@${f.pkg.version}${ids ? ` (${ids})` : ""}`);
|
|
449
|
+
}
|
|
450
|
+
console.log(chalk.gray("To accept these, re-baseline intentionally by deleting .cve-lite/baseline.json and re-running --ratchet."));
|
|
436
451
|
}
|
|
437
|
-
console.log(chalk.gray("To accept these, re-baseline intentionally by deleting .cve-lite/baseline.json and re-running --ratchet."));
|
|
438
452
|
// The build fails here because something new appeared, which is exactly the run where a
|
|
439
453
|
// machine-readable artefact matters most, and it produced none.
|
|
440
454
|
const acceptedHere = scanState.sorted.filter(f => !newFindings.includes(f));
|
|
@@ -466,13 +480,13 @@ export async function handleSingleFolderScan(params) {
|
|
|
466
480
|
const licenseResult = await detectLicenseIssues({
|
|
467
481
|
lockfilePath: scanInput.filePath,
|
|
468
482
|
directDeps,
|
|
469
|
-
isNpm: scanInput.source
|
|
483
|
+
isNpm: isNpmLockSource(scanInput.source),
|
|
470
484
|
isOffline: !!options.offline || !!options.offlineDb,
|
|
471
485
|
});
|
|
472
486
|
licenseFindings = licenseResult.findings;
|
|
473
487
|
licenseLimitedToDirectOnly = licenseResult.limitedToDirectOnly;
|
|
474
488
|
}
|
|
475
|
-
await writeOutputs(options, {
|
|
489
|
+
const scanJsonPath = await writeOutputs(options, {
|
|
476
490
|
registry: reportedRegistry,
|
|
477
491
|
sorted: scanState.sorted,
|
|
478
492
|
allPackages: scanState.allPackages,
|
|
@@ -489,7 +503,9 @@ export async function handleSingleFolderScan(params) {
|
|
|
489
503
|
licenseFindings,
|
|
490
504
|
licenseLimitedToDirectOnly,
|
|
491
505
|
}, scanInput, projectPath);
|
|
492
|
-
if (
|
|
506
|
+
if (scanJsonPath)
|
|
507
|
+
onScanJsonPath?.(scanJsonPath);
|
|
508
|
+
if (!isOutputStdout(options.output) && (!(options.json || options.sarif || options.sbom) || options.verbose)) {
|
|
493
509
|
const offline = !!options.offline || !!options.offlineDb;
|
|
494
510
|
const showOverrideHint = !options.checkOverrides && !options.ratchet && hasOverrideEntries(projectPath);
|
|
495
511
|
if (options.verbose) {
|
|
@@ -620,7 +636,7 @@ export async function handleSingleFolderScan(params) {
|
|
|
620
636
|
findings: scanState.sorted.length,
|
|
621
637
|
packages: packages.length,
|
|
622
638
|
});
|
|
623
|
-
if (baseline) {
|
|
639
|
+
if (baseline && !isOutputStdout(options.output)) {
|
|
624
640
|
if (scanState.sorted.length === 0) {
|
|
625
641
|
console.log(chalk.green(`No new findings above baseline - ${suppressedCount} existing ${suppressedCount === 1 ? "finding" : "findings"} suppressed`));
|
|
626
642
|
}
|
|
@@ -640,7 +656,7 @@ export async function handleSingleFolderScan(params) {
|
|
|
640
656
|
{ label: GATE_CLASS_LABELS.maintenanceRisk, findings: maintenanceFindings },
|
|
641
657
|
], options.failOn);
|
|
642
658
|
const shouldFail = gateLine !== null;
|
|
643
|
-
if (gateLine && !options.json && !options.fix)
|
|
659
|
+
if (gateLine && !options.json && !isOutputStdout(options.output) && !options.fix)
|
|
644
660
|
console.log(chalk.red(gateLine));
|
|
645
661
|
// In fix mode, remaining transitive findings cannot be auto-fixed.
|
|
646
662
|
// Exiting non-zero would prevent the Action PR step from running.
|