cve-lite-cli 1.5.0 → 1.5.1

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 CHANGED
@@ -85,7 +85,7 @@ For real-world remediation examples, see the [OWASP Juice Shop case study](docs/
85
85
  ## New here? Start here
86
86
 
87
87
  1. run one scan on a real project with `npx cve-lite-cli /path/to/project --verbose`
88
- 2. review direct vs transitive findings and the `Copy And Run These Fix Commands` section
88
+ 2. review direct vs transitive findings and the `Copy And Run These Fix Commands` section (direct command groups apply to manifest-declared dependencies)
89
89
  3. compare the output with your current scanner workflow
90
90
  4. check a real walkthrough:
91
91
  - [OWASP Juice Shop case study](docs/case-studies/owasp-juice-shop.md)
@@ -239,7 +239,7 @@ The most important section to look for in the output is:
239
239
  🛠 Copy And Run These Fix Commands
240
240
  ```
241
241
 
242
- That is one of the clearest differentiators in CVE Lite CLI. Instead of only showing advisories and severity counts, the tool tries to turn the findings into concrete commands developers can copy and run immediately.
242
+ That is one of the clearest differentiators in CVE Lite CLI. Instead of only showing advisories and severity counts, the tool tries to turn findings into concrete commands developers can copy and run immediately for manifest-declared direct dependencies, while still showing parent-upgrade guidance for transitive issues when available.
243
243
 
244
244
  For example, the tool can now suggest a concrete next command such as:
245
245
 
@@ -526,6 +526,7 @@ The commands are:
526
526
  - package-manager-aware
527
527
  - grouped by severity and fix type
528
528
  - designed to be copied directly from the terminal
529
+ - direct command groups are limited to dependencies declared in the scanned root manifest
529
530
  - shown before the deeper remediation detail in verbose mode
530
531
  - when enough advisory data exists, targeted to the lowest known non-vulnerable version with transparent version-scan counts in verbose output
531
532
 
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import process from "node:process";
4
5
  import { parseArgs } from "./cli/args.js";
@@ -131,7 +132,8 @@ if (parsedArgs) {
131
132
  process.exit(0);
132
133
  return;
133
134
  }
134
- const findings = await scanPackages(packages, batchSize, options);
135
+ const directDependencyNames = readDirectDependencyNames(projectPath, !!options.prodOnly);
136
+ const findings = await scanPackages(packages, batchSize, options, { directDependencyNames });
135
137
  const sorted = findings.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity]);
136
138
  const coverage = buildCoverageNotes(scanInput, !!options.offline || !!options.offlineDb);
137
139
  const minSeverity = normalizeSeverity(options.minSeverity || "medium");
@@ -197,6 +199,34 @@ function formatAdvisorySourceLine(sourceLabel) {
197
199
  }
198
200
  return `${match[1]} (${chalk.cyan(match[2])})`;
199
201
  }
202
+ function readDirectDependencyNames(projectPath, prodOnly) {
203
+ const packageJsonPath = path.join(projectPath, "package.json");
204
+ if (!fs.existsSync(packageJsonPath)) {
205
+ return null;
206
+ }
207
+ try {
208
+ const raw = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
209
+ const directNames = new Set();
210
+ const sections = [
211
+ raw?.dependencies,
212
+ raw?.optionalDependencies,
213
+ ];
214
+ if (!prodOnly) {
215
+ sections.push(raw?.devDependencies);
216
+ }
217
+ for (const section of sections) {
218
+ if (!section || typeof section !== "object")
219
+ continue;
220
+ for (const name of Object.keys(section)) {
221
+ directNames.add(name);
222
+ }
223
+ }
224
+ return directNames;
225
+ }
226
+ catch {
227
+ return null;
228
+ }
229
+ }
200
230
  function formatAdvisoryDbFreshness(lastSyncAt) {
201
231
  if (!lastSyncAt) {
202
232
  return chalk.yellow("unknown");
@@ -122,6 +122,7 @@ export function printSuggestedFixCommands(findings, scanInput) {
122
122
  if (plan.sections.length === 0)
123
123
  return;
124
124
  const sharedDirectTableWidths = computeSharedDirectTableWidths(plan.sections);
125
+ const sharedParentUpgradeTableWidths = computeSharedParentUpgradeTableWidths(plan.sections);
125
126
  console.log("");
126
127
  console.log(chalk.bold.yellow("🛠 Copy And Run These Fix Commands"));
127
128
  console.log(`${chalk.gray("Detected package manager:")} ${chalk.cyan(plan.packageManager)} ${chalk.gray(`(${plan.sourceLabel})`)}`);
@@ -137,6 +138,9 @@ export function printSuggestedFixCommands(findings, scanInput) {
137
138
  console.log(chalk.gray(` Note: ${note}`));
138
139
  }
139
140
  }
141
+ else if (shouldRenderParentUpgradeTable(section.targets)) {
142
+ printParentUpgradeTargetsTable(section.targets, sharedParentUpgradeTableWidths);
143
+ }
140
144
  console.log(renderCommandCallout(section.command));
141
145
  }
142
146
  }
@@ -533,6 +537,26 @@ function printDirectTargetsTable(targets, remainingNotes, validationSummary, wid
533
537
  }
534
538
  console.log(line("└", "┴", "┘"));
535
539
  }
540
+ function printParentUpgradeTargetsTable(targets, widthsOverride) {
541
+ const headers = ["Package", "Current", "Recommended target", "Context"];
542
+ const rows = targets.map(target => [
543
+ target.package,
544
+ target.currentVersion ?? "-",
545
+ chalk.cyan(target.targetVersion),
546
+ chalk.gray(target.reason),
547
+ ]);
548
+ if (rows.length === 0)
549
+ return;
550
+ const widths = widthsOverride ?? computeTableWidths(headers, rows);
551
+ const line = (left, mid, right) => left + widths.map(w => "─".repeat(w + 2)).join(mid) + right;
552
+ console.log(line("┌", "┬", "┐"));
553
+ console.log(renderRow(headers, widths));
554
+ console.log(line("├", "┼", "┤"));
555
+ for (const row of rows) {
556
+ console.log(renderRow(row.map(value => String(value)), widths));
557
+ }
558
+ console.log(line("└", "┴", "┘"));
559
+ }
536
560
  function computeTableWidths(headers, rows) {
537
561
  return headers.map((header, index) => Math.min(40, Math.max(header.length, ...rows.map(row => stripAnsi(String(row[index])).length))));
538
562
  }
@@ -557,3 +581,24 @@ function computeSharedDirectTableWidths(sections) {
557
581
  }
558
582
  return computeTableWidths(headers, rows);
559
583
  }
584
+ function shouldRenderParentUpgradeTable(targets) {
585
+ return targets.length > 0 && targets.every(target => target.kind === "parent-upgrade");
586
+ }
587
+ function computeSharedParentUpgradeTableWidths(sections) {
588
+ const parentSections = sections.filter(section => shouldRenderParentUpgradeTable(section.targets));
589
+ if (parentSections.length === 0)
590
+ return undefined;
591
+ const headers = ["Package", "Current", "Recommended target", "Context"];
592
+ const rows = [];
593
+ for (const section of parentSections) {
594
+ for (const target of section.targets) {
595
+ rows.push([
596
+ target.package,
597
+ target.currentVersion ?? "-",
598
+ target.targetVersion,
599
+ target.reason,
600
+ ]);
601
+ }
602
+ }
603
+ return computeTableWidths(headers, rows);
604
+ }
@@ -94,6 +94,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput) {
94
94
  isUpgradeTarget(finding.recommendedParentUpgrade.currentVersion, finding.recommendedParentUpgrade.targetVersion)) {
95
95
  upsertTarget(targetsByPackage, {
96
96
  package: finding.recommendedParentUpgrade.package,
97
+ currentVersion: finding.recommendedParentUpgrade.currentVersion,
97
98
  targetVersion: finding.recommendedParentUpgrade.targetVersion,
98
99
  scannedVersions: null,
99
100
  knownVulnerableVersions: null,
@@ -196,6 +197,7 @@ function upsertTarget(targetsByPackage, next) {
196
197
  if (looksLikeVersion(existing.targetVersion) && looksLikeVersion(next.targetVersion)) {
197
198
  if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
198
199
  merged.targetVersion = next.targetVersion;
200
+ merged.currentVersion = next.currentVersion ?? merged.currentVersion;
199
201
  merged.reason = next.reason;
200
202
  merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
201
203
  merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
@@ -204,6 +206,7 @@ function upsertTarget(targetsByPackage, next) {
204
206
  return;
205
207
  }
206
208
  if (next.kind === "direct" && existing.kind !== "direct") {
209
+ merged.currentVersion = next.currentVersion ?? merged.currentVersion;
207
210
  merged.targetVersion = next.targetVersion;
208
211
  merged.reason = next.reason;
209
212
  merged.adjustmentNote = next.adjustmentNote ?? merged.adjustmentNote;
package/dist/scanner.js CHANGED
@@ -37,7 +37,7 @@ export function createAdvisorySource(options) {
37
37
  function getPackageCacheKey(pkg) {
38
38
  return `${pkg.ecosystem}:${pkg.name}@${pkg.version}`;
39
39
  }
40
- export async function scanPackages(packages, batchSize, options) {
40
+ export async function scanPackages(packages, batchSize, options, context) {
41
41
  const sourceContext = createAdvisorySource({
42
42
  osvUrl: options.osvUrl,
43
43
  offline: options.offline,
@@ -165,7 +165,7 @@ export async function scanPackages(packages, batchSize, options) {
165
165
  const severity = maxSeverity(vulnerabilities);
166
166
  const cveAliases = unique(vulnerabilities.flatMap(v => (v.aliases ?? []).filter(a => a.startsWith("CVE-"))));
167
167
  const dependencyPaths = result.pkg.paths ?? [];
168
- const relationship = classifyRelationship(dependencyPaths);
168
+ const relationship = classifyRelationship(dependencyPaths, result.pkg.name, context?.directDependencyNames);
169
169
  const firstFixedVersion = findFirstFixedVersion(vulnerabilities);
170
170
  return {
171
171
  pkg: result.pkg,
@@ -252,9 +252,13 @@ function isAdvisoryDbStale(metadata) {
252
252
  }
253
253
  return Date.now() - timestamp > ADVISORY_DB_STALE_AFTER_MS;
254
254
  }
255
- function classifyRelationship(paths) {
255
+ function classifyRelationship(paths, packageName, directDependencyNames) {
256
+ if (packageName && directDependencyNames?.has(packageName))
257
+ return "direct";
256
258
  if (paths.length === 0)
257
259
  return "unknown";
260
+ if (directDependencyNames)
261
+ return "transitive";
258
262
  const shortest = Math.min(...paths.map(p => p.length));
259
263
  if (shortest <= 2)
260
264
  return "direct";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
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": {