cve-lite-cli 1.29.0 → 1.31.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 +2 -1
- package/dist/advisory/osv-advisory-source.js +3 -0
- package/dist/cli/help.js +3 -2
- package/dist/cli/validate.js +12 -12
- package/dist/constants.js +1 -0
- package/dist/index.js +29 -2
- package/dist/output/formatters.js +19 -7
- package/dist/output/html-reporter.js +22 -14
- package/dist/output/multi-folder-html-reporter.js +3 -2
- package/dist/output/override-findings-html.js +6 -5
- package/dist/output/override-findings-terminal.js +2 -1
- package/dist/output/printers.js +16 -14
- package/dist/overrides/detectors/oa001-orphaned-target.js +2 -1
- package/dist/overrides/detectors/oa002-floating-tag.js +2 -1
- package/dist/overrides/detectors/oa003-wrong-section.js +2 -1
- package/dist/overrides/detectors/oa004-surpassed-pin.js +2 -1
- package/dist/overrides/detectors/oa005-nested-ineffective.js +2 -1
- package/dist/overrides/detectors/oa006-coupled-platform-binary.js +2 -1
- package/dist/overrides/detectors/oa007-frozen-latest.js +2 -1
- package/dist/overrides/detectors/oa009-stale-floor.js +2 -1
- package/dist/parsers/pnpm-lock.js +22 -7
- package/dist/remediation/fix-commands.js +43 -12
- package/dist/remediation/npm-transitive-resolution.js +5 -6
- package/dist/remediation/package-path-lookup.js +29 -0
- package/dist/remediation/parent-upgrade.js +2 -22
- package/dist/scan/multi-folder-scan.js +18 -3
- package/dist/scanner.js +26 -2
- package/dist/utils/finding.js +28 -0
- package/dist/utils/fix-runner.js +87 -50
- package/dist/utils/severity.js +2 -0
- package/dist/utils/version.js +13 -4
- package/package.json +2 -2
package/dist/utils/fix-runner.js
CHANGED
|
@@ -4,18 +4,8 @@ import path from "node:path";
|
|
|
4
4
|
import { createSpinner } from "../output/spinner.js";
|
|
5
5
|
import { chalk } from "./chalk.js";
|
|
6
6
|
import { pluralize } from "./string.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return ["npm", "install", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
10
|
-
}
|
|
11
|
-
if (packageManager === "pnpm") {
|
|
12
|
-
return ["pnpm", "add", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
13
|
-
}
|
|
14
|
-
if (packageManager === "bun") {
|
|
15
|
-
return ["bun", "add", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
16
|
-
}
|
|
17
|
-
return ["yarn", "add", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
18
|
-
}
|
|
7
|
+
import { isBreakingUpgrade } from "./version.js";
|
|
8
|
+
import { buildTargetCommand } from "../remediation/fix-commands.js";
|
|
19
9
|
export async function runInstallCommand(command, args, cwd, debugLog) {
|
|
20
10
|
const commandLine = [command, ...args].join(" ");
|
|
21
11
|
debugLog?.("Fix command", { command: commandLine, cwd });
|
|
@@ -45,63 +35,101 @@ export function commandLabelForPackageManager(packageManager) {
|
|
|
45
35
|
return "bun add";
|
|
46
36
|
return "yarn add";
|
|
47
37
|
}
|
|
38
|
+
// Categorize the fixes that --fix does NOT auto-apply. Direct upgrades and
|
|
39
|
+
// within-range refreshes (parent-update) are auto-applied, so only parent
|
|
40
|
+
// upgrades (breaking ones especially) and no-fix findings remain here.
|
|
41
|
+
export function categorizeUnappliedTargets(plan) {
|
|
42
|
+
let parentUpgradeCount = 0;
|
|
43
|
+
let breakingUpgradeCount = 0;
|
|
44
|
+
for (const target of plan.targets) {
|
|
45
|
+
if (target.kind === "parent-upgrade") {
|
|
46
|
+
parentUpgradeCount += 1;
|
|
47
|
+
if (target.currentVersion && isBreakingUpgrade(target.currentVersion, target.targetVersion)) {
|
|
48
|
+
breakingUpgradeCount += 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
parentUpgradeCount,
|
|
54
|
+
breakingUpgradeCount,
|
|
55
|
+
noFixCount: plan.skipped.length,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const EMPTY_UNAPPLIED = {
|
|
59
|
+
parentUpgradeCount: 0,
|
|
60
|
+
breakingUpgradeCount: 0,
|
|
61
|
+
noFixCount: 0,
|
|
62
|
+
};
|
|
63
|
+
// Build the command(s) to apply a target. Within-range refresh (parent-update)
|
|
64
|
+
// targets carry an explicit, already-workspace-scoped command; direct targets
|
|
65
|
+
// are installed by version. A multi-member workspace command is `&&`-joined and
|
|
66
|
+
// is split into one spawn per member.
|
|
67
|
+
function buildApplyCommands(packageManager, target) {
|
|
68
|
+
// Use the same workspace-scoped command the report/plan shows, so --fix applies
|
|
69
|
+
// fixes to the declaring member (npm install -w, pnpm --filter ...) rather than
|
|
70
|
+
// flat at the root. A multi-member command is `&&`-joined; split per spawn.
|
|
71
|
+
return buildTargetCommand(target, packageManager)
|
|
72
|
+
.split("&&")
|
|
73
|
+
.map(part => part.trim())
|
|
74
|
+
.filter(Boolean)
|
|
75
|
+
.map(part => part.split(/\s+/));
|
|
76
|
+
}
|
|
48
77
|
export function writeFixResultJson(json, projectPath) {
|
|
49
78
|
const outPath = path.join(projectPath, "cve-lite-fix-result.json");
|
|
50
79
|
fs.writeFileSync(outPath, JSON.stringify(json, null, 2), "utf8");
|
|
51
80
|
}
|
|
52
81
|
export async function applyFixesIfRequested(params) {
|
|
82
|
+
const runCommand = params.runCommand ?? runInstallCommand;
|
|
53
83
|
console.log("");
|
|
54
84
|
console.log(chalk.bold.cyan("Applying fixes (--fix)"));
|
|
55
85
|
if (!params.plan) {
|
|
56
86
|
return {
|
|
57
87
|
appliedFixCount: 0,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
skippedNoValidatedTargetCount: params.totalFindings,
|
|
88
|
+
appliedWithinRangeRefreshCount: 0,
|
|
89
|
+
...EMPTY_UNAPPLIED,
|
|
61
90
|
applied: [],
|
|
62
91
|
note: "No package-manager-native fix command is available for this project.",
|
|
63
92
|
};
|
|
64
93
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
94
|
+
// Auto-apply the safe fixes: direct upgrades and within-range transitive
|
|
95
|
+
// refreshes (parent-update). Parent upgrades (breaking or otherwise) still
|
|
96
|
+
// need review and are left for the user.
|
|
97
|
+
const applyTargets = params.plan.targets.filter(target => target.kind === "direct" || target.kind === "parent-update");
|
|
98
|
+
const unapplied = categorizeUnappliedTargets(params.plan);
|
|
99
|
+
if (applyTargets.length === 0) {
|
|
70
100
|
return {
|
|
71
101
|
appliedFixCount: 0,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
skippedNoValidatedTargetCount: skippedDirect.length,
|
|
102
|
+
appliedWithinRangeRefreshCount: 0,
|
|
103
|
+
...unapplied,
|
|
75
104
|
applied: [],
|
|
76
|
-
note: "No
|
|
105
|
+
note: "No fixes were auto-applied. `--fix` auto-applies safe direct upgrades and within-range refreshes; the remaining fixes are parent upgrades that need review. See the Suggested Fix Plan above.",
|
|
77
106
|
};
|
|
78
107
|
}
|
|
79
108
|
const commandLabel = commandLabelForPackageManager(params.plan.packageManager);
|
|
80
|
-
const total =
|
|
81
|
-
const spinner = createSpinner(`Applying
|
|
109
|
+
const total = applyTargets.length;
|
|
110
|
+
const spinner = createSpinner(`Applying safe package fixes with ${commandLabel}... 0/${total}`, params.options);
|
|
82
111
|
const fixHint = `\nHint: Check that \`${params.plan.packageManager}\` is available and you have write access to node_modules.\nIf running in CI, ensure the install step has already run before cve-lite --fix.`;
|
|
83
|
-
for (let i = 0; i <
|
|
84
|
-
const target =
|
|
85
|
-
const commandParts
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
112
|
+
for (let i = 0; i < applyTargets.length; i++) {
|
|
113
|
+
const target = applyTargets[i];
|
|
114
|
+
for (const commandParts of buildApplyCommands(params.plan.packageManager, target)) {
|
|
115
|
+
spinner.update(`Applying fix ${i + 1}/${total}: ${commandParts.join(" ")}`);
|
|
116
|
+
const run = await runCommand(commandParts[0], commandParts.slice(1), params.projectPath, params.debugLog);
|
|
117
|
+
if (run.error) {
|
|
118
|
+
spinner.fail("Failed to apply fixes");
|
|
119
|
+
throw new Error(`Failed to apply fixes: ${run.error.message}${fixHint}`);
|
|
120
|
+
}
|
|
121
|
+
if ((run.status ?? 1) !== 0) {
|
|
122
|
+
spinner.fail(`Fix command failed (${commandLabel})`);
|
|
123
|
+
throw new Error(`Fix command exited with status ${run.status ?? 1}${fixHint}`);
|
|
124
|
+
}
|
|
95
125
|
}
|
|
96
126
|
}
|
|
97
|
-
spinner.succeed(`Applied ${
|
|
98
|
-
const skippedCount = transitiveTargets.length + skippedDirect.length;
|
|
127
|
+
spinner.succeed(`Applied ${applyTargets.length} package ${pluralize(applyTargets.length, "fix", "fixes")} with ${commandLabel}`);
|
|
99
128
|
return {
|
|
100
|
-
appliedFixCount:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
applied: directTargets.map(target => ({
|
|
129
|
+
appliedFixCount: applyTargets.length,
|
|
130
|
+
appliedWithinRangeRefreshCount: applyTargets.filter(target => target.kind === "parent-update").length,
|
|
131
|
+
...unapplied,
|
|
132
|
+
applied: applyTargets.map(target => ({
|
|
105
133
|
package: target.package,
|
|
106
134
|
from: target.currentVersion ?? "unknown",
|
|
107
135
|
to: target.targetVersion,
|
|
@@ -125,11 +153,20 @@ export function printFixModeSummary(params) {
|
|
|
125
153
|
}
|
|
126
154
|
console.log("");
|
|
127
155
|
console.log(chalk.bold.cyan("Fix summary"));
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
156
|
+
const refreshNote = result.appliedWithinRangeRefreshCount > 0
|
|
157
|
+
? ` (incl. ${result.appliedWithinRangeRefreshCount} within-range ${pluralize(result.appliedWithinRangeRefreshCount, "refresh", "refreshes")})`
|
|
158
|
+
: "";
|
|
159
|
+
console.log(`- Applied fixes: ${chalk.green(String(result.appliedFixCount))}${chalk.gray(refreshNote)}`);
|
|
160
|
+
const notAutoApplied = result.parentUpgradeCount + result.noFixCount;
|
|
161
|
+
console.log(`- Not auto-applied: ${chalk.yellow(String(notAutoApplied))}`);
|
|
162
|
+
if (result.parentUpgradeCount > 0) {
|
|
163
|
+
const breakingNote = result.breakingUpgradeCount > 0
|
|
164
|
+
? `, ${result.breakingUpgradeCount} breaking`
|
|
165
|
+
: "";
|
|
166
|
+
console.log(` - Parent upgrades (review + test): ${chalk.yellow(String(result.parentUpgradeCount))}${chalk.gray(breakingNote)}`);
|
|
167
|
+
}
|
|
168
|
+
if (result.noFixCount > 0) {
|
|
169
|
+
console.log(` - No fix available: ${chalk.yellow(String(result.noFixCount))}`);
|
|
133
170
|
}
|
|
134
171
|
console.log(`- Findings before fix: ${chalk.white(String(params.findingsBeforeFix))}`);
|
|
135
172
|
console.log(`- Remaining findings after fix: ${chalk.white(String(params.findingsAfterFix))}`);
|
package/dist/utils/severity.js
CHANGED
|
@@ -3,6 +3,8 @@ import { severityOrder } from "../constants.js";
|
|
|
3
3
|
import { normalizeSeverity } from "../osv/severity.js";
|
|
4
4
|
export const SEVERITY_ORDER = ["critical", "high", "medium", "low", "unknown", "none"];
|
|
5
5
|
export function reachesFailOn(findings, failOn) {
|
|
6
|
+
if (!failOn)
|
|
7
|
+
return false;
|
|
6
8
|
const failLevel = normalizeSeverity(failOn);
|
|
7
9
|
return findings.some((f) => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
8
10
|
}
|
package/dist/utils/version.js
CHANGED
|
@@ -45,10 +45,19 @@ export function parseExactManifestVersion(spec) {
|
|
|
45
45
|
return cleaned;
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
|
-
export function
|
|
49
|
-
const fromMajor =
|
|
50
|
-
const toMajor =
|
|
51
|
-
|
|
48
|
+
export function isBreakingUpgrade(from, to) {
|
|
49
|
+
const [fromMajor, fromMinor] = from.split(".").map(Number);
|
|
50
|
+
const [toMajor, toMinor] = to.split(".").map(Number);
|
|
51
|
+
if (Number.isNaN(fromMajor) || Number.isNaN(toMajor))
|
|
52
|
+
return false;
|
|
53
|
+
if (toMajor > fromMajor)
|
|
54
|
+
return true;
|
|
55
|
+
// Under semver, 0.x releases treat the minor as the breaking position
|
|
56
|
+
// (^0.21.1 resolves to >=0.21.1 <0.22.0), so a 0.x cross-minor bump is breaking.
|
|
57
|
+
if (fromMajor === 0 && toMajor === 0) {
|
|
58
|
+
return !Number.isNaN(fromMinor) && !Number.isNaN(toMinor) && toMinor > fromMinor;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
52
61
|
}
|
|
53
62
|
export function isPreReleaseVersion(version) {
|
|
54
63
|
return /^\d+\.\d+\.\d+-[^\s]+$/.test(version);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cve-lite-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.0",
|
|
4
4
|
"description": "Developer-friendly CLI for scanning JS/TS projects for dependency vulnerabilities using local lockfiles and OSV",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
],
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
50
|
+
"node": ">=20"
|
|
51
51
|
},
|
|
52
52
|
"repository": {
|
|
53
53
|
"type": "git",
|