cve-lite-cli 1.31.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.
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 => {
@@ -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) {
@@ -792,6 +847,22 @@ function buildCompletenessDiagnostics(params) {
792
847
  addDiagnostic("CHAIN_RESOLUTION_FAILURE", params.chainResolutionFailureCount, "remediation");
793
848
  return diagnostics;
794
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
+ }
795
866
  export function buildCoverageNotes(scanInput, offline) {
796
867
  const notes = [
797
868
  "CVE Lite CLI checks package versions against OSV advisories. It does not prove exploitability or runtime reachability.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cve-lite-cli",
3
- "version": "1.31.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": {