cve-lite-cli 1.41.2 → 1.41.3

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.
@@ -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 { shellQuote } from "../utils/shell-quote.js";
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 inspectMessage = `No parent dependency was identified for ${finding.pkg.name} in the lockfile. Run \`npm ls ${shellQuote(finding.pkg.name)}\` (or your package manager equivalent) to find which package pulls it in`;
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
- return `No parent identified in the lockfile. Run \`npm ls ${shellQuote(finding.pkg.name)}\` to find the parent, then upgrade toward ${directTarget}+.`;
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 { shellQuote } from "../utils/shell-quote.js";
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">Run <code>npm ls ${escapeHtml(shellQuote(finding.package))}</code> to find which package pulls it in.</p>
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
- lines.push(chalk.bold.cyan(`> ${cmd}`));
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
  }
@@ -1,4 +1,4 @@
1
- import { formatPhantomInstallCommand, getDeclaredPackages, undeclaredImportFiles } from "./phantom-utils.js";
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
- `Run: ${formatPhantomInstallCommand(ctx.packageManager, pkgName)}`,
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 { formatPhantomInstallCommand, getDeclaredPackages, undeclaredImportFiles } from "./phantom-utils.js";
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
- `Run: ${formatPhantomInstallCommand(ctx.packageManager, pkgName)}`,
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
- /** Format a copyable phantom-dependency install command with shell-quoted package name. */
53
- export function formatPhantomInstallCommand(pm, pkgName) {
54
- return `${installCmd(pm)} ${shellQuote(pkgName)}`;
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,7 +5,7 @@ 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";
@@ -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 targets = [...targetsByKey.values()].sort((a, b) => {
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,6 +672,52 @@ export function planVersionForFinding(plan, finding) {
671
672
  }
672
673
  return target.targetVersion;
673
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
+ }
674
721
  function upsertTarget(targetsByKey, finding, next) {
675
722
  const key = targetKey(finding, next);
676
723
  const existing = targetsByKey.get(key);
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 { shellQuote } from "./utils/shell-quote.js";
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 aliasNote = `Automatic parent remediation is unavailable for paths containing an npm alias. Run \`npm ls ${shellQuote(finding.pkg.name)}\` to inspect the declaring dependency, then rescan after updating it.`;
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
  }
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.41.2",
3
+ "version": "1.41.3",
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": {