cve-lite-cli 1.41.3 → 1.41.4
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/dist/output/printers.js
CHANGED
|
@@ -965,7 +965,7 @@ function colorFixSectionTitle(severity, title) {
|
|
|
965
965
|
return chalk.green(title);
|
|
966
966
|
return chalk.gray(title);
|
|
967
967
|
}
|
|
968
|
-
function formatFixCommandSummary(plan) {
|
|
968
|
+
export function formatFixCommandSummary(plan) {
|
|
969
969
|
if (!plan)
|
|
970
970
|
return "";
|
|
971
971
|
const packageCount = plan.targets.length;
|
|
@@ -12,7 +12,7 @@ import { buildYarnWorkspaceMap } from "../parsers/yarn-lock.js";
|
|
|
12
12
|
import { buildBunWorkspaceMap } from "../parsers/bun-lock.js";
|
|
13
13
|
import { readConfiguredCooldown, cooldownWarningFor } from "./cooldown.js";
|
|
14
14
|
import { isVerifiedUpgrade } from "./parent-upgrade.js";
|
|
15
|
-
import { installPackageSpec, packageInstanceKey, packageNameKey, registryPackageName } from "../utils/package-identity.js";
|
|
15
|
+
import { commandPackageName, installPackageSpec, isOptionShapedName, packageInstanceKey, packageNameKey, registryPackageName } from "../utils/package-identity.js";
|
|
16
16
|
// Rendered next to a parent-upgrade fix target whose recommendedParentUpgrade
|
|
17
17
|
// could not be verified end-to-end (parent-upgrade.ts confidence: "unverified").
|
|
18
18
|
// Shared across terminal and HTML output so the wording stays in sync.
|
|
@@ -117,7 +117,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
117
117
|
isUpgradeTarget(finding.pkg.version, directTarget) &&
|
|
118
118
|
validatedFieldOk) {
|
|
119
119
|
const pkgWorkspaces = workspaceMap.get(packageNameKey(finding.pkg))?.filter(w => w !== ".") ?? [];
|
|
120
|
-
upsertTarget(targetsByKey, finding, {
|
|
120
|
+
upsertTarget(targetsByKey, skippedByKey, finding, {
|
|
121
121
|
package: finding.pkg.name,
|
|
122
122
|
...(finding.pkg.registryName ? { registryName: finding.pkg.registryName } : {}),
|
|
123
123
|
currentVersion: finding.pkg.version,
|
|
@@ -184,7 +184,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
184
184
|
if (packageManager === "npm" &&
|
|
185
185
|
finding.relationship === "transitive" &&
|
|
186
186
|
finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
187
|
-
upsertTarget(targetsByKey, finding, parentUpdateTarget(finding, urgent, {
|
|
187
|
+
upsertTarget(targetsByKey, skippedByKey, finding, parentUpdateTarget(finding, urgent, {
|
|
188
188
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
189
189
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
190
190
|
childTargetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
@@ -221,7 +221,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
221
221
|
? finding.chainResolution
|
|
222
222
|
: null;
|
|
223
223
|
const npmParentUpgradeWorkspaces = workspaceMap.get(finding.recommendedNpmTransitiveRemediation.package)?.filter(w => w !== ".") ?? [];
|
|
224
|
-
upsertTarget(targetsByKey, finding, {
|
|
224
|
+
upsertTarget(targetsByKey, skippedByKey, finding, {
|
|
225
225
|
package: finding.recommendedNpmTransitiveRemediation.package,
|
|
226
226
|
currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
|
|
227
227
|
targetVersion: finding.recommendedNpmTransitiveRemediation.targetVersion,
|
|
@@ -253,7 +253,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
253
253
|
? finding.chainResolution
|
|
254
254
|
: null;
|
|
255
255
|
const parentUpgradeWorkspaces = workspaceMap.get(finding.recommendedParentUpgrade.package)?.filter(w => w !== ".") ?? [];
|
|
256
|
-
upsertTarget(targetsByKey, finding, {
|
|
256
|
+
upsertTarget(targetsByKey, skippedByKey, finding, {
|
|
257
257
|
package: finding.recommendedParentUpgrade.package,
|
|
258
258
|
currentVersion: finding.recommendedParentUpgrade.currentVersion,
|
|
259
259
|
targetVersion: finding.recommendedParentUpgrade.targetVersion,
|
|
@@ -295,7 +295,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
295
295
|
: packageManager === "yarn"
|
|
296
296
|
? buildYarnUpgradeCommand(finding.pkg.name, finding.recommendedNpmTransitiveRemediation.workspaces)
|
|
297
297
|
: buildBunUpdateCommand(finding.pkg.name);
|
|
298
|
-
upsertTarget(targetsByKey, finding, parentUpdateTarget(finding, urgent, {
|
|
298
|
+
upsertTarget(targetsByKey, skippedByKey, finding, parentUpdateTarget(finding, urgent, {
|
|
299
299
|
package: finding.pkg.name,
|
|
300
300
|
currentVersion: finding.pkg.version,
|
|
301
301
|
childTargetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
|
|
@@ -311,7 +311,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
311
311
|
const isDev = devLookup.get(`${finding.chainResolution.directDep}@${finding.chainResolution.directDepCurrentVersion}`) ?? false;
|
|
312
312
|
const coverage = calculatePathCoverage(finding.dependencyPaths, [finding.chainResolution.directDep]);
|
|
313
313
|
const chainWorkspaces = workspaceMap.get(finding.chainResolution.directDep)?.filter(w => w !== ".") ?? [];
|
|
314
|
-
upsertTarget(targetsByKey, finding, {
|
|
314
|
+
upsertTarget(targetsByKey, skippedByKey, finding, {
|
|
315
315
|
package: finding.chainResolution.directDep,
|
|
316
316
|
currentVersion: finding.chainResolution.directDepCurrentVersion,
|
|
317
317
|
targetVersion: finding.chainResolution.targetVersion,
|
|
@@ -718,7 +718,18 @@ function withholdShellUnsafeTargets(sortedTargets, findings, skippedByKey, subfo
|
|
|
718
718
|
}
|
|
719
719
|
return kept;
|
|
720
720
|
}
|
|
721
|
-
function upsertTarget(targetsByKey, finding, next) {
|
|
721
|
+
function upsertTarget(targetsByKey, skippedByKey, finding, next) {
|
|
722
|
+
const operand = commandPackageName(next);
|
|
723
|
+
if (isOptionShapedName(operand)) {
|
|
724
|
+
skippedByKey.set(`option-shaped:${packageInstanceKey(finding.pkg)}`, {
|
|
725
|
+
package: finding.pkg.name,
|
|
726
|
+
version: finding.pkg.version,
|
|
727
|
+
relationship: finding.relationship,
|
|
728
|
+
reason: `Package name "${operand}" looks like a command-line option, so no fix command is offered.`,
|
|
729
|
+
optionShapedName: true,
|
|
730
|
+
});
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
722
733
|
const key = targetKey(finding, next);
|
|
723
734
|
const existing = targetsByKey.get(key);
|
|
724
735
|
if (!existing) {
|
package/dist/scan/single-scan.js
CHANGED
|
@@ -314,6 +314,7 @@ export async function handleSingleFolderScan(params) {
|
|
|
314
314
|
parentUpgradeCount: fixResult?.parentUpgradeCount ?? 0,
|
|
315
315
|
breakingUpgradeCount: fixResult?.breakingUpgradeCount ?? 0,
|
|
316
316
|
noFixCount: fixResult?.noFixCount ?? 0,
|
|
317
|
+
optionShapedNameCount: fixResult?.optionShapedNameCount ?? 0,
|
|
317
318
|
},
|
|
318
319
|
};
|
|
319
320
|
writeFixResultJson(fixResultJson, projectPath);
|
package/dist/utils/fix-runner.js
CHANGED
|
@@ -5,7 +5,7 @@ import { createSpinner } from "../output/spinner.js";
|
|
|
5
5
|
import { chalk } from "./chalk.js";
|
|
6
6
|
import { pluralize } from "./string.js";
|
|
7
7
|
import { isBreakingUpgrade } from "./version.js";
|
|
8
|
-
import { installPackageSpec } from "./package-identity.js";
|
|
8
|
+
import { installPackageSpec, isOptionShapedName } from "./package-identity.js";
|
|
9
9
|
import { formatParentUpdateChildNote } from "../remediation/parent-update-child-note.js";
|
|
10
10
|
export async function runInstallCommand(command, args, cwd, debugLog) {
|
|
11
11
|
const commandLine = [command, ...args].join(" ");
|
|
@@ -53,19 +53,21 @@ export function categorizeUnappliedTargets(plan) {
|
|
|
53
53
|
return {
|
|
54
54
|
parentUpgradeCount,
|
|
55
55
|
breakingUpgradeCount,
|
|
56
|
-
noFixCount: plan.skipped.length,
|
|
56
|
+
noFixCount: plan.skipped.filter(skip => !skip.optionShapedName).length,
|
|
57
|
+
optionShapedNameCount: plan.skipped.filter(skip => skip.optionShapedName).length,
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
const EMPTY_UNAPPLIED = {
|
|
60
61
|
parentUpgradeCount: 0,
|
|
61
62
|
breakingUpgradeCount: 0,
|
|
62
63
|
noFixCount: 0,
|
|
64
|
+
optionShapedNameCount: 0,
|
|
63
65
|
};
|
|
64
66
|
// Build argv lists for --fix without round-tripping through a shell string.
|
|
65
67
|
// Workspace paths and package tokens are passed as whole argv elements to spawn
|
|
66
68
|
// (no shell), so a directory name containing `&&` cannot become a second executable.
|
|
67
69
|
// Human-facing plan strings still come from buildTargetCommand.
|
|
68
|
-
function buildApplyCommands(packageManager, target) {
|
|
70
|
+
export function buildApplyCommands(packageManager, target) {
|
|
69
71
|
if (target.kind === "parent-update") {
|
|
70
72
|
return buildParentUpdateApplyArgv(packageManager, target);
|
|
71
73
|
}
|
|
@@ -74,6 +76,8 @@ function buildApplyCommands(packageManager, target) {
|
|
|
74
76
|
function buildInstallApplyArgv(packageManager, target) {
|
|
75
77
|
const workspaces = (target.workspaces ?? []).filter(w => w !== ".");
|
|
76
78
|
const pkgArg = installPackageSpec(target);
|
|
79
|
+
if (isOptionShapedName(pkgArg))
|
|
80
|
+
return [];
|
|
77
81
|
const isDev = Boolean(target.isDev);
|
|
78
82
|
if (packageManager === "npm") {
|
|
79
83
|
const args = ["install"];
|
|
@@ -126,6 +130,8 @@ function buildParentUpdateApplyArgv(packageManager, target) {
|
|
|
126
130
|
// Always build from structured fields. Never tokenize target.command: plan
|
|
127
131
|
// strings may be shell-quoted for display, and must not be re-parsed into argv.
|
|
128
132
|
const updatePkg = target.childPackage ?? target.package;
|
|
133
|
+
if (isOptionShapedName(updatePkg))
|
|
134
|
+
return [];
|
|
129
135
|
const workspaces = target.workspaces ?? [];
|
|
130
136
|
const nonRoot = workspaces.filter(w => w !== ".");
|
|
131
137
|
if (packageManager === "npm") {
|
|
@@ -178,8 +184,10 @@ export async function applyFixesIfRequested(params) {
|
|
|
178
184
|
// refreshes (parent-update). Parent upgrades (breaking or otherwise) still
|
|
179
185
|
// need review and are left for the user.
|
|
180
186
|
const applyTargets = params.plan.targets.filter(target => target.kind === "direct" || target.kind === "parent-update");
|
|
187
|
+
const packageManager = params.plan.packageManager;
|
|
188
|
+
const runnableTargets = applyTargets.filter(target => buildApplyCommands(packageManager, target).length > 0);
|
|
181
189
|
const unapplied = categorizeUnappliedTargets(params.plan);
|
|
182
|
-
if (
|
|
190
|
+
if (runnableTargets.length === 0) {
|
|
183
191
|
return {
|
|
184
192
|
appliedFixCount: 0,
|
|
185
193
|
appliedWithinRangeRefreshCount: 0,
|
|
@@ -189,7 +197,7 @@ export async function applyFixesIfRequested(params) {
|
|
|
189
197
|
};
|
|
190
198
|
}
|
|
191
199
|
const commandLabel = commandLabelForPackageManager(params.plan.packageManager);
|
|
192
|
-
const total =
|
|
200
|
+
const total = runnableTargets.length;
|
|
193
201
|
const spinner = createSpinner(`Applying safe package fixes with ${commandLabel}... 0/${total}`, params.options);
|
|
194
202
|
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.`;
|
|
195
203
|
// parent-update is keyed per child, so two children behind one parent produce
|
|
@@ -197,8 +205,8 @@ export async function applyFixesIfRequested(params) {
|
|
|
197
205
|
// parents that refresh the same child can still share `npm update <child>`.
|
|
198
206
|
// Spawn each command once; the displayed plan already dedupes the same way.
|
|
199
207
|
const seenCommands = new Set();
|
|
200
|
-
for (let i = 0; i <
|
|
201
|
-
const target =
|
|
208
|
+
for (let i = 0; i < runnableTargets.length; i++) {
|
|
209
|
+
const target = runnableTargets[i];
|
|
202
210
|
for (const commandParts of buildApplyCommands(params.plan.packageManager, target)) {
|
|
203
211
|
const commandLine = commandParts.join(" ");
|
|
204
212
|
if (seenCommands.has(commandLine))
|
|
@@ -216,12 +224,12 @@ export async function applyFixesIfRequested(params) {
|
|
|
216
224
|
}
|
|
217
225
|
}
|
|
218
226
|
}
|
|
219
|
-
spinner.succeed(`Applied ${
|
|
227
|
+
spinner.succeed(`Applied ${runnableTargets.length} package ${pluralize(runnableTargets.length, "fix", "fixes")} with ${commandLabel}`);
|
|
220
228
|
return {
|
|
221
|
-
appliedFixCount:
|
|
222
|
-
appliedWithinRangeRefreshCount:
|
|
229
|
+
appliedFixCount: runnableTargets.length,
|
|
230
|
+
appliedWithinRangeRefreshCount: runnableTargets.filter(target => target.kind === "parent-update").length,
|
|
223
231
|
...unapplied,
|
|
224
|
-
applied:
|
|
232
|
+
applied: runnableTargets.map(target => ({
|
|
225
233
|
package: target.package,
|
|
226
234
|
from: target.currentVersion ?? "unknown",
|
|
227
235
|
to: target.targetVersion,
|
|
@@ -253,7 +261,7 @@ export function printFixModeSummary(params) {
|
|
|
253
261
|
? ` (incl. ${result.appliedWithinRangeRefreshCount} within-range ${pluralize(result.appliedWithinRangeRefreshCount, "refresh", "refreshes")})`
|
|
254
262
|
: "";
|
|
255
263
|
console.log(`- Applied fixes: ${chalk.green(String(result.appliedFixCount))}${chalk.gray(refreshNote)}`);
|
|
256
|
-
const notAutoApplied = result.parentUpgradeCount + result.noFixCount;
|
|
264
|
+
const notAutoApplied = result.parentUpgradeCount + result.noFixCount + (result.optionShapedNameCount ?? 0);
|
|
257
265
|
console.log(`- Not auto-applied: ${chalk.yellow(String(notAutoApplied))}`);
|
|
258
266
|
if (result.parentUpgradeCount > 0) {
|
|
259
267
|
const breakingNote = result.breakingUpgradeCount > 0
|
|
@@ -264,6 +272,10 @@ export function printFixModeSummary(params) {
|
|
|
264
272
|
if (result.noFixCount > 0) {
|
|
265
273
|
console.log(` - No fix available: ${chalk.yellow(String(result.noFixCount))}`);
|
|
266
274
|
}
|
|
275
|
+
const optionShapedNameCount = result.optionShapedNameCount ?? 0;
|
|
276
|
+
if (optionShapedNameCount > 0) {
|
|
277
|
+
console.log(` - Package name looks like an option (no command offered): ${chalk.yellow(String(optionShapedNameCount))}`);
|
|
278
|
+
}
|
|
267
279
|
console.log(`- Findings before fix: ${chalk.white(String(params.findingsBeforeFix))}`);
|
|
268
280
|
console.log(`- Remaining findings after fix: ${chalk.white(String(params.findingsAfterFix))}`);
|
|
269
281
|
console.log(`- Remaining severity mix: critical ${chalk.redBright(String(params.remainingBySeverity.critical))}, high ${chalk.red(String(params.remainingBySeverity.high))}, medium ${chalk.yellow(String(params.remainingBySeverity.medium))}, low ${chalk.blueBright(String(params.remainingBySeverity.low))}, unknown ${chalk.magenta(String(params.remainingBySeverity.unknown))}`);
|
|
@@ -26,6 +26,21 @@ export function installPackageSpec(target) {
|
|
|
26
26
|
const version = target.registryName ? `${NPM_ALIAS_PROTOCOL}${target.registryName}@${target.targetVersion}` : target.targetVersion;
|
|
27
27
|
return `${target.package}@${version}`;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* A package name beginning with "-" would be read as an option by the package
|
|
31
|
+
* manager (npm never allows such a name), so fix commands that would name one
|
|
32
|
+
* are suppressed rather than printed or run.
|
|
33
|
+
*/
|
|
34
|
+
export function isOptionShapedName(name) {
|
|
35
|
+
return name.startsWith("-");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The package name a fix command would name. For a parent-update the command
|
|
39
|
+
* names the child being refreshed; otherwise it names the package itself.
|
|
40
|
+
*/
|
|
41
|
+
export function commandPackageName(target) {
|
|
42
|
+
return target.kind === "parent-update" ? (target.childPackage ?? target.package) : target.package;
|
|
43
|
+
}
|
|
29
44
|
/** npm lockfile v1 stores an alias's resolved name and version in `version`. */
|
|
30
45
|
export function parseNpmAliasVersion(value) {
|
|
31
46
|
if (typeof value !== "string" || !value.startsWith(NPM_ALIAS_PROTOCOL)) {
|