cve-lite-cli 1.30.0 → 1.32.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.
@@ -18,10 +18,12 @@ import { getCliVersion } from "../utils/version-info.js";
18
18
  import { buildOverrideContext, audit } from "../overrides/index.js";
19
19
  import { NULL_AUDIT_LOG } from "../audit-log/index.js";
20
20
  import { detectDM001 } from "../maintenance/dm001-maintenance-risk.js";
21
+ import { detectLicenseIssues } from "../licenses/license-check.js";
22
+ import { renderLicenseFindings } from "../output/license-terminal.js";
21
23
  import { reachesFailOn } from "../utils/severity.js";
22
24
  import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "../utils/baseline.js";
23
25
  import { pluralize } from "../utils/string.js";
24
- import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, } from "./completeness.js";
26
+ import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, shouldFailForIncompleteScan, } from "./completeness.js";
25
27
  import { scanProjectForPackageUsage } from "../usage/scanner.js";
26
28
  export async function runMultiFolderScan(params) {
27
29
  const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
@@ -96,6 +98,20 @@ export async function runMultiFolderScan(params) {
96
98
  const directDependencies = scanInput.packages.filter(p => directDependencyNames?.has(p.name));
97
99
  maintenanceFindings = await detectDM001(sorted, directDependencies, offline);
98
100
  }
101
+ let licenseFindings = [];
102
+ let licenseLimitedToDirectOnly = false;
103
+ if (params.options.checkLicenses && !params.options.ratchet) {
104
+ const directDeps = scanInput.packages.filter(p => directDependencyNames?.has(p.name));
105
+ const isNpm = scanInput.source === "package-lock" || scanInput.source === "npm-shrinkwrap";
106
+ const licenseResult = await detectLicenseIssues({
107
+ lockfilePath: scanInput.filePath,
108
+ directDeps,
109
+ isNpm,
110
+ isOffline: offline,
111
+ });
112
+ licenseFindings = licenseResult.findings;
113
+ licenseLimitedToDirectOnly = licenseResult.limitedToDirectOnly;
114
+ }
99
115
  results.push({
100
116
  subfolder,
101
117
  scanInput,
@@ -108,6 +124,8 @@ export async function runMultiFolderScan(params) {
108
124
  completeness,
109
125
  overrideFindings,
110
126
  maintenanceFindings,
127
+ licenseFindings,
128
+ licenseLimitedToDirectOnly,
111
129
  suppressedCount,
112
130
  });
113
131
  }
@@ -229,19 +247,19 @@ export async function handleMultiFolderScan(params) {
229
247
  if (params.options.ratchet) {
230
248
  return handleMultiFolderRatchet(results, params.projectRoot, params.options);
231
249
  }
250
+ const aggregatedCompleteness = aggregateMultiFolderCompleteness(results);
232
251
  if (params.options.json) {
233
252
  // Match single-folder writeOutputs: timestamped file in cwd, not stdout dump.
234
253
  // Help text and CI both treat --json as "save a JSON file".
235
254
  const allFindings = results.flatMap(r => r.sorted.map(f => ({ ...serializeFinding(f, r.suggestedFixCommands), subfolder: r.subfolder })));
236
- const completeness = aggregateMultiFolderCompleteness(results);
237
255
  const payload = {
238
256
  multiFolder: true,
239
257
  projectPath: params.projectRoot,
240
258
  folders: results.map(r => r.subfolder),
241
259
  findingCount: allFindings.length,
242
- status: completeness.complete ? "ok" : "partial",
243
- complete: completeness.complete,
244
- diagnostics: completeness.diagnostics,
260
+ status: aggregatedCompleteness.complete ? "ok" : "partial",
261
+ complete: aggregatedCompleteness.complete,
262
+ diagnostics: aggregatedCompleteness.diagnostics,
245
263
  findings: allFindings,
246
264
  ...(params.options.checkOverrides
247
265
  ? {
@@ -253,6 +271,11 @@ export async function handleMultiFolderScan(params) {
253
271
  maintenanceFindings: results.flatMap(r => r.maintenanceFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
254
272
  }
255
273
  : {}),
274
+ ...(params.options.checkLicenses
275
+ ? {
276
+ licenseFindings: results.flatMap(r => r.licenseFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
277
+ }
278
+ : {}),
256
279
  scannedAt: new Date().toISOString(),
257
280
  };
258
281
  const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
@@ -277,6 +300,12 @@ export async function handleMultiFolderScan(params) {
277
300
  console.log(renderMaintenanceFindings(r.maintenanceFindings, { verbose: !!params.options.verbose }));
278
301
  }
279
302
  }
303
+ if (params.options.checkLicenses) {
304
+ for (const r of results) {
305
+ process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray("license issues")}\n`);
306
+ console.log(renderLicenseFindings(r.licenseFindings, { limitedToDirectOnly: r.licenseLimitedToDirectOnly }));
307
+ }
308
+ }
280
309
  if (!params.options.checkOverrides && !params.options.ratchet) {
281
310
  for (const r of results) {
282
311
  const subfolderPath = path.join(params.projectRoot, r.subfolder);
@@ -300,6 +329,7 @@ export async function handleMultiFolderScan(params) {
300
329
  // flag so empty panels render when the check ran with no hits.
301
330
  includeOverrides: !!params.options.checkOverrides,
302
331
  includeMaintenance: !!params.options.checkMaintenance,
332
+ includeLicenses: !!params.options.checkLicenses,
303
333
  });
304
334
  console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
305
335
  }
@@ -313,7 +343,12 @@ export async function handleMultiFolderScan(params) {
313
343
  const shouldFail = allSorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]) ||
314
344
  reachesFailOn(allOverrideFindings, params.options.failOn) ||
315
345
  reachesFailOn(allMaintenanceFindings, params.options.failOn);
316
- const exitCode = shouldFail ? EXIT_FINDINGS : EXIT_OK;
346
+ const incompleteFailure = shouldFailForIncompleteScan(aggregatedCompleteness, params.options.incompletePolicy);
347
+ const exitCode = incompleteFailure
348
+ ? EXIT_ERROR
349
+ : shouldFail
350
+ ? EXIT_FINDINGS
351
+ : EXIT_OK;
317
352
  auditLog.emit({
318
353
  ts: new Date(scanFinishedAt).toISOString(),
319
354
  type: "scan.finished",
package/dist/scanner.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { fetchEpssScores } from "./epss/client.js";
1
2
  import { chunk, runWithConcurrency } from "./utils/array.js";
2
3
  import { isPrivateRegistrySource, isGitSource, hasCommitShaPinning } from "./utils/advisory.js";
3
4
  import { extractCveAliases, hasMaliciousAdvisory } from "./utils/vuln.js";
@@ -7,6 +8,7 @@ import { maxSeverity } from "./osv/severity.js";
7
8
  import { createSpinner } from "./output/spinner.js";
8
9
  import { OsvAdvisorySource } from "./advisory/osv-advisory-source.js";
9
10
  import { LocalAdvisorySource } from "./advisory/local-advisory-source.js";
11
+ import { queryNpmAdvisoryGaps } from "./advisory/npm-advisory-source.js";
10
12
  import { LocalAdvisoryDatabase } from "./advisory/local-db.js";
11
13
  import { ADVISORY_DB_STALE_AFTER_MS, getDefaultAdvisoryDbPath } from "./advisory/osv-sync.js";
12
14
  import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js";
@@ -41,7 +43,7 @@ export function createAdvisorySource(options) {
41
43
  offline: false,
42
44
  sourceLabel: options?.osvUrl
43
45
  ? `custom OSV endpoint (${options.osvUrl})`
44
- : "OSV (https://api.osv.dev)",
46
+ : "OSV + npm registry advisory (https://api.osv.dev)",
45
47
  advisoryDbMetadata: null,
46
48
  advisoryDbIsStale: false,
47
49
  cleanup: () => { },
@@ -162,8 +164,56 @@ export async function scanPackages(packages, batchSize, options, context, debugL
162
164
  }
163
165
  spinner.succeed("Loaded package matches from the local advisory database");
164
166
  }
165
- const idSet = new Set(results.flatMap(r => r.vulnIds));
166
167
  const vulnMap = new Map();
168
+ // npm advisory supplemental pass: query all npm packages and surface vulns that OSV missed
169
+ const existingVulnIds = new Set(results.flatMap(r => r.vulnIds));
170
+ const allNpmPkgs = packages.filter(pkg => pkg.ecosystem === "npm");
171
+ let wroteNpmAdvisoryEntries = false;
172
+ if (allNpmPkgs.length > 0 && !offline) {
173
+ const nowMs = Date.now();
174
+ const cachedAt = new Date(nowMs).toISOString();
175
+ const uncachedForNpm = [];
176
+ for (const pkg of allNpmPkgs) {
177
+ const key = getPackageCacheKey(pkg);
178
+ const cached = cache.npmAdvisoryEntries[key];
179
+ if (cached && !isEntryStale(cached, nowMs)) {
180
+ const newCachedVulnIds = cached.vulnIds.filter(id => !existingVulnIds.has(id));
181
+ if (newCachedVulnIds.length > 0) {
182
+ results.push({ pkg, vulnIds: newCachedVulnIds });
183
+ }
184
+ }
185
+ else {
186
+ uncachedForNpm.push(pkg);
187
+ }
188
+ }
189
+ if (uncachedForNpm.length > 0) {
190
+ const npmResults = await queryNpmAdvisoryGaps(uncachedForNpm, {
191
+ fetchImpl,
192
+ offline,
193
+ debugLog: log,
194
+ });
195
+ for (const pkg of uncachedForNpm) {
196
+ const found = npmResults.find(r => r.pkg.name === pkg.name && r.pkg.version === pkg.version);
197
+ const vulns = found?.vulns ?? [];
198
+ const vulnIds = vulns.map(v => v.id);
199
+ // Store the full list in cache (for cache correctness on future scans),
200
+ // but only add genuinely new vulns to results - ones OSV did not already surface
201
+ cache.npmAdvisoryEntries[getPackageCacheKey(pkg)] = { vulnIds, cachedAt };
202
+ const newVulns = vulns.filter(v => !existingVulnIds.has(v.id));
203
+ const newVulnIds = newVulns.map(v => v.id);
204
+ if (newVulns.length > 0) {
205
+ results.push({ pkg, vulnIds: newVulnIds });
206
+ for (const vuln of newVulns) {
207
+ vulnMap.set(vuln.id, vuln);
208
+ }
209
+ }
210
+ }
211
+ // Persist npm advisory cache entries for clean projects that won't trigger
212
+ // the idSet.size > 0 saveCache path below
213
+ wroteNpmAdvisoryEntries = true;
214
+ }
215
+ }
216
+ const idSet = new Set(results.flatMap(r => r.vulnIds));
167
217
  const transientDetailIds = new Set();
168
218
  const offlineMissingDetailIds = new Set();
169
219
  const confirmedMissingDetailIds = new Set();
@@ -186,7 +236,9 @@ export async function scanPackages(packages, batchSize, options, context, debugL
186
236
  }
187
237
  }
188
238
  else {
189
- uncachedIds.push(id);
239
+ if (!vulnMap.has(id)) {
240
+ uncachedIds.push(id);
241
+ }
190
242
  }
191
243
  }
192
244
  if (uncachedIds.length > 0) {
@@ -255,7 +307,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
255
307
  throw error;
256
308
  }
257
309
  }
258
- if (!offline && idSet.size > 0) {
310
+ if (!offline && (idSet.size > 0 || wroteNpmAdvisoryEntries)) {
259
311
  saveCache(cache, cacheDirOverride, options.debug ? log : undefined);
260
312
  }
261
313
  const findings = results.map(result => {
@@ -267,7 +319,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
267
319
  const cveAliases = extractCveAliases(vulnerabilities);
268
320
  const dependencyPaths = result.pkg.paths ?? [];
269
321
  const relationship = classifyRelationship(dependencyPaths, result.pkg.name, context?.directDependencyNames);
270
- const firstFixedVersion = findFirstFixedVersion(vulnerabilities);
322
+ const firstFixedVersion = findFirstFixedVersion(vulnerabilities, result.pkg.name, result.pkg.ecosystem);
271
323
  return {
272
324
  pkg: result.pkg,
273
325
  vulnerabilities,
@@ -576,6 +628,9 @@ export async function scanPackages(packages, batchSize, options, context, debugL
576
628
  complete: diagnostics.length === 0,
577
629
  diagnostics,
578
630
  };
631
+ if (!offline) {
632
+ await enrichWithEpssScores(findings, fetchImpl);
633
+ }
579
634
  return { findings, completeness };
580
635
  }
581
636
  catch (error) {
@@ -727,10 +782,34 @@ function classifyRelationship(paths, packageName, directDependencyNames) {
727
782
  return "direct";
728
783
  return "transitive";
729
784
  }
730
- function findFirstFixedVersion(vulns) {
785
+ /**
786
+ * Does this `affected[]` entry describe the package being scanned?
787
+ *
788
+ * Permissive by design, matching `resolveLowestKnownNonVulnerableVersion` in
789
+ * remediation/npm-registry.ts: an entry is excluded only when it positively
790
+ * identifies a *different* package. An entry that omits the name (or the
791
+ * ecosystem) is kept, so an advisory with sparse metadata still contributes
792
+ * its fix rather than silently dropping to "no fix known".
793
+ */
794
+ function affectedEntryMatchesPackage(affected, packageName, ecosystem) {
795
+ const affectedName = affected.package?.name;
796
+ if (affectedName && affectedName !== packageName)
797
+ return false;
798
+ const affectedEcosystem = affected.package?.ecosystem?.toLowerCase();
799
+ if (affectedEcosystem && affectedEcosystem !== ecosystem.toLowerCase())
800
+ return false;
801
+ return true;
802
+ }
803
+ export function findFirstFixedVersion(vulns, packageName, ecosystem) {
731
804
  const fixedVersions = [];
732
805
  for (const vuln of vulns) {
733
806
  for (const affected of vuln.affected ?? []) {
807
+ // An advisory may list several packages with different fix versions.
808
+ // Without this filter the global minimum across all of them was
809
+ // returned, so a package inherited another package's (lower) fix and
810
+ // the scan reported a version that does not fix it.
811
+ if (!affectedEntryMatchesPackage(affected, packageName, ecosystem))
812
+ continue;
734
813
  for (const range of affected.ranges ?? []) {
735
814
  for (const event of range.events ?? []) {
736
815
  const fixed = event.fixed;
@@ -768,6 +847,22 @@ function buildCompletenessDiagnostics(params) {
768
847
  addDiagnostic("CHAIN_RESOLUTION_FAILURE", params.chainResolutionFailureCount, "remediation");
769
848
  return diagnostics;
770
849
  }
850
+ async function enrichWithEpssScores(findings, fetchImpl) {
851
+ const allCves = [...new Set(findings.flatMap(f => f.cveAliases))];
852
+ if (allCves.length === 0)
853
+ return;
854
+ const epssMap = await fetchEpssScores(allCves, fetchImpl);
855
+ if (epssMap.size === 0)
856
+ return;
857
+ for (const finding of findings) {
858
+ const scores = finding.cveAliases.flatMap(cve => {
859
+ const score = epssMap.get(cve.toUpperCase());
860
+ return score ? [score] : [];
861
+ });
862
+ if (scores.length > 0)
863
+ finding.epssScores = scores;
864
+ }
865
+ }
771
866
  export function buildCoverageNotes(scanInput, offline) {
772
867
  const notes = [
773
868
  "CVE Lite CLI checks package versions against OSV advisories. It does not prove exploitability or runtime reachability.",
@@ -3,6 +3,8 @@ import { severityOrder } from "../constants.js";
3
3
  import { normalizeSeverity } from "../osv/severity.js";
4
4
  export const SEVERITY_ORDER = ["critical", "high", "medium", "low", "unknown", "none"];
5
5
  export function reachesFailOn(findings, failOn) {
6
+ if (!failOn)
7
+ return false;
6
8
  const failLevel = normalizeSeverity(failOn);
7
9
  return findings.some((f) => severityOrder[f.severity] >= severityOrder[failLevel]);
8
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.30.0",
3
+ "version": "1.32.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": {