cve-lite-cli 1.41.2 → 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/formatters.js +7 -3
- package/dist/output/html-reporter.js +6 -2
- package/dist/output/override-findings-terminal.js +4 -3
- package/dist/output/override-fix-command.js +7 -1
- package/dist/output/printers.js +1 -1
- package/dist/overrides/detectors/pd001-override-only-phantom.js +2 -2
- package/dist/overrides/detectors/pd002-transitive-only-phantom.js +2 -2
- package/dist/overrides/detectors/phantom-utils.js +7 -4
- package/dist/remediation/fix-commands.js +68 -10
- package/dist/scan/single-scan.js +1 -0
- package/dist/scanner.js +4 -2
- package/dist/utils/fix-runner.js +24 -12
- package/dist/utils/package-identity.js +15 -0
- package/dist/utils/shell-quote.js +16 -0
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import { inferSeverity } from "../osv/severity.js";
|
|
|
6
6
|
import { getPrimaryParent, getRootDependencies, isUnconfirmedFix } from "../utils/finding.js";
|
|
7
7
|
import { calculatePathCoverage, formatDependencyPath } from "../utils/path-coverage.js";
|
|
8
8
|
import { pluralize, isOutputStdout } from "../utils/string.js";
|
|
9
|
-
import {
|
|
9
|
+
import { npmLsCommand, UNSAFE_LS_INSTRUCTION } from "../utils/shell-quote.js";
|
|
10
10
|
import { hasMaliciousAdvisory } from "../utils/vuln.js";
|
|
11
11
|
import { computePrioritySignal } from "../utils/priority-signal.js";
|
|
12
12
|
import { computeContextualSignals } from "../utils/contextual-signals.js";
|
|
@@ -114,7 +114,9 @@ export function getRecommendedAction(finding) {
|
|
|
114
114
|
// a degenerate length-2 chain (project -> vulnerable, common when the
|
|
115
115
|
// package is hoisted to top-level node_modules). The advice is the same
|
|
116
116
|
// either way - inspect the lockfile or run `<pm> ls` to find the parent.
|
|
117
|
-
const
|
|
117
|
+
const lsCommand = npmLsCommand(finding.pkg.name);
|
|
118
|
+
const lookup = lsCommand ? `Run \`${lsCommand}\` (or your package manager equivalent)` : UNSAFE_LS_INSTRUCTION;
|
|
119
|
+
const inspectMessage = `No parent dependency was identified for ${finding.pkg.name} in the lockfile. ${lookup} to find which package pulls it in`;
|
|
118
120
|
if (directTarget) {
|
|
119
121
|
return `${inspectMessage}, then upgrade toward ${directTarget}+.`;
|
|
120
122
|
}
|
|
@@ -230,7 +232,9 @@ export function summarizeNextAction(finding) {
|
|
|
230
232
|
return `Upgrade ${parent} - no safe version identified. Find a release resolving ${finding.pkg.name} to ${directTarget}+.`;
|
|
231
233
|
}
|
|
232
234
|
if (directTarget) {
|
|
233
|
-
|
|
235
|
+
const lsCommand = npmLsCommand(finding.pkg.name);
|
|
236
|
+
const lookup = lsCommand ? `Run \`${lsCommand}\`` : UNSAFE_LS_INSTRUCTION;
|
|
237
|
+
return `No parent identified in the lockfile. ${lookup} to find the parent, then upgrade toward ${directTarget}+.`;
|
|
234
238
|
}
|
|
235
239
|
return `Inspect the parent dependency chain for ${finding.pkg.name} and choose the safest available upgrade.`;
|
|
236
240
|
}
|
|
@@ -6,7 +6,7 @@ import { serializeFinding, summarizeNextAction, summarizeRisk, formatCooldownWar
|
|
|
6
6
|
import { loadLogoDataUri } from "./logos.js";
|
|
7
7
|
import { isBreakingUpgrade } from "../utils/version.js";
|
|
8
8
|
import { pluralize } from "../utils/string.js";
|
|
9
|
-
import {
|
|
9
|
+
import { npmLsCommand, UNSAFE_LS_INSTRUCTION } from "../utils/shell-quote.js";
|
|
10
10
|
import { MAL_GIT_SOURCE_PINNED_DISPLAY, MAL_GIT_SOURCE_FLOATING_DISPLAY, severityOrder } from "../constants.js";
|
|
11
11
|
import { hasMaliciousAdvisory } from "../utils/vuln.js";
|
|
12
12
|
import { renderOverrideFindingsHtml } from "./override-findings-html.js";
|
|
@@ -740,7 +740,7 @@ function renderTransitiveContextCol(finding) {
|
|
|
740
740
|
return `<div class="detail-col" style="max-width:200px">
|
|
741
741
|
<h4>Context</h4>
|
|
742
742
|
<span class="tier-err">✕ No parent identified</span>
|
|
743
|
-
<p style="font-size:12px;color:var(--text-2);margin-top:4px"
|
|
743
|
+
<p style="font-size:12px;color:var(--text-2);margin-top:4px">${lsLookupHtml(finding.package)} to find which package pulls it in.</p>
|
|
744
744
|
</div>`;
|
|
745
745
|
}
|
|
746
746
|
export function renderCompletenessBanner(completeness) {
|
|
@@ -1036,3 +1036,7 @@ export function openInBrowser(filePath) {
|
|
|
1036
1036
|
// Best-effort only: report creation should not fail if the OS open command is unavailable.
|
|
1037
1037
|
}
|
|
1038
1038
|
}
|
|
1039
|
+
function lsLookupHtml(packageName) {
|
|
1040
|
+
const lsCommand = npmLsCommand(packageName);
|
|
1041
|
+
return lsCommand ? `Run <code>${escapeHtml(lsCommand)}</code>` : escapeHtml(UNSAFE_LS_INSTRUCTION);
|
|
1042
|
+
}
|
|
@@ -3,7 +3,7 @@ import { groupSkippedByReason, skippedHeadline, skippedRuleCount } from "./skipp
|
|
|
3
3
|
import { chalk, stripAnsi } from "../utils/chalk.js";
|
|
4
4
|
import { formatSeverityLabel, SEVERITY_ORDER } from "../utils/severity.js";
|
|
5
5
|
import { pluralize } from "../utils/string.js";
|
|
6
|
-
import { buildOverrideFixCommand, overrideCommandTargetSuffix } from "./override-fix-command.js";
|
|
6
|
+
import { buildOverrideFixCommand, isPasteableOverrideTarget, overrideCommandTargetSuffix } from "./override-fix-command.js";
|
|
7
7
|
const COL_RULE_MAX = 8;
|
|
8
8
|
const COL_PKG_MAX = 30;
|
|
9
9
|
const COL_MSG_MAX = 50;
|
|
@@ -69,14 +69,15 @@ export function renderOverrideFindings(findings, options) {
|
|
|
69
69
|
if (f.fix?.runnableCommand && !seenRules.has(f.ruleId)) {
|
|
70
70
|
seenRules.add(f.ruleId);
|
|
71
71
|
const cmd = buildOverrideFixCommand(f.fix.runnableCommand, commandTarget);
|
|
72
|
-
|
|
72
|
+
if (cmd)
|
|
73
|
+
lines.push(chalk.bold.cyan(`> ${cmd}`));
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
lines.push("");
|
|
76
77
|
}
|
|
77
78
|
const projectInfix = overrideCommandTargetSuffix(commandTarget);
|
|
78
79
|
const allFixableRules = new Set(findings.filter(f => f.fix?.runnableCommand).map(f => f.ruleId));
|
|
79
|
-
if (allFixableRules.size >= 2) {
|
|
80
|
+
if (allFixableRules.size >= 2 && isPasteableOverrideTarget(commandTarget)) {
|
|
80
81
|
const fixAllCmd = `cve-lite${projectInfix} overrides --fix`;
|
|
81
82
|
lines.push("💡 " + chalk.gray(`Tip: run ${fixAllCmd} to apply all auto-fixable fixes in one shot.`));
|
|
82
83
|
lines.push("");
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { OVERRIDES_COMMAND } from "../constants.js";
|
|
2
|
-
import { quoteShellPath } from "../utils/shell-quote.js";
|
|
2
|
+
import { isSafeInEveryShell, quoteShellPath } from "../utils/shell-quote.js";
|
|
3
3
|
// HTML callers pass a project-relative path, and terminal callers pass a
|
|
4
4
|
// cwd-relative path. An empty target or "." needs no positional argument.
|
|
5
5
|
export function overrideCommandTargetSuffix(commandTarget) {
|
|
6
6
|
return commandTarget && commandTarget !== "." ? ` ${quoteShellPath(commandTarget)}` : "";
|
|
7
7
|
}
|
|
8
|
+
/** False when the folder name is not safe to paste into every shell, so no command should be printed for it. */
|
|
9
|
+
export function isPasteableOverrideTarget(commandTarget) {
|
|
10
|
+
return !commandTarget || isSafeInEveryShell(commandTarget);
|
|
11
|
+
}
|
|
8
12
|
export function buildOverrideFixCommand(runnableCommand, commandTarget) {
|
|
13
|
+
if (!isPasteableOverrideTarget(commandTarget))
|
|
14
|
+
return null;
|
|
9
15
|
const suffix = overrideCommandTargetSuffix(commandTarget);
|
|
10
16
|
return runnableCommand.replace(OVERRIDES_COMMAND, () => `cve-lite${suffix} overrides`);
|
|
11
17
|
}
|
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDeclaredPackages, phantomInstallInstruction, undeclaredImportFiles } from "./phantom-utils.js";
|
|
2
2
|
const RULE_ID = "PD001";
|
|
3
3
|
export function detect(ctx) {
|
|
4
4
|
if (ctx.skippedDetectors.some((s) => s.ruleId === RULE_ID))
|
|
@@ -24,7 +24,7 @@ export function detect(ctx) {
|
|
|
24
24
|
message: `${pkgName} is imported in source but only present via an override pin - declare it as a dependency`,
|
|
25
25
|
details: `Imported in: ${shown.join(", ")}${extra}. ` +
|
|
26
26
|
`In pnpm strict mode (default on Vercel), override-only packages are not importable and will cause a deploy failure. ` +
|
|
27
|
-
|
|
27
|
+
phantomInstallInstruction(ctx.packageManager, pkgName),
|
|
28
28
|
references: ["https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/PD001.md"],
|
|
29
29
|
});
|
|
30
30
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDeclaredPackages, phantomInstallInstruction, undeclaredImportFiles } from "./phantom-utils.js";
|
|
2
2
|
const RULE_ID = "PD002";
|
|
3
3
|
export function detect(ctx) {
|
|
4
4
|
if (ctx.skippedDetectors.some((s) => s.ruleId === RULE_ID))
|
|
@@ -26,7 +26,7 @@ export function detect(ctx) {
|
|
|
26
26
|
message: `${pkgName} is imported in source but only present as a transitive dependency - declare it explicitly`,
|
|
27
27
|
details: `Imported in: ${shown.join(", ")}${extra}. ` +
|
|
28
28
|
`If the parent package drops or changes this dependency, your code will break without warning. ` +
|
|
29
|
-
|
|
29
|
+
phantomInstallInstruction(ctx.packageManager, pkgName),
|
|
30
30
|
references: ["https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/PD002.md"],
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { shellQuote } from "../../utils/shell-quote.js";
|
|
1
|
+
import { isSafeInEveryShell, shellQuote } from "../../utils/shell-quote.js";
|
|
2
2
|
export function getDeclaredPackages(packageJson) {
|
|
3
3
|
const declared = new Set();
|
|
4
4
|
for (const section of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
@@ -49,7 +49,10 @@ export function installCmd(pm) {
|
|
|
49
49
|
return "bun add";
|
|
50
50
|
return "npm install";
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
53
|
-
export function
|
|
54
|
-
|
|
52
|
+
/** The closing instruction for a phantom-dependency finding: a copyable install command, or a plain step when the name is not safe in every shell. */
|
|
53
|
+
export function phantomInstallInstruction(pm, pkgName) {
|
|
54
|
+
if (!isSafeInEveryShell(pkgName)) {
|
|
55
|
+
return "Declare it in package.json (no command is shown because the name is not safe to paste into every shell).";
|
|
56
|
+
}
|
|
57
|
+
return `Run: ${installCmd(pm)} ${shellQuote(pkgName)}`;
|
|
55
58
|
}
|
|
@@ -5,14 +5,14 @@ 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
|
-
import { quoteShellPath, shellQuote } from "../utils/shell-quote.js";
|
|
8
|
+
import { isSafeInEveryShell, quoteShellPath, shellQuote } from "../utils/shell-quote.js";
|
|
9
9
|
import { buildNpmWorkspaceMap } from "../parsers/package-lock.js";
|
|
10
10
|
import { buildPnpmWorkspaceMap } from "../parsers/pnpm-lock.js";
|
|
11
11
|
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,
|
|
@@ -352,7 +352,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
352
352
|
: "No confident automatic fix command could be generated for this issue.",
|
|
353
353
|
});
|
|
354
354
|
}
|
|
355
|
-
const
|
|
355
|
+
const sortedTargets = [...targetsByKey.values()].sort((a, b) => {
|
|
356
356
|
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
357
357
|
if (sevDelta !== 0)
|
|
358
358
|
return sevDelta;
|
|
@@ -365,6 +365,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
365
365
|
return kindDelta;
|
|
366
366
|
return a.package.localeCompare(b.package);
|
|
367
367
|
});
|
|
368
|
+
const targets = withholdShellUnsafeTargets(sortedTargets, findings, skippedByKey, options?.subfolder);
|
|
368
369
|
// Some install targets carry an explicit `command` built without workspace
|
|
369
370
|
// context (e.g. a chain-resolution command). This raw field is exposed in JSON
|
|
370
371
|
// and embedded in the HTML report, so scope it to the declaring member too.
|
|
@@ -671,7 +672,64 @@ export function planVersionForFinding(plan, finding) {
|
|
|
671
672
|
}
|
|
672
673
|
return target.targetVersion;
|
|
673
674
|
}
|
|
674
|
-
|
|
675
|
+
export const UNSAFE_PACKAGE_REASON = "The package or workspace name contains characters that are not safe to paste into every shell, so no command is offered. Check the name in your lockfile before running anything for it.";
|
|
676
|
+
export const UNSAFE_FOLDER_REASON = "The folder name contains characters that are not safe to paste into every shell, so no command is offered for this folder.";
|
|
677
|
+
// Every token a target's printed command is built from. A token that would
|
|
678
|
+
// still act in cmd.exe or PowerShell despite our quoting withholds the command.
|
|
679
|
+
function unsafeShellReason(target) {
|
|
680
|
+
const tokens = [
|
|
681
|
+
target.package,
|
|
682
|
+
target.registryName,
|
|
683
|
+
target.targetVersion,
|
|
684
|
+
target.childPackage,
|
|
685
|
+
target.childTargetVersion,
|
|
686
|
+
...(target.workspaces ?? []),
|
|
687
|
+
];
|
|
688
|
+
return tokens.every(token => token === undefined || isSafeInEveryShell(token)) ? null : UNSAFE_PACKAGE_REASON;
|
|
689
|
+
}
|
|
690
|
+
// Drops targets whose printed command could not be pasted safely into every
|
|
691
|
+
// shell, and records a skip for each finding that loses its command, under the
|
|
692
|
+
// finding's own package so a parent-update target named after its parent cannot
|
|
693
|
+
// hide the child it was refreshing.
|
|
694
|
+
function withholdShellUnsafeTargets(sortedTargets, findings, skippedByKey, subfolder) {
|
|
695
|
+
const unsafeFolder = !!subfolder && !isSafeInEveryShell(subfolder);
|
|
696
|
+
const kept = [];
|
|
697
|
+
const withheld = new Map();
|
|
698
|
+
for (const target of sortedTargets) {
|
|
699
|
+
const reason = unsafeFolder ? UNSAFE_FOLDER_REASON : unsafeShellReason(target);
|
|
700
|
+
if (reason)
|
|
701
|
+
withheld.set(target, reason);
|
|
702
|
+
else
|
|
703
|
+
kept.push(target);
|
|
704
|
+
}
|
|
705
|
+
if (withheld.size === 0)
|
|
706
|
+
return kept;
|
|
707
|
+
const withheldPlan = { targets: [...withheld.keys()] };
|
|
708
|
+
for (const finding of findings) {
|
|
709
|
+
const target = findFixTargetForFinding(withheldPlan, finding);
|
|
710
|
+
if (!target)
|
|
711
|
+
continue;
|
|
712
|
+
skippedByKey.set(`${finding.relationship}:${packageInstanceKey(finding.pkg)}`, {
|
|
713
|
+
package: finding.pkg.name,
|
|
714
|
+
version: finding.pkg.version,
|
|
715
|
+
relationship: finding.relationship,
|
|
716
|
+
reason: withheld.get(target),
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
return kept;
|
|
720
|
+
}
|
|
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
|
+
}
|
|
675
733
|
const key = targetKey(finding, next);
|
|
676
734
|
const existing = targetsByKey.get(key);
|
|
677
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/scanner.js
CHANGED
|
@@ -28,7 +28,7 @@ import { buildPnpmWorkspaceMap } from "./parsers/pnpm-lock.js";
|
|
|
28
28
|
import { buildNpmWorkspaceMap } from "./parsers/package-lock.js";
|
|
29
29
|
import { buildBunWorkspaceMap } from "./parsers/bun-lock.js";
|
|
30
30
|
import { pluralize } from "./utils/string.js";
|
|
31
|
-
import {
|
|
31
|
+
import { npmLsCommand, UNSAFE_LS_INSTRUCTION } from "./utils/shell-quote.js";
|
|
32
32
|
import path from "node:path";
|
|
33
33
|
import { resolveRegistryConfig } from "./utils/registry-config.js";
|
|
34
34
|
import { extractErrorMessage } from "./utils/network.js";
|
|
@@ -590,7 +590,9 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
590
590
|
continue;
|
|
591
591
|
updateAnalysisProgress("resolving remediation for", `${finding.pkg.name}@${finding.pkg.version}`);
|
|
592
592
|
if (aliasRemediationFindings.has(finding)) {
|
|
593
|
-
const
|
|
593
|
+
const lsCommand = npmLsCommand(finding.pkg.name);
|
|
594
|
+
const lookup = lsCommand ? `Run \`${lsCommand}\`` : UNSAFE_LS_INSTRUCTION;
|
|
595
|
+
const aliasNote = `Automatic parent remediation is unavailable for paths containing an npm alias. ${lookup} to inspect the declaring dependency, then rescan after updating it.`;
|
|
594
596
|
finding.fixVersionValidationNote = [finding.fixVersionValidationNote, aliasNote].filter(Boolean).join(" ");
|
|
595
597
|
continue;
|
|
596
598
|
}
|
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)) {
|
|
@@ -5,8 +5,24 @@ export function shellQuote(token) {
|
|
|
5
5
|
return token;
|
|
6
6
|
return "'" + token.replace(/'/g, "'\\''") + "'";
|
|
7
7
|
}
|
|
8
|
+
// shellQuote only protects POSIX shells. cmd.exe ignores single quotes, so
|
|
9
|
+
// & | < > ^ % ! and double quotes still act there, and PowerShell reads the
|
|
10
|
+
// POSIX escape for a quote inside a token differently, as it does a backtick.
|
|
11
|
+
// Spaces are left alone: in cmd.exe they only split an argument, they cannot
|
|
12
|
+
// run anything.
|
|
13
|
+
const UNSAFE_IN_SOME_SHELL = /[&|<>^%!"'`\u0000-\u001f\u007f]/;
|
|
14
|
+
/** True when a quoted token stays inert if pasted into any common shell, Windows included. */
|
|
15
|
+
export function isSafeInEveryShell(token) {
|
|
16
|
+
return !UNSAFE_IN_SOME_SHELL.test(token);
|
|
17
|
+
}
|
|
8
18
|
export function quoteShellPath(directory) {
|
|
9
19
|
// Preserve literal backslashes in POSIX names and keep ordinary Windows paths unquoted.
|
|
10
20
|
const normalized = path.sep === "\\" ? directory.replace(/\\/g, "/") : directory;
|
|
11
21
|
return shellQuote(normalized.startsWith("-") ? `./${normalized}` : normalized);
|
|
12
22
|
}
|
|
23
|
+
/** Shown in place of an `npm ls` command when the package name is not safe to paste into every shell. */
|
|
24
|
+
export const UNSAFE_LS_INSTRUCTION = "Look it up with your package manager's ls command (no command is shown because the name is not safe to paste into every shell)";
|
|
25
|
+
/** `npm ls <name>` for a pasteable inspection hint, or null when the name is not safe in every shell. */
|
|
26
|
+
export function npmLsCommand(packageName) {
|
|
27
|
+
return isSafeInEveryShell(packageName) ? `npm ls ${shellQuote(packageName)}` : null;
|
|
28
|
+
}
|