cve-lite-cli 1.28.0 → 1.30.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.
Files changed (47) hide show
  1. package/README.md +30 -4
  2. package/dist/advisory/osv-advisory-source.js +3 -0
  3. package/dist/cli/help.js +3 -2
  4. package/dist/cli/validate.js +6 -0
  5. package/dist/constants.js +1 -0
  6. package/dist/index.js +50 -7
  7. package/dist/maintenance/dm001-maintenance-risk.js +74 -15
  8. package/dist/maintenance/score.js +51 -0
  9. package/dist/output/formatters.js +21 -8
  10. package/dist/output/html-reporter.js +133 -12
  11. package/dist/output/maintenance-findings-html.js +4 -0
  12. package/dist/output/maintenance-findings-sarif.js +58 -0
  13. package/dist/output/maintenance-terminal.js +63 -5
  14. package/dist/output/multi-folder-html-reporter.js +64 -7
  15. package/dist/output/multi-folder-printer.js +11 -2
  16. package/dist/output/override-findings-html.js +6 -5
  17. package/dist/output/override-findings-terminal.js +2 -1
  18. package/dist/output/printers.js +92 -30
  19. package/dist/output/sarif.js +23 -7
  20. package/dist/output/write-outputs.js +4 -1
  21. package/dist/overrides/detectors/oa001-orphaned-target.js +2 -1
  22. package/dist/overrides/detectors/oa002-floating-tag.js +2 -1
  23. package/dist/overrides/detectors/oa003-wrong-section.js +2 -1
  24. package/dist/overrides/detectors/oa004-surpassed-pin.js +2 -1
  25. package/dist/overrides/detectors/oa005-nested-ineffective.js +2 -1
  26. package/dist/overrides/detectors/oa006-coupled-platform-binary.js +2 -1
  27. package/dist/overrides/detectors/oa007-frozen-latest.js +2 -1
  28. package/dist/overrides/detectors/oa009-stale-floor.js +2 -1
  29. package/dist/parsers/bun-lock.js +47 -7
  30. package/dist/parsers/npm-lock-graph.js +90 -12
  31. package/dist/parsers/pnpm-lock.js +60 -10
  32. package/dist/parsers/utils.js +0 -15
  33. package/dist/parsers/yarn-lock.js +140 -58
  34. package/dist/remediation/fix-commands.js +43 -12
  35. package/dist/remediation/npm-registry.js +69 -52
  36. package/dist/remediation/npm-transitive-resolution.js +5 -6
  37. package/dist/remediation/package-path-lookup.js +29 -0
  38. package/dist/remediation/parent-upgrade.js +2 -22
  39. package/dist/scan/completeness.js +49 -0
  40. package/dist/scan/multi-folder-scan.js +183 -15
  41. package/dist/scanner.js +210 -155
  42. package/dist/usage/scanner.js +12 -2
  43. package/dist/utils/finding.js +28 -0
  44. package/dist/utils/fix-runner.js +87 -50
  45. package/dist/utils/version.js +13 -4
  46. package/dist/utils/vuln.js +16 -0
  47. package/package.json +3 -3
@@ -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
- export function buildFixCommandParts(packageManager, targets) {
8
- if (packageManager === "npm") {
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
- skippedCount: params.totalFindings,
59
- skippedTransitiveCount: 0,
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
- const directTargets = params.plan.targets.filter(target => target.kind === "direct");
66
- const transitiveTargets = params.plan.targets.filter(target => target.kind !== "direct");
67
- const skippedDirect = params.plan.skipped.filter(skip => skip.relationship === "direct" || skip.relationship === "unknown");
68
- if (directTargets.length === 0) {
69
- const skippedCount = transitiveTargets.length + skippedDirect.length;
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
- skippedCount,
73
- skippedTransitiveCount: transitiveTargets.length,
74
- skippedNoValidatedTargetCount: skippedDirect.length,
102
+ appliedWithinRangeRefreshCount: 0,
103
+ ...unapplied,
75
104
  applied: [],
76
- note: "No validated direct dependency fixes were eligible for auto-apply.",
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 = directTargets.length;
81
- const spinner = createSpinner(`Applying direct package fixes with ${commandLabel}... 0/${total}`, params.options);
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 < directTargets.length; i++) {
84
- const target = directTargets[i];
85
- const commandParts = buildFixCommandParts(params.plan.packageManager, [target]);
86
- spinner.update(`Applying direct fix ${i + 1}/${total}: ${commandParts.join(" ")}`);
87
- const run = await runInstallCommand(commandParts[0], commandParts.slice(1), params.projectPath, params.debugLog);
88
- if (run.error) {
89
- spinner.fail("Failed to apply fixes");
90
- throw new Error(`Failed to apply fixes: ${run.error.message}${fixHint}`);
91
- }
92
- if ((run.status ?? 1) !== 0) {
93
- spinner.fail(`Fix command failed (${commandLabel})`);
94
- throw new Error(`Fix command exited with status ${run.status ?? 1}${fixHint}`);
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 ${directTargets.length} direct package ${pluralize(directTargets.length, "fix", "fixes")} with ${commandLabel}`);
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: directTargets.length,
101
- skippedCount,
102
- skippedTransitiveCount: transitiveTargets.length,
103
- skippedNoValidatedTargetCount: skippedDirect.length,
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
- console.log(`- Applied fixes: ${chalk.green(String(result.appliedFixCount))}`);
129
- console.log(`- Skipped findings: ${chalk.yellow(String(result.skippedCount))}`);
130
- if (result.skippedCount > 0) {
131
- console.log(` - Transitive (v1 skip): ${chalk.yellow(String(result.skippedTransitiveCount))}`);
132
- console.log(` - No validated direct target: ${chalk.yellow(String(result.skippedNoValidatedTargetCount))}`);
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))}`);
@@ -45,10 +45,19 @@ export function parseExactManifestVersion(spec) {
45
45
  return cleaned;
46
46
  return null;
47
47
  }
48
- export function isMajorVersionBump(from, to) {
49
- const fromMajor = Number(from.split(".")[0]);
50
- const toMajor = Number(to.split(".")[0]);
51
- return !Number.isNaN(fromMajor) && !Number.isNaN(toMajor) && toMajor > fromMajor;
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);
@@ -0,0 +1,16 @@
1
+ import { unique } from "./array.js";
2
+ // MAL-* is the OSV prefix for malicious code advisories. Guarded because OSV
3
+ // records are external data - the declared `string` type on OsvVuln.id does
4
+ // not guarantee a malformed advisory record cannot have a missing/non-string id.
5
+ export function isMaliciousVulnId(id) {
6
+ return typeof id === "string" && id.startsWith("MAL-");
7
+ }
8
+ export function hasMaliciousAdvisory(vulns) {
9
+ return vulns.some(v => isMaliciousVulnId(v.id));
10
+ }
11
+ // Guards against non-string alias elements from malformed OSV records - a
12
+ // malformed record with a null/undefined/non-string entry in `aliases` must
13
+ // not abort the whole scan.
14
+ export function extractCveAliases(vulns) {
15
+ return unique(vulns.flatMap(v => (v.aliases ?? []).filter((a) => typeof a === "string" && a.startsWith("CVE-"))));
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.28.0",
3
+ "version": "1.30.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": {
@@ -28,7 +28,7 @@
28
28
  "@types/better-sqlite3": "^7.6.13",
29
29
  "@types/jest": "^30.0.0",
30
30
  "@types/node": "^24.0.0",
31
- "jest": "^30.4.1",
31
+ "jest": "^30.4.2",
32
32
  "ts-jest": "^29.4.9",
33
33
  "tsx": "^4.22.0",
34
34
  "typescript": "^5.8.2"
@@ -47,7 +47,7 @@
47
47
  ],
48
48
  "license": "MIT",
49
49
  "engines": {
50
- "node": ">=18"
50
+ "node": ">=20"
51
51
  },
52
52
  "repository": {
53
53
  "type": "git",