cve-lite-cli 1.41.5 → 1.42.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 +22 -19
- package/dist/advisory/detail-resolution.js +62 -0
- package/dist/advisory/local-db.js +90 -15
- package/dist/advisory/osv-advisory-source.js +113 -62
- package/dist/advisory/osv-sync.js +18 -16
- package/dist/advisory/sqlite.js +50 -0
- package/dist/audit-log/ndjson-writer.js +6 -3
- package/dist/audit-log/open-error.js +22 -0
- package/dist/cli/args.js +145 -87
- package/dist/cli/flags.js +2 -0
- package/dist/cli/help.js +6 -2
- package/dist/cli/overrides.js +5 -2
- package/dist/cli/validate.js +45 -5
- package/dist/constants.js +10 -0
- package/dist/index.js +15 -6
- package/dist/licenses/license-check.js +17 -4
- package/dist/osv/cache.js +7 -13
- package/dist/output/cyclonedx.js +57 -18
- package/dist/output/finding-display.js +8 -1
- package/dist/output/formatters.js +52 -11
- package/dist/output/html-reporter.js +40 -8
- package/dist/output/override-findings-terminal.js +21 -13
- package/dist/output/printers.js +185 -76
- package/dist/output/sarif.js +182 -16
- package/dist/output/spdx.js +15 -1
- package/dist/output/write-outputs.js +29 -20
- package/dist/overrides/context-builder.js +1 -7
- package/dist/overrides/detectors/oa005-nested-ineffective.js +6 -1
- package/dist/overrides/detectors/oa008-materialized.js +33 -10
- package/dist/overrides/detectors/oa009-stale-floor.js +2 -2
- package/dist/overrides/detectors/oa010-vulnerable-floor.js +19 -13
- package/dist/overrides/detectors/phantom-utils.js +2 -10
- package/dist/overrides/fixer.js +13 -2
- package/dist/overrides/index.js +1 -0
- package/dist/overrides/types.js +15 -1
- package/dist/parsers/bun-lock.js +6 -0
- package/dist/parsers/index.js +177 -40
- package/dist/parsers/multi-package.js +4 -0
- package/dist/parsers/package-lock.js +6 -2
- package/dist/parsers/pnpm-lock.js +4 -7
- package/dist/parsers/requirements-txt.js +185 -0
- package/dist/parsers/utils.js +11 -6
- package/dist/parsers/yarn-lock.js +1 -5
- package/dist/remediation/fix-commands.js +60 -36
- package/dist/remediation/parent-update-child-note.js +3 -2
- package/dist/scan/completeness.js +57 -4
- package/dist/scan/multi-folder-scan.js +27 -13
- package/dist/scan/single-scan.js +118 -37
- package/dist/scanner.js +59 -36
- package/dist/types.js +1 -1
- package/dist/utils/array.js +5 -0
- package/dist/utils/baseline.js +8 -2
- package/dist/utils/chalk.js +1 -3
- package/dist/utils/create-pr.js +2 -2
- package/dist/utils/debug-bundle.js +37 -22
- package/dist/utils/debug-project.js +6 -5
- package/dist/utils/debug-redaction.js +1 -1
- package/dist/utils/effective-options.js +5 -1
- package/dist/utils/finding.js +4 -0
- package/dist/utils/fix-runner.js +110 -36
- package/dist/utils/import-type-queries.js +5 -1
- package/dist/utils/install-command.js +6 -0
- package/dist/utils/malicious.js +11 -0
- package/dist/utils/package-identity.js +12 -2
- package/dist/utils/path-coverage.js +1 -5
- package/dist/utils/sanitize.js +59 -0
- package/dist/utils/sbom-format.js +17 -8
- package/dist/utils/severity.js +61 -7
- package/dist/utils/url.js +175 -0
- package/dist/utils/version.js +44 -0
- package/dist/utils/vuln.js +11 -14
- package/package.json +2 -4
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { parse as parseYarnLock } from "yarn-lockfile";
|
|
4
4
|
import { npmAliasRegistryName, packageInstanceKey } from "../utils/package-identity.js";
|
|
5
5
|
import { normalizeRawVersion } from "../utils/version.js";
|
|
6
|
+
import { pathsEqual } from "../utils/array.js";
|
|
6
7
|
import { upsertPackage, MAX_PATHS_PER_PACKAGE } from "./utils.js";
|
|
7
8
|
const MAX_PATH_DEPTH = 10;
|
|
8
9
|
// Record a display path for a package, matching the existing de-dup + cap behavior (keep the
|
|
@@ -130,11 +131,6 @@ function readWorkspacePackages(filePath, rootPkg) {
|
|
|
130
131
|
export function isYarnBerry(content) {
|
|
131
132
|
return content.startsWith('__metadata:') || content.includes('\n__metadata:');
|
|
132
133
|
}
|
|
133
|
-
function pathsEqual(left, right) {
|
|
134
|
-
if (left.length !== right.length)
|
|
135
|
-
return false;
|
|
136
|
-
return left.every((value, index) => value === right[index]);
|
|
137
|
-
}
|
|
138
134
|
export function parseYarnPackageKey(key) {
|
|
139
135
|
const idx = key.lastIndexOf("@");
|
|
140
136
|
if (idx <= 0)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { severityOrder } from "../constants.js";
|
|
3
|
-
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
3
|
+
import { compareVersions, isPep440Ecosystem, looksLikeVersion } from "../utils/version.js";
|
|
4
4
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
5
5
|
import { isNpmLockSource, packageManagerForSource } from "../utils/package-manager-source.js";
|
|
6
6
|
import { calculatePathCoverage, formatDependencyPath } from "../utils/path-coverage.js";
|
|
7
7
|
import { pluralize } from "../utils/string.js";
|
|
8
8
|
import { isSafeInEveryShell, quoteShellPath, shellQuote } from "../utils/shell-quote.js";
|
|
9
|
+
import { INSTALL_COMMANDS } from "../utils/install-command.js";
|
|
9
10
|
import { buildNpmWorkspaceMap } from "../parsers/package-lock.js";
|
|
10
11
|
import { buildPnpmWorkspaceMap } from "../parsers/pnpm-lock.js";
|
|
11
12
|
import { buildYarnWorkspaceMap } from "../parsers/yarn-lock.js";
|
|
@@ -84,6 +85,8 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
84
85
|
}),
|
|
85
86
|
];
|
|
86
87
|
for (const finding of orderedFindings) {
|
|
88
|
+
if (isPep440Ecosystem(finding.pkg.ecosystem))
|
|
89
|
+
continue;
|
|
87
90
|
const urgent = finding.severity === "critical" || finding.severity === "high";
|
|
88
91
|
if (finding.relationship === "direct") {
|
|
89
92
|
const hasValidatedField = Object.prototype.hasOwnProperty.call(finding, "validatedFirstFixedVersion");
|
|
@@ -116,7 +119,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
116
119
|
if (directTarget &&
|
|
117
120
|
isUpgradeTarget(finding.pkg.version, directTarget) &&
|
|
118
121
|
validatedFieldOk) {
|
|
119
|
-
const pkgWorkspaces = workspaceMap.get(packageNameKey(finding.pkg))
|
|
122
|
+
const pkgWorkspaces = resolveTargetWorkspaces(packageManager, workspaceMap.get(packageNameKey(finding.pkg)));
|
|
120
123
|
upsertTarget(targetsByKey, skippedByKey, finding, {
|
|
121
124
|
package: finding.pkg.name,
|
|
122
125
|
...(finding.pkg.registryName ? { registryName: finding.pkg.registryName } : {}),
|
|
@@ -138,7 +141,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
138
141
|
: null,
|
|
139
142
|
reason: `Direct upgrade target for ${finding.pkg.name}@${finding.pkg.version}`,
|
|
140
143
|
usage: finding.usage ?? null,
|
|
141
|
-
workspaces: pkgWorkspaces
|
|
144
|
+
workspaces: pkgWorkspaces,
|
|
142
145
|
isDev: finding.pkg.dev ?? false,
|
|
143
146
|
fixVersionPublishedAt: finding.fixVersionPublishedAt ?? null,
|
|
144
147
|
});
|
|
@@ -220,7 +223,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
220
223
|
const chainForNpmRemediation = finding.chainResolution?.directDep === finding.recommendedNpmTransitiveRemediation.package
|
|
221
224
|
? finding.chainResolution
|
|
222
225
|
: null;
|
|
223
|
-
const npmParentUpgradeWorkspaces = workspaceMap.get(finding.recommendedNpmTransitiveRemediation.package)
|
|
226
|
+
const npmParentUpgradeWorkspaces = resolveTargetWorkspaces(packageManager, workspaceMap.get(finding.recommendedNpmTransitiveRemediation.package));
|
|
224
227
|
upsertTarget(targetsByKey, skippedByKey, finding, {
|
|
225
228
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
226
229
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
@@ -238,7 +241,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
238
241
|
remainingPaths: coverage.remainingPaths,
|
|
239
242
|
usage: finding.usage ?? null,
|
|
240
243
|
isDev: devLookup.get(`${finding.recommendedNpmTransitiveRemediation.package}@${finding.recommendedNpmTransitiveRemediation.currentVersion}`) ?? false,
|
|
241
|
-
workspaces: npmParentUpgradeWorkspaces
|
|
244
|
+
workspaces: npmParentUpgradeWorkspaces,
|
|
242
245
|
chainProof: chainForNpmRemediation?.chain,
|
|
243
246
|
chainSafeVersion: chainForNpmRemediation?.safeVersion,
|
|
244
247
|
chainVulnerablePackage: chainForNpmRemediation ? finding.pkg.name : undefined,
|
|
@@ -252,7 +255,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
252
255
|
const chainForParentUpgrade = finding.chainResolution?.directDep === finding.recommendedParentUpgrade.package
|
|
253
256
|
? finding.chainResolution
|
|
254
257
|
: null;
|
|
255
|
-
const parentUpgradeWorkspaces = workspaceMap.get(finding.recommendedParentUpgrade.package)
|
|
258
|
+
const parentUpgradeWorkspaces = resolveTargetWorkspaces(packageManager, workspaceMap.get(finding.recommendedParentUpgrade.package));
|
|
256
259
|
upsertTarget(targetsByKey, skippedByKey, finding, {
|
|
257
260
|
package: finding.recommendedParentUpgrade.package,
|
|
258
261
|
currentVersion: finding.recommendedParentUpgrade.currentVersion,
|
|
@@ -270,7 +273,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
270
273
|
remainingPaths: coverage.remainingPaths,
|
|
271
274
|
usage: finding.usage ?? null,
|
|
272
275
|
isDev: devLookup.get(`${finding.recommendedParentUpgrade.package}@${finding.recommendedParentUpgrade.currentVersion}`) ?? false,
|
|
273
|
-
workspaces: parentUpgradeWorkspaces
|
|
276
|
+
workspaces: parentUpgradeWorkspaces,
|
|
274
277
|
chainProof: chainForParentUpgrade?.chain,
|
|
275
278
|
chainSafeVersion: chainForParentUpgrade?.safeVersion,
|
|
276
279
|
chainVulnerablePackage: chainForParentUpgrade ? finding.pkg.name : undefined,
|
|
@@ -310,7 +313,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
310
313
|
if (finding.chainResolution) {
|
|
311
314
|
const isDev = devLookup.get(`${finding.chainResolution.directDep}@${finding.chainResolution.directDepCurrentVersion}`) ?? false;
|
|
312
315
|
const coverage = calculatePathCoverage(finding.dependencyPaths, [finding.chainResolution.directDep]);
|
|
313
|
-
const chainWorkspaces = workspaceMap.get(finding.chainResolution.directDep)
|
|
316
|
+
const chainWorkspaces = resolveTargetWorkspaces(packageManager, workspaceMap.get(finding.chainResolution.directDep));
|
|
314
317
|
upsertTarget(targetsByKey, skippedByKey, finding, {
|
|
315
318
|
package: finding.chainResolution.directDep,
|
|
316
319
|
currentVersion: finding.chainResolution.directDepCurrentVersion,
|
|
@@ -327,7 +330,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
327
330
|
chainVulnerablePackage: finding.pkg.name,
|
|
328
331
|
usage: finding.usage ?? null,
|
|
329
332
|
isDev,
|
|
330
|
-
workspaces: chainWorkspaces
|
|
333
|
+
workspaces: chainWorkspaces,
|
|
331
334
|
});
|
|
332
335
|
continue;
|
|
333
336
|
}
|
|
@@ -366,11 +369,8 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
366
369
|
return a.package.localeCompare(b.package);
|
|
367
370
|
});
|
|
368
371
|
const targets = withholdShellUnsafeTargets(sortedTargets, findings, skippedByKey, options?.subfolder);
|
|
369
|
-
//
|
|
370
|
-
//
|
|
371
|
-
// and embedded in the HTML report, so scope it to the declaring member too.
|
|
372
|
-
// Parent-update commands are rebuilt from the (possibly merged) workspace list
|
|
373
|
-
// so the printed plan matches what --fix will spawn.
|
|
372
|
+
// Explicit commands are exposed in JSON and HTML. Rebuild them from the
|
|
373
|
+
// final targets so they use the merged workspace and dependency scope.
|
|
374
374
|
for (const target of targets) {
|
|
375
375
|
if (target.kind === "parent-update") {
|
|
376
376
|
const updatePkg = target.childPackage ?? target.package;
|
|
@@ -388,10 +388,8 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
388
388
|
}
|
|
389
389
|
continue;
|
|
390
390
|
}
|
|
391
|
-
if (target.command
|
|
392
|
-
|
|
393
|
-
if (scoped.length > 0)
|
|
394
|
-
target.command = scoped.join(" && ");
|
|
391
|
+
if (target.command) {
|
|
392
|
+
target.command = buildWorkspaceInstallCommands([target], packageManager).join(" && ");
|
|
395
393
|
}
|
|
396
394
|
}
|
|
397
395
|
const nowMs = options?.nowMs ?? Date.now();
|
|
@@ -475,14 +473,8 @@ function buildYarnUpgradeCommand(pkg, workspaces) {
|
|
|
475
473
|
function buildBunUpdateCommand(pkg) {
|
|
476
474
|
return `bun update ${shellQuote(pkg)}`;
|
|
477
475
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
return "npm install";
|
|
481
|
-
if (packageManager === "pnpm")
|
|
482
|
-
return "pnpm add";
|
|
483
|
-
if (packageManager === "bun")
|
|
484
|
-
return "bun add";
|
|
485
|
-
return "yarn add";
|
|
476
|
+
function commandPrefix(packageManager) {
|
|
477
|
+
return INSTALL_COMMANDS[packageManager].join(" ");
|
|
486
478
|
}
|
|
487
479
|
/** Format a single install command with a shell-quoted package spec. */
|
|
488
480
|
export function buildPackageInstallCommand(packageManager, packageSpec, flag = "") {
|
|
@@ -492,11 +484,16 @@ function devFlag(packageManager) {
|
|
|
492
484
|
return packageManager === "bun" ? "--dev" : "-D";
|
|
493
485
|
}
|
|
494
486
|
export function findFixTargetForFinding(plan, finding) {
|
|
487
|
+
return findFixTargetAmong(plan.targets, finding);
|
|
488
|
+
}
|
|
489
|
+
// Matches a finding against a bare list of targets, for callers that hold
|
|
490
|
+
// targets but not a finished plan.
|
|
491
|
+
function findFixTargetAmong(targets, finding) {
|
|
495
492
|
// A sibling finding may share the parent upgrade, but a direct dependency
|
|
496
493
|
// keeps this copy installed, so no command in the plan fixes this one.
|
|
497
494
|
if (finding.recommendedParentUpgrade && finding.parentUpgradeBlockers?.length)
|
|
498
495
|
return null;
|
|
499
|
-
const target =
|
|
496
|
+
const target = targets.find(item => {
|
|
500
497
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
501
498
|
const rem = finding.recommendedNpmTransitiveRemediation;
|
|
502
499
|
if (item.kind !== "parent-update")
|
|
@@ -704,9 +701,9 @@ function withholdShellUnsafeTargets(sortedTargets, findings, skippedByKey, subfo
|
|
|
704
701
|
}
|
|
705
702
|
if (withheld.size === 0)
|
|
706
703
|
return kept;
|
|
707
|
-
const
|
|
704
|
+
const withheldTargets = [...withheld.keys()];
|
|
708
705
|
for (const finding of findings) {
|
|
709
|
-
const target =
|
|
706
|
+
const target = findFixTargetAmong(withheldTargets, finding);
|
|
710
707
|
if (!target)
|
|
711
708
|
continue;
|
|
712
709
|
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
@@ -829,6 +826,22 @@ function buildParentUpgradeReason(finding, coverage) {
|
|
|
829
826
|
const remainingCount = coverage.remainingPaths.length;
|
|
830
827
|
return `${base}; run this command, then rescan. ${remainingCount} other known ${pluralize(remainingCount, "path")} may still need separate parent upgrades.`;
|
|
831
828
|
}
|
|
829
|
+
function resolveTargetWorkspaces(packageManager, rawWorkspaces) {
|
|
830
|
+
if (!rawWorkspaces || rawWorkspaces.length === 0)
|
|
831
|
+
return undefined;
|
|
832
|
+
const unique = [...new Set(rawWorkspaces)];
|
|
833
|
+
const nonRoot = unique.filter(w => w !== ".");
|
|
834
|
+
if (nonRoot.length === 0)
|
|
835
|
+
return undefined;
|
|
836
|
+
if (packageManager === "bun") {
|
|
837
|
+
// Bun scopes member installs with --cwd and root installs with a flat
|
|
838
|
+
// command. When declared in both root and members, preserve "." so both
|
|
839
|
+
// commands are emitted. If only declared in root, omit workspaces so a
|
|
840
|
+
// flat command is emitted.
|
|
841
|
+
return unique;
|
|
842
|
+
}
|
|
843
|
+
return nonRoot;
|
|
844
|
+
}
|
|
832
845
|
function mergeStringArrays(a, b) {
|
|
833
846
|
if (!a?.length && !b?.length)
|
|
834
847
|
return undefined;
|
|
@@ -956,6 +969,8 @@ function groupByWorkspaceKey(targets) {
|
|
|
956
969
|
function buildWorkspaceInstallCommands(targets, packageManager) {
|
|
957
970
|
const groups = groupByWorkspaceKey(targets);
|
|
958
971
|
const commands = [];
|
|
972
|
+
const [executable, subcommand] = INSTALL_COMMANDS[packageManager];
|
|
973
|
+
const installPrefix = `${executable} ${subcommand}`;
|
|
959
974
|
for (const [wsKey, groupTargets] of groups) {
|
|
960
975
|
const workspaces = wsKey ? wsKey.split("\0") : [];
|
|
961
976
|
const devTargets = groupTargets.filter(t => t.isDev);
|
|
@@ -967,31 +982,40 @@ function buildWorkspaceInstallCommands(targets, packageManager) {
|
|
|
967
982
|
const flag = isDev ? ` ${devFlag(packageManager)}` : "";
|
|
968
983
|
if (packageManager === "npm") {
|
|
969
984
|
const wsFlags = workspaces.map(ws => `-w ${shellQuote(ws)}`).join(" ");
|
|
970
|
-
commands.push(
|
|
985
|
+
commands.push(`${installPrefix}${flag}${wsFlags ? " " + wsFlags : ""} ${pkgArgs}`);
|
|
971
986
|
}
|
|
972
987
|
else if (packageManager === "pnpm") {
|
|
973
988
|
// pnpm's --filter selector is a CLI-level flag that precedes the command
|
|
974
989
|
// (`pnpm --filter ./client add pkg`), not a trailing argument.
|
|
975
990
|
const wsFlags = workspaces.map(ws => `--filter ${shellQuote("./" + ws)}`).join(" ");
|
|
976
|
-
const prefix = wsFlags ?
|
|
991
|
+
const prefix = wsFlags ? `${executable} ${wsFlags} ${subcommand}` : installPrefix;
|
|
977
992
|
commands.push(`${prefix}${flag} ${pkgArgs}`);
|
|
978
993
|
}
|
|
979
994
|
else if (packageManager === "yarn") {
|
|
980
995
|
if (workspaces.length === 0) {
|
|
981
|
-
commands.push(
|
|
996
|
+
commands.push(`${installPrefix}${flag} ${pkgArgs}`);
|
|
982
997
|
}
|
|
983
998
|
else {
|
|
984
999
|
for (const ws of workspaces) {
|
|
985
|
-
commands.push(
|
|
1000
|
+
commands.push(`${executable} workspace ${shellQuote(ws)} ${subcommand}${flag} ${pkgArgs}`);
|
|
986
1001
|
}
|
|
987
1002
|
}
|
|
988
1003
|
}
|
|
989
1004
|
else if (packageManager === "bun") {
|
|
990
|
-
|
|
991
|
-
|
|
1005
|
+
// --filter for `bun add` only arrived in Bun 1.4.0 and is ignored (or
|
|
1006
|
+
// edits the root manifest) on older releases. --cwd selects the member
|
|
1007
|
+
// directory on every version.
|
|
1008
|
+
const hasRoot = workspaces.includes(".");
|
|
1009
|
+
const nonRoot = workspaces.filter(ws => ws !== ".");
|
|
1010
|
+
if (hasRoot || nonRoot.length === 0) {
|
|
1011
|
+
commands.push(`${installPrefix}${flag} ${pkgArgs}`);
|
|
1012
|
+
}
|
|
1013
|
+
for (const ws of nonRoot) {
|
|
1014
|
+
commands.push(`${installPrefix}${flag} --cwd ${shellQuote(ws)} ${pkgArgs}`);
|
|
1015
|
+
}
|
|
992
1016
|
}
|
|
993
1017
|
else {
|
|
994
|
-
commands.push(`${
|
|
1018
|
+
commands.push(`${installPrefix}${flag} ${pkgArgs}`);
|
|
995
1019
|
}
|
|
996
1020
|
}
|
|
997
1021
|
}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* Context note naming the child a parent-update target refreshes, or null.
|
|
3
3
|
* Leaf module so printers / fix-runner / create-pr can import without cycling through fix-commands.
|
|
4
4
|
*/
|
|
5
|
-
export function formatParentUpdateChildNote(target) {
|
|
5
|
+
export function formatParentUpdateChildNote(target, options) {
|
|
6
6
|
if (target.kind && target.kind !== "parent-update")
|
|
7
7
|
return null;
|
|
8
8
|
if (!target.childPackage || !target.childTargetVersion)
|
|
9
9
|
return null;
|
|
10
|
-
|
|
10
|
+
const child = options?.codeSpan ? `\`${target.childPackage}\`` : target.childPackage;
|
|
11
|
+
return `refresh ${child} to ${target.childTargetVersion}`;
|
|
11
12
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { chalk } from "../utils/chalk.js";
|
|
1
2
|
import { pluralize } from "../utils/string.js";
|
|
2
3
|
export function getCompletenessImpact(completeness) {
|
|
3
4
|
const diagnostics = completeness?.diagnostics ?? [];
|
|
@@ -6,7 +7,12 @@ export function getCompletenessImpact(completeness) {
|
|
|
6
7
|
hasRemediationGap: diagnostics.some(diagnostic => diagnostic.impact === "remediation"),
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
// A scan is partial only when something is missing. A freshness diagnostic
|
|
11
|
+
// records that cached data was used, which leaves the result complete.
|
|
12
|
+
export function isCompleteGivenDiagnostics(diagnostics) {
|
|
13
|
+
return diagnostics.every(diagnostic => diagnostic.impact === "freshness");
|
|
14
|
+
}
|
|
15
|
+
export function formatDiagnosticMessage(code, count, affectedPackageCount, impact, oldestCachedAt, now = Date.now()) {
|
|
10
16
|
switch (code) {
|
|
11
17
|
case "OSV_DETAIL_TRANSIENT_FAILURE":
|
|
12
18
|
return `${count} advisory detail ${pluralize(count, "lookup")} failed with a transient error: re-run to retry.`;
|
|
@@ -14,6 +20,12 @@ export function formatDiagnosticMessage(code, count, affectedPackageCount, impac
|
|
|
14
20
|
return `${count} advisory detail ${pluralize(count, "record")} ${pluralize(count, "is", "are")} missing from the local advisory database: refresh to sync.`;
|
|
15
21
|
case "OSV_DETAIL_CONFIRMED_MISSING":
|
|
16
22
|
return `${count} advisory detail ${pluralize(count, "record")} ${pluralize(count, "is", "are")} confirmed missing from the OSV API: affected findings lack detail data.`;
|
|
23
|
+
case "OSV_DETAIL_STALE_CACHE_USED": {
|
|
24
|
+
const since = oldestCachedAt
|
|
25
|
+
? `, the oldest cached on ${oldestCachedAt.slice(0, 10)}${formatCacheAge(oldestCachedAt, now)}`
|
|
26
|
+
: "";
|
|
27
|
+
return `${count} advisory detail ${pluralize(count, "lookup")} could not be fetched, so cached details were used instead${since}.`;
|
|
28
|
+
}
|
|
17
29
|
case "PACKUMENT_FETCH_FAILURE":
|
|
18
30
|
return `${count} packument ${pluralize(count, "fetch", "fetches")} failed: remediation guidance may be incomplete.`;
|
|
19
31
|
case "REMEDIATION_FAILURE":
|
|
@@ -28,10 +40,22 @@ export function formatDiagnosticMessage(code, count, affectedPackageCount, impac
|
|
|
28
40
|
return `${count} ${pluralize(count, "package")} ${pluralize(count, "has", "have")} an unreadable PyPI advisory boundary, so the fix is inconclusive.`;
|
|
29
41
|
}
|
|
30
42
|
return `${count} ${pluralize(count, "package")} ${pluralize(count, "has", "have")} an unreadable PyPI version or advisory boundary, so vulnerability status could not be determined.`;
|
|
43
|
+
case "SKIPPED_DEPENDENCY":
|
|
44
|
+
return `${count} unsupported or unpinned ${pluralize(count, "dependency", "dependencies")} ${pluralize(count, "was", "were")} skipped: not all dependencies were checked.`;
|
|
45
|
+
case "UNSCANNED_REQUIREMENTS_FILE":
|
|
46
|
+
return `${count} ${pluralize(count, "requirements file was", "requirements files were")} not scanned: not all dependencies were checked.`;
|
|
31
47
|
default:
|
|
32
48
|
return `${count} unknown diagnostic occurred.`;
|
|
33
49
|
}
|
|
34
50
|
}
|
|
51
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
52
|
+
function formatCacheAge(cachedAt, now) {
|
|
53
|
+
const timestamp = Date.parse(cachedAt);
|
|
54
|
+
if (Number.isNaN(timestamp))
|
|
55
|
+
return "";
|
|
56
|
+
const days = Math.floor(Math.max(0, now - timestamp) / DAY_MS);
|
|
57
|
+
return days === 0 ? " (less than a day old)" : ` (${days} ${pluralize(days, "day")} old)`;
|
|
58
|
+
}
|
|
35
59
|
export function aggregateMultiFolderCompleteness(results) {
|
|
36
60
|
const deduped = new Map();
|
|
37
61
|
for (const result of results) {
|
|
@@ -44,19 +68,48 @@ export function aggregateMultiFolderCompleteness(results) {
|
|
|
44
68
|
existing.affectedPackageCount =
|
|
45
69
|
(existing.affectedPackageCount ?? 0) + diagnostic.affectedPackageCount;
|
|
46
70
|
}
|
|
47
|
-
|
|
71
|
+
if (diagnostic.oldestCachedAt !== undefined &&
|
|
72
|
+
(existing.oldestCachedAt === undefined || diagnostic.oldestCachedAt < existing.oldestCachedAt)) {
|
|
73
|
+
existing.oldestCachedAt = diagnostic.oldestCachedAt;
|
|
74
|
+
}
|
|
75
|
+
existing.message = formatDiagnosticMessage(diagnostic.code, existing.count, existing.affectedPackageCount, existing.impact, existing.oldestCachedAt);
|
|
48
76
|
}
|
|
49
77
|
else {
|
|
50
78
|
deduped.set(key, { ...diagnostic });
|
|
51
79
|
}
|
|
52
80
|
}
|
|
53
81
|
}
|
|
54
|
-
|
|
82
|
+
const diagnostics = [...deduped.values()];
|
|
83
|
+
return { complete: isCompleteGivenDiagnostics(diagnostics), diagnostics };
|
|
55
84
|
}
|
|
56
85
|
export function shouldFailForIncompleteScan(completeness, policy) {
|
|
57
86
|
// only "error" triggers a non-zero exit; "warn" (the default) still surfaces the diagnostic but lets the scan succeed
|
|
58
87
|
if (policy !== "error") {
|
|
59
88
|
return false;
|
|
60
89
|
}
|
|
61
|
-
|
|
90
|
+
// A cached copy that stood in for a failed lookup leaves the finding intact,
|
|
91
|
+
// but its severity may since have been raised, so a strict gate fails (#1443).
|
|
92
|
+
return getCompletenessImpact(completeness).hasDetectionGap || findStaleCacheDiagnostic(completeness) !== undefined;
|
|
93
|
+
}
|
|
94
|
+
function findStaleCacheDiagnostic(completeness) {
|
|
95
|
+
return completeness?.diagnostics.find(diagnostic => diagnostic.impact === "freshness");
|
|
96
|
+
}
|
|
97
|
+
// Why the error policy failed a scan whose only shortfall is cached advisory
|
|
98
|
+
// details. Null when no cached details were used.
|
|
99
|
+
export function staleCacheGateReason(completeness, now = Date.now()) {
|
|
100
|
+
const diagnostic = findStaleCacheDiagnostic(completeness);
|
|
101
|
+
if (!diagnostic)
|
|
102
|
+
return null;
|
|
103
|
+
const { count, oldestCachedAt } = diagnostic;
|
|
104
|
+
const since = oldestCachedAt
|
|
105
|
+
? `, ${count === 1 ? "" : "the oldest "}cached on ${oldestCachedAt.slice(0, 10)}${formatCacheAge(oldestCachedAt, now)}`
|
|
106
|
+
: "";
|
|
107
|
+
return `Failed by --incomplete-policy error: details for ${count} ${pluralize(count, "advisory", "advisories")} were taken from a cached copy${since}, so ${pluralize(count, "its", "their")} severity may be out of date.`;
|
|
108
|
+
}
|
|
109
|
+
// A machine-readable payload may be on stdout, so the reason goes to stderr there.
|
|
110
|
+
export function printStaleCacheGateReason(completeness, machineOutput) {
|
|
111
|
+
const reason = staleCacheGateReason(completeness);
|
|
112
|
+
if (!reason)
|
|
113
|
+
return;
|
|
114
|
+
(machineOutput ? console.error : console.log)(chalk.red(reason));
|
|
62
115
|
}
|
|
@@ -5,13 +5,14 @@ import { randomUUID } from "node:crypto";
|
|
|
5
5
|
import { EXIT_OK, EXIT_FINDINGS, EXIT_ERROR } from "../types.js";
|
|
6
6
|
import { loadMultiplePackages } from "../parsers/multi-package.js";
|
|
7
7
|
import { scanPackages, buildCoverageNotes } from "../scanner.js";
|
|
8
|
-
import { sortFindingsForOutput, logInfo } from "../output/formatters.js";
|
|
8
|
+
import { sortFindingsForOutput, logInfo, logEmptyScan } from "../output/formatters.js";
|
|
9
9
|
import { buildMultiFolderScanJson } from "../output/scan-json.js";
|
|
10
10
|
import { resolveOutputTarget, displayOutputPath, checkFormatExtensionMismatch, isOutputStdout, drainStdout } from "../output/output-dir.js";
|
|
11
11
|
import { normalizeSeverity } from "../osv/severity.js";
|
|
12
12
|
import { selectFindingsForTable } from "../output/finding-display.js";
|
|
13
13
|
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
14
14
|
import { readDirectDependencyNames, hasOverrideEntries } from "../utils/package-json.js";
|
|
15
|
+
import { isGatableFinding } from "../utils/finding.js";
|
|
15
16
|
import { DEFAULT_SEARCH_DEPTH, OVERRIDES_COMMAND, RATCHET_BASELINE_COMMIT_HINT } from "../constants.js";
|
|
16
17
|
import { printMultiFolderResults } from "../output/multi-folder-printer.js";
|
|
17
18
|
import { printOverrideHint } from "../output/printers.js";
|
|
@@ -23,10 +24,10 @@ import { NULL_AUDIT_LOG } from "../audit-log/index.js";
|
|
|
23
24
|
import { detectDM001 } from "../maintenance/dm001-maintenance-risk.js";
|
|
24
25
|
import { detectLicenseIssues } from "../licenses/license-check.js";
|
|
25
26
|
import { renderLicenseFindings } from "../output/license-terminal.js";
|
|
26
|
-
import { GATE_CLASS_LABELS, failingGateSummary } from "../utils/severity.js";
|
|
27
|
+
import { GATE_CLASS_LABELS, failingGateSummary, unresolvedGateNotice, vulnerabilityGateClasses } from "../utils/severity.js";
|
|
27
28
|
import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "../utils/baseline.js";
|
|
28
29
|
import { pluralize } from "../utils/string.js";
|
|
29
|
-
import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, shouldFailForIncompleteScan, } from "./completeness.js";
|
|
30
|
+
import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, printStaleCacheGateReason, shouldFailForIncompleteScan, } from "./completeness.js";
|
|
30
31
|
import { scanProjectForPackageUsage, usageScanTruncationWarning } from "../usage/scanner.js";
|
|
31
32
|
import { isNpmLockSource } from "../utils/package-manager-source.js";
|
|
32
33
|
export async function runMultiFolderScan(params) {
|
|
@@ -83,6 +84,7 @@ export async function runMultiFolderScan(params) {
|
|
|
83
84
|
}
|
|
84
85
|
let sorted = sortFindingsForOutput(finalFindings);
|
|
85
86
|
let suppressedCount = 0;
|
|
87
|
+
const sortedBeforeBaseline = sorted;
|
|
86
88
|
// Non-ratchet: auto-apply an existing per-folder baseline before fix plan,
|
|
87
89
|
// table selection, and maintenance (mirrors single-folder index.ts).
|
|
88
90
|
// --ratchet keeps the full set so handleMultiFolderScan can save or gate.
|
|
@@ -137,6 +139,7 @@ export async function runMultiFolderScan(params) {
|
|
|
137
139
|
directDeps,
|
|
138
140
|
isNpm,
|
|
139
141
|
isOffline: offline,
|
|
142
|
+
prodOnly: params.options.prodOnly,
|
|
140
143
|
});
|
|
141
144
|
licenseFindings = licenseResult.findings;
|
|
142
145
|
licenseLimitedToDirectOnly = licenseResult.limitedToDirectOnly;
|
|
@@ -145,6 +148,7 @@ export async function runMultiFolderScan(params) {
|
|
|
145
148
|
subfolder,
|
|
146
149
|
scanInput,
|
|
147
150
|
sorted,
|
|
151
|
+
sortedBeforeBaseline,
|
|
148
152
|
suggestedFixCommands,
|
|
149
153
|
coverage,
|
|
150
154
|
minSeverity,
|
|
@@ -202,7 +206,7 @@ function handleMultiFolderRatchet(results, projectRoot, options) {
|
|
|
202
206
|
if (!isStdout) {
|
|
203
207
|
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
208
|
}
|
|
205
|
-
const gateLine = failingGateSummary(
|
|
209
|
+
const gateLine = failingGateSummary(vulnerabilityGateClasses(r.sorted.filter(isGatableFinding)), options.failOn);
|
|
206
210
|
if (gateLine) {
|
|
207
211
|
anyFirstRunGateFailure = true;
|
|
208
212
|
if (!options.json && !isStdout) {
|
|
@@ -225,7 +229,10 @@ function handleMultiFolderRatchet(results, projectRoot, options) {
|
|
|
225
229
|
}
|
|
226
230
|
continue;
|
|
227
231
|
}
|
|
228
|
-
|
|
232
|
+
const gatableNewFindings = newFindings.filter(isGatableFinding);
|
|
233
|
+
if (gatableNewFindings.length > 0) {
|
|
234
|
+
anyNewFindings = true;
|
|
235
|
+
}
|
|
229
236
|
if (!isStdout) {
|
|
230
237
|
console.log(chalk.red(`${r.subfolder}/: ${newFindings.length} new ${pluralize(newFindings.length, "finding")} above baseline - ${suppressedLabel}`));
|
|
231
238
|
for (const f of newFindings) {
|
|
@@ -334,18 +341,17 @@ export async function handleMultiFolderScan(params) {
|
|
|
334
341
|
if (params.options.json) {
|
|
335
342
|
await writeMultiFolderJson(results, params.projectRoot, params.options, params.onScanJsonPath);
|
|
336
343
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
344
|
+
const exitCode = params.options.allowEmpty ? EXIT_OK : EXIT_ERROR;
|
|
345
|
+
logEmptyScan("No scannable packages found in any subfolder.", exitCode, params.options);
|
|
340
346
|
auditLog.emit({
|
|
341
347
|
ts: new Date(scanFinishedAt).toISOString(),
|
|
342
348
|
type: "scan.finished",
|
|
343
349
|
schemaVersion: 1,
|
|
344
350
|
durationMs: scanFinishedAt - scanStartedAt,
|
|
345
351
|
findingsCount: 0,
|
|
346
|
-
exitCode
|
|
352
|
+
exitCode,
|
|
347
353
|
});
|
|
348
|
-
return
|
|
354
|
+
return exitCode;
|
|
349
355
|
}
|
|
350
356
|
if (params.options.fix) {
|
|
351
357
|
console.error(chalk.yellow("--fix is not yet supported in multi-folder mode. Run cve-lite . from each subfolder individually."));
|
|
@@ -433,23 +439,27 @@ export async function handleMultiFolderScan(params) {
|
|
|
433
439
|
console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
|
|
434
440
|
}
|
|
435
441
|
const allSorted = results.flatMap(r => r.sorted);
|
|
442
|
+
const allSortedBeforeBaseline = results.flatMap(r => r.sortedBeforeBaseline ?? r.sorted);
|
|
436
443
|
const allOverrideFindings = results.flatMap(r => r.overrideFindings);
|
|
437
444
|
const allMaintenanceFindings = results.flatMap(r => r.maintenanceFindings);
|
|
438
445
|
// Mirror single-folder exit policy in src/scan/single-scan.ts: CVE + override +
|
|
439
446
|
// maintenance all count toward --fail-on. Without overrides here, multi-folder CI
|
|
440
447
|
// using --check-overrides --fail-on high would exit 0 despite high OA findings.
|
|
448
|
+
const incompleteFailure = shouldFailForIncompleteScan(aggregatedCompleteness, params.options.incompletePolicy);
|
|
449
|
+
if (incompleteFailure) {
|
|
450
|
+
printStaleCacheGateReason(aggregatedCompleteness, !!params.options.json || isOutputStdout(params.options.output));
|
|
451
|
+
}
|
|
441
452
|
let exitCode;
|
|
442
453
|
if (params.options.ratchet) {
|
|
443
|
-
exitCode = ratchetExitCode;
|
|
454
|
+
exitCode = incompleteFailure ? EXIT_ERROR : ratchetExitCode;
|
|
444
455
|
}
|
|
445
456
|
else {
|
|
446
457
|
const gateLine = failingGateSummary([
|
|
447
|
-
|
|
458
|
+
...vulnerabilityGateClasses(allSorted.filter(isGatableFinding)),
|
|
448
459
|
{ label: GATE_CLASS_LABELS.overrideHygiene, findings: allOverrideFindings },
|
|
449
460
|
{ label: GATE_CLASS_LABELS.maintenanceRisk, findings: allMaintenanceFindings },
|
|
450
461
|
], params.options.failOn);
|
|
451
462
|
const shouldFail = gateLine !== null;
|
|
452
|
-
const incompleteFailure = shouldFailForIncompleteScan(aggregatedCompleteness, params.options.incompletePolicy);
|
|
453
463
|
exitCode = incompleteFailure
|
|
454
464
|
? EXIT_ERROR
|
|
455
465
|
: shouldFail
|
|
@@ -458,6 +468,10 @@ export async function handleMultiFolderScan(params) {
|
|
|
458
468
|
if (gateLine && !params.options.json && !isOutputStdout(params.options.output)) {
|
|
459
469
|
console.log(chalk.red(gateLine));
|
|
460
470
|
}
|
|
471
|
+
const unresolvedNotice = unresolvedGateNotice(allSortedBeforeBaseline, params.options.failOn, params.options.incompletePolicy);
|
|
472
|
+
if (unresolvedNotice && !params.options.json && !isOutputStdout(params.options.output)) {
|
|
473
|
+
console.log(chalk.yellow(unresolvedNotice));
|
|
474
|
+
}
|
|
461
475
|
}
|
|
462
476
|
auditLog.emit({
|
|
463
477
|
ts: new Date(scanFinishedAt).toISOString(),
|