cve-lite-cli 1.26.0 → 1.28.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 (43) hide show
  1. package/README.md +147 -398
  2. package/dist/advisory/osv-advisory-source.js +5 -3
  3. package/dist/cli/advisories-init.js +24 -0
  4. package/dist/cli/args.js +36 -0
  5. package/dist/cli/help.js +9 -5
  6. package/dist/cli/overrides.js +20 -16
  7. package/dist/constants.js +1 -0
  8. package/dist/index.js +61 -39
  9. package/dist/maintenance/dm001-maintenance-risk.js +63 -0
  10. package/dist/maintenance/types.js +1 -0
  11. package/dist/osv/cache.js +49 -50
  12. package/dist/output/debug.js +2 -1
  13. package/dist/output/formatters.js +17 -3
  14. package/dist/output/html-reporter.js +156 -102
  15. package/dist/output/logos.js +1 -1
  16. package/dist/output/maintenance-findings-html.js +56 -0
  17. package/dist/output/maintenance-findings-json.js +3 -0
  18. package/dist/output/maintenance-terminal.js +80 -0
  19. package/dist/output/override-findings-html.js +24 -28
  20. package/dist/output/override-findings-sarif.js +34 -24
  21. package/dist/output/override-findings-terminal.js +19 -2
  22. package/dist/output/printers.js +19 -6
  23. package/dist/output/sarif.js +14 -6
  24. package/dist/output/spinner.js +5 -0
  25. package/dist/output/write-outputs.js +3 -1
  26. package/dist/overrides/context-builder.js +29 -0
  27. package/dist/overrides/detectors/index.js +6 -0
  28. package/dist/overrides/detectors/oa009-stale-floor.js +80 -0
  29. package/dist/overrides/detectors/pd001-override-only-phantom.js +32 -0
  30. package/dist/overrides/detectors/pd002-transitive-only-phantom.js +34 -0
  31. package/dist/overrides/detectors/phantom-utils.js +21 -0
  32. package/dist/overrides/fixer.js +21 -1
  33. package/dist/remediation/cooldown.js +74 -0
  34. package/dist/remediation/fix-commands.js +42 -2
  35. package/dist/remediation/npm-registry.js +11 -0
  36. package/dist/remediation/parent-upgrade.js +114 -18
  37. package/dist/scan/multi-folder-scan.js +35 -10
  38. package/dist/scanner.js +86 -22
  39. package/dist/usage/scanner.js +60 -1
  40. package/dist/utils/network.js +77 -0
  41. package/dist/utils/sarif.js +4 -0
  42. package/dist/utils/severity.js +6 -0
  43. package/package.json +2 -1
package/dist/osv/cache.js CHANGED
@@ -1,8 +1,30 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import os from "node:os";
4
+ import { CACHE_TTL_MS } from "../constants.js";
4
5
  function createEmptyCache() {
5
- return { version: 3, createdAt: new Date().toISOString(), entries: {}, queryEntries: {}, npmVersionEntries: {} };
6
+ return { version: 4, createdAt: new Date().toISOString(), entries: {}, queryEntries: {}, npmVersionEntries: {} };
7
+ }
8
+ // v4 stores detail records as { vuln, cachedAt }. v1-v3 stored the OsvVuln (or
9
+ // null for a known-empty lookup) directly, with no timestamp. Legacy records are
10
+ // wrapped with an epoch-0 cachedAt so they read as stale and get refreshed on the
11
+ // next scan, matching how the queryEntries v2->v3 migration backdates its records.
12
+ function wrapLegacyDetailEntries(raw) {
13
+ const epoch = new Date(0).toISOString();
14
+ const entries = {};
15
+ for (const [id, value] of Object.entries(raw ?? {})) {
16
+ entries[id] = { vuln: value ?? null, cachedAt: epoch };
17
+ }
18
+ return entries;
19
+ }
20
+ function readDetailEntries(raw) {
21
+ const entries = {};
22
+ for (const [id, value] of Object.entries(raw ?? {})) {
23
+ if (value && typeof value === "object" && "vuln" in value && "cachedAt" in value) {
24
+ entries[id] = value;
25
+ }
26
+ }
27
+ return entries;
6
28
  }
7
29
  export function getCacheFilePath(cacheDirOverride) {
8
30
  const baseDir = cacheDirOverride
@@ -12,7 +34,7 @@ export function getCacheFilePath(cacheDirOverride) {
12
34
  return path.join(baseDir, "osv-vulns.json");
13
35
  }
14
36
  export function isEntryStale(entry, nowMs) {
15
- return nowMs - new Date(entry.cachedAt).getTime() > 30 * 60 * 1000;
37
+ return nowMs - new Date(entry.cachedAt).getTime() > CACHE_TTL_MS;
16
38
  }
17
39
  export function loadCache(cacheDirOverride, debugLog) {
18
40
  const filePath = getCacheFilePath(cacheDirOverride);
@@ -31,64 +53,40 @@ export function loadCache(cacheDirOverride, debugLog) {
31
53
  debugLog?.("Cache load failed", { path: filePath, reason: "invalid root object" });
32
54
  return createEmptyCache();
33
55
  }
34
- const entries = (parsed.entries && typeof parsed.entries === "object")
35
- ? parsed.entries
36
- : {};
37
- // v2: queryEntries values are string[] — migrate to { vulnIds, cachedAt: epoch }
38
- if (parsed.version === 2) {
56
+ const version = parsed.version;
57
+ const rawEntries = parsed.entries;
58
+ // Detail records: v4 already carries { vuln, cachedAt }; v1-v3 stored the record
59
+ // directly and are wrapped (and backdated) so the TTL applies uniformly.
60
+ const entries = version === 4 ? readDetailEntries(rawEntries) : wrapLegacyDetailEntries(rawEntries);
61
+ // Query records: v2 stored string[]; v3 and v4 store { vulnIds, cachedAt }; v1/unknown had none.
62
+ const queryEntries = {};
63
+ if (version === 2) {
39
64
  const rawQuery = parsed.queryEntries;
40
- const queryEntries = {};
65
+ const epoch = new Date(0).toISOString();
41
66
  for (const [key, vulnIds] of Object.entries(rawQuery ?? {})) {
42
- queryEntries[key] = { vulnIds: Array.isArray(vulnIds) ? vulnIds : [], cachedAt: new Date(0).toISOString() };
67
+ queryEntries[key] = { vulnIds: Array.isArray(vulnIds) ? vulnIds : [], cachedAt: epoch };
43
68
  }
44
- const migrated = {
45
- version: 3,
46
- createdAt: String(parsed.createdAt ?? new Date().toISOString()),
47
- entries,
48
- queryEntries,
49
- npmVersionEntries: {},
50
- };
51
- debugLog?.("Cache loaded", {
52
- path: filePath,
53
- queryEntries: Object.keys(migrated.queryEntries).length,
54
- detailEntries: Object.keys(migrated.entries).length,
55
- migratedFrom: 2,
56
- });
57
- return migrated;
58
- }
59
- // v1 or unknown: no queryEntries
60
- if (parsed.version !== 3) {
61
- const upgraded = {
62
- version: 3,
63
- createdAt: new Date().toISOString(),
64
- entries,
65
- queryEntries: {},
66
- npmVersionEntries: {},
67
- };
68
- debugLog?.("Cache loaded", {
69
- path: filePath,
70
- queryEntries: 0,
71
- detailEntries: Object.keys(upgraded.entries).length,
72
- migratedFrom: parsed.version ?? "unknown",
73
- });
74
- return upgraded;
75
69
  }
76
- const rawQuery = parsed.queryEntries;
77
- const queryEntries = {};
78
- for (const [key, value] of Object.entries(rawQuery ?? {})) {
79
- if (value && typeof value === "object" && "vulnIds" in value && "cachedAt" in value) {
80
- queryEntries[key] = value;
70
+ else if (version === 3 || version === 4) {
71
+ const rawQuery = parsed.queryEntries;
72
+ for (const [key, value] of Object.entries(rawQuery ?? {})) {
73
+ if (value && typeof value === "object" && "vulnIds" in value && "cachedAt" in value) {
74
+ queryEntries[key] = value;
75
+ }
81
76
  }
82
77
  }
83
- const rawNpmVersions = parsed.npmVersionEntries;
78
+ // npm publish-date records exist from v3 onward.
84
79
  const npmVersionEntries = {};
85
- for (const [key, value] of Object.entries(rawNpmVersions ?? {})) {
86
- if (value && typeof value === "object" && "publishedAt" in value && "cachedAt" in value) {
87
- npmVersionEntries[key] = value;
80
+ if (version === 3 || version === 4) {
81
+ const rawNpmVersions = parsed.npmVersionEntries;
82
+ for (const [key, value] of Object.entries(rawNpmVersions ?? {})) {
83
+ if (value && typeof value === "object" && "publishedAt" in value && "cachedAt" in value) {
84
+ npmVersionEntries[key] = value;
85
+ }
88
86
  }
89
87
  }
90
88
  const loaded = {
91
- version: 3,
89
+ version: 4,
92
90
  createdAt: String(parsed.createdAt ?? new Date().toISOString()),
93
91
  entries,
94
92
  queryEntries,
@@ -98,6 +96,7 @@ export function loadCache(cacheDirOverride, debugLog) {
98
96
  path: filePath,
99
97
  queryEntries: Object.keys(loaded.queryEntries).length,
100
98
  detailEntries: Object.keys(loaded.entries).length,
99
+ ...(version === 4 ? {} : { migratedFrom: version ?? "unknown" }),
101
100
  });
102
101
  return loaded;
103
102
  }
@@ -5,6 +5,7 @@ export function createDebugLogger(enabled) {
5
5
  return {
6
6
  log: () => { },
7
7
  announcePath: () => { },
8
+ close: () => { },
8
9
  };
9
10
  }
10
11
  const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
@@ -24,7 +25,7 @@ export function createDebugLogger(enabled) {
24
25
  announced = true;
25
26
  console.error(`[debug] Writing debug log to ./${filename}`);
26
27
  };
27
- return { log, announcePath };
28
+ return { log, announcePath, close: () => { } };
28
29
  }
29
30
  function formatJson(details) {
30
31
  if (typeof details === "string")
@@ -1,4 +1,4 @@
1
- import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
1
+ import { findFixTargetForFinding, findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
2
2
  import { chalk } from "../utils/chalk.js";
3
3
  import { severityOrder, MAL_PRIVATE_REGISTRY_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, } from "../constants.js";
4
4
  import { loadCache } from "../osv/cache.js";
@@ -24,6 +24,15 @@ export function formatAdvisorySourceLine(sourceLabel) {
24
24
  }
25
25
  return `${match[1]} (${chalk.cyan(match[2])})`;
26
26
  }
27
+ export function formatHintLines(lines) {
28
+ if (lines.length === 0)
29
+ return [];
30
+ const [first, ...rest] = lines;
31
+ return [
32
+ chalk.yellow(first),
33
+ ...rest.map(line => chalk.gray(line)),
34
+ ];
35
+ }
27
36
  // MAL-* is the OSV prefix for malicious code advisories
28
37
  function isMaliciousAdvisory(finding) {
29
38
  return finding.vulnerabilities.some(v => v.id.startsWith("MAL-"));
@@ -182,6 +191,9 @@ export function summarizeNextAction(finding) {
182
191
  export function formatFixVersionPublishDate(iso) {
183
192
  return iso.slice(0, 10);
184
193
  }
194
+ export function formatCooldownWarning(warning) {
195
+ return `Published ${formatFixVersionPublishDate(warning.publishedAt)}, newer than your configured ${warning.windowLabel} release cooldown (${warning.sourceFile}); your package manager would hold this version - validate before overriding.`;
196
+ }
185
197
  export function formatFixCommandPublishSuffix(targets) {
186
198
  const dated = targets.filter(target => target.kind === "direct" && target.fixVersionPublishedAt);
187
199
  if (dated.length === 0)
@@ -207,6 +219,7 @@ export function serializeFinding(finding, plan) {
207
219
  validatedFirstFixedVersion: finding.validatedFirstFixedVersion ?? null,
208
220
  fixVersionValidationNote: finding.fixVersionValidationNote ?? null,
209
221
  fixVersionPublishedAt: finding.fixVersionPublishedAt ?? null,
222
+ cooldownWarning: plan ? (findFixTargetForFinding(plan, finding)?.cooldownWarning ?? null) : null,
210
223
  validatedTargetScannedVersions: finding.validatedTargetScannedVersions ?? null,
211
224
  validatedTargetKnownVulnerableVersions: finding.validatedTargetKnownVulnerableVersions ?? null,
212
225
  recommendedAction: getRecommendedAction(finding),
@@ -220,6 +233,7 @@ export function serializeFinding(finding, plan) {
220
233
  maliciousUnverifiable: finding.maliciousUnverifiable ?? false,
221
234
  maliciousGitSource: finding.maliciousGitSource ?? false,
222
235
  maliciousGitSourcePinned: finding.maliciousGitSourcePinned ?? false,
236
+ unresolvedAdvisoryIds: finding.unresolvedAdvisoryIds ?? [],
223
237
  vulnerabilities: finding.vulnerabilities.map(v => ({
224
238
  id: v.id,
225
239
  aliases: v.aliases ?? [],
@@ -232,8 +246,8 @@ export function printCacheSummary(cacheDirOverride, options) {
232
246
  if (options?.json)
233
247
  return;
234
248
  const cache = loadCache(cacheDirOverride);
235
- const advisoryCount = Object.entries(cache.entries).filter(([, value]) => Boolean(value)).length;
236
- const emptyCount = Object.entries(cache.entries).filter(([, value]) => value === null).length;
249
+ const advisoryCount = Object.values(cache.entries).filter(entry => entry.vuln).length;
250
+ const emptyCount = Object.values(cache.entries).filter(entry => entry.vuln === null).length;
237
251
  const packageQueryCount = Object.keys(cache.queryEntries).length;
238
252
  const totalCount = advisoryCount + emptyCount;
239
253
  if (totalCount === 0 && packageQueryCount === 0)