cve-lite-cli 1.24.0 → 1.26.0-beta.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.
Files changed (77) hide show
  1. package/README.md +83 -2
  2. package/assets/OWASP_Logo_Black_TM.png +0 -0
  3. package/assets/logo-with-title-removebg-preview.png +0 -0
  4. package/dist/advisory/local-db.js +7 -1
  5. package/dist/advisory/osv-advisory-source.js +2 -1
  6. package/dist/audit-log/events.js +3 -0
  7. package/dist/audit-log/handle.js +20 -0
  8. package/dist/audit-log/index.js +16 -0
  9. package/dist/audit-log/ndjson-writer.js +28 -0
  10. package/dist/cli/args.js +75 -0
  11. package/dist/cli/fix-overrides-hook.js +64 -0
  12. package/dist/cli/help.js +24 -1
  13. package/dist/cli/overrides.js +67 -0
  14. package/dist/cli/validate.js +9 -1
  15. package/dist/index.js +310 -21
  16. package/dist/osv/cache.js +28 -4
  17. package/dist/output/formatters.js +22 -18
  18. package/dist/output/html-reporter.js +37 -8
  19. package/dist/output/logos.js +18 -0
  20. package/dist/output/multi-folder-html-reporter.js +3 -4
  21. package/dist/output/override-findings-html.js +63 -0
  22. package/dist/output/override-findings-json.js +3 -0
  23. package/dist/output/override-findings-sarif.js +52 -0
  24. package/dist/output/override-findings-terminal.js +106 -0
  25. package/dist/output/printers.js +66 -23
  26. package/dist/output/sarif.js +77 -8
  27. package/dist/output/write-outputs.js +7 -3
  28. package/dist/overrides/api.js +79 -0
  29. package/dist/overrides/composite.js +23 -0
  30. package/dist/overrides/context-builder.js +150 -0
  31. package/dist/overrides/context.js +3 -0
  32. package/dist/overrides/detectors/index.js +23 -0
  33. package/dist/overrides/detectors/oa001-orphaned-target.js +36 -0
  34. package/dist/overrides/detectors/oa002-floating-tag.js +40 -0
  35. package/dist/overrides/detectors/oa003-wrong-section.js +48 -0
  36. package/dist/overrides/detectors/oa004-surpassed-pin.js +49 -0
  37. package/dist/overrides/detectors/oa005-nested-ineffective.js +128 -0
  38. package/dist/overrides/detectors/oa006-coupled-platform-binary.js +170 -0
  39. package/dist/overrides/detectors/oa007-frozen-latest.js +69 -0
  40. package/dist/overrides/detectors/oa008-materialized.js +75 -0
  41. package/dist/overrides/detectors/platform-binary.js +37 -0
  42. package/dist/overrides/fixer.js +199 -0
  43. package/dist/overrides/index.js +5 -0
  44. package/dist/overrides/parsing/installed-tree.js +164 -0
  45. package/dist/overrides/parsing/json-pointer.js +8 -0
  46. package/dist/overrides/parsing/node-modules.js +19 -0
  47. package/dist/overrides/parsing/package-json.js +139 -0
  48. package/dist/overrides/parsing/registry.js +66 -0
  49. package/dist/overrides/types.js +2 -0
  50. package/dist/parsers/pnpm-lock.js +46 -3
  51. package/dist/parsers/yarn-lock.js +2 -2
  52. package/dist/remediation/fix-commands.js +59 -5
  53. package/dist/remediation/npm-registry.js +55 -43
  54. package/dist/remediation/npm-transitive-resolution.js +2 -2
  55. package/dist/remediation/transitive-chain-resolver.js +100 -0
  56. package/dist/scan/multi-folder-scan.js +37 -1
  57. package/dist/scanner.js +122 -46
  58. package/dist/types.js +13 -1
  59. package/dist/utils/baseline.js +16 -0
  60. package/dist/utils/create-pr.js +19 -4
  61. package/dist/utils/fix-runner.js +6 -0
  62. package/dist/utils/package-json.js +21 -0
  63. package/dist/utils/severity.js +16 -0
  64. package/dist/utils/string.js +34 -0
  65. package/dist/utils/validate-url.js +223 -0
  66. package/dist/utils/version.js +135 -2
  67. package/package.json +8 -2
  68. package/dist/learn/keypress.js +0 -50
  69. package/dist/learn/runner.js +0 -96
  70. package/dist/learn/scenario.js +0 -47
  71. package/dist/learn/session.js +0 -36
  72. package/dist/learn/types.js +0 -1
  73. package/dist/llm/client.js +0 -40
  74. package/dist/llm/config.js +0 -48
  75. package/dist/llm/explainer.js +0 -31
  76. package/dist/output/logo-base64.js +0 -1
  77. package/dist/output/owasp-logo-base64.js +0 -1
@@ -120,6 +120,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
120
120
  usage: finding.usage ?? null,
121
121
  workspaces: pkgWorkspaces.length > 0 ? pkgWorkspaces : undefined,
122
122
  isDev: finding.pkg.dev ?? false,
123
+ fixVersionPublishedAt: finding.fixVersionPublishedAt ?? null,
123
124
  });
124
125
  }
125
126
  else if (finding.fixVersionValidationNote) {
@@ -166,7 +167,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
166
167
  package: finding.recommendedNpmTransitiveRemediation.package,
167
168
  currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
168
169
  targetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
169
- displayTargetVersion: "lockfile refresh",
170
+ displayTargetVersion: "npm install",
170
171
  scannedVersions: null,
171
172
  knownVulnerableVersions: null,
172
173
  kind: "parent-update",
@@ -187,6 +188,9 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
187
188
  finding.recommendedNpmTransitiveRemediation.targetVersion &&
188
189
  isUpgradeTarget(finding.recommendedNpmTransitiveRemediation.currentVersion, finding.recommendedNpmTransitiveRemediation.targetVersion)) {
189
190
  const coverage = calculatePathCoverage(finding.dependencyPaths, finding.recommendedNpmTransitiveRemediation.viaPath);
191
+ const chainForNpmRemediation = finding.chainResolution?.directDep === finding.recommendedNpmTransitiveRemediation.package
192
+ ? finding.chainResolution
193
+ : null;
190
194
  upsertTarget(targetsByPackage, {
191
195
  package: finding.recommendedNpmTransitiveRemediation.package,
192
196
  currentVersion: finding.recommendedNpmTransitiveRemediation.currentVersion,
@@ -204,6 +208,9 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
204
208
  remainingPaths: coverage.remainingPaths,
205
209
  usage: finding.usage ?? null,
206
210
  isDev: devLookup.get(`${finding.recommendedNpmTransitiveRemediation.package}@${finding.recommendedNpmTransitiveRemediation.currentVersion}`) ?? false,
211
+ chainProof: chainForNpmRemediation?.chain,
212
+ chainSafeVersion: chainForNpmRemediation?.safeVersion,
213
+ chainVulnerablePackage: chainForNpmRemediation ? finding.pkg.name : undefined,
207
214
  });
208
215
  continue;
209
216
  }
@@ -211,6 +218,9 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
211
218
  finding.recommendedParentUpgrade &&
212
219
  isUpgradeTarget(finding.recommendedParentUpgrade.currentVersion, finding.recommendedParentUpgrade.targetVersion)) {
213
220
  const coverage = calculatePathCoverage(finding.dependencyPaths, finding.recommendedParentUpgrade.viaPath);
221
+ const chainForParentUpgrade = finding.chainResolution?.directDep === finding.recommendedParentUpgrade.package
222
+ ? finding.chainResolution
223
+ : null;
214
224
  upsertTarget(targetsByPackage, {
215
225
  package: finding.recommendedParentUpgrade.package,
216
226
  currentVersion: finding.recommendedParentUpgrade.currentVersion,
@@ -228,6 +238,9 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
228
238
  remainingPaths: coverage.remainingPaths,
229
239
  usage: finding.usage ?? null,
230
240
  isDev: devLookup.get(`${finding.recommendedParentUpgrade.package}@${finding.recommendedParentUpgrade.currentVersion}`) ?? false,
241
+ chainProof: chainForParentUpgrade?.chain,
242
+ chainSafeVersion: chainForParentUpgrade?.safeVersion,
243
+ chainVulnerablePackage: chainForParentUpgrade ? finding.pkg.name : undefined,
231
244
  });
232
245
  continue;
233
246
  }
@@ -252,7 +265,6 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
252
265
  package: finding.pkg.name,
253
266
  currentVersion: finding.pkg.version,
254
267
  targetVersion: finding.recommendedNpmTransitiveRemediation.targetChildVersion,
255
- displayTargetVersion: "lockfile refresh",
256
268
  scannedVersions: null,
257
269
  knownVulnerableVersions: null,
258
270
  kind: "parent-update",
@@ -268,9 +280,31 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
268
280
  }
269
281
  const primaryParent = getPrimaryParent(finding);
270
282
  if (finding.relationship === "transitive" && primaryParent) {
283
+ if (finding.chainResolution) {
284
+ const isDev = devLookup.get(`${finding.chainResolution.directDep}@${finding.chainResolution.directDepCurrentVersion}`) ?? false;
285
+ const coverage = calculatePathCoverage(finding.dependencyPaths, [finding.chainResolution.directDep]);
286
+ upsertTarget(targetsByPackage, {
287
+ package: finding.chainResolution.directDep,
288
+ currentVersion: finding.chainResolution.directDepCurrentVersion,
289
+ targetVersion: finding.chainResolution.targetVersion,
290
+ kind: "parent-upgrade",
291
+ urgent,
292
+ severity: finding.severity,
293
+ adjusted: false,
294
+ adjustmentNote: null,
295
+ reason: buildParentUpgradeReason(finding, coverage),
296
+ command: finding.chainResolution.command,
297
+ chainProof: finding.chainResolution.chain,
298
+ chainSafeVersion: finding.chainResolution.safeVersion,
299
+ chainVulnerablePackage: finding.pkg.name,
300
+ usage: finding.usage ?? null,
301
+ isDev,
302
+ });
303
+ continue;
304
+ }
271
305
  const fixHint = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
272
306
  const fixClause = fixHint
273
- ? ` — check for a release that resolves ${finding.pkg.name} to ${fixHint}+`
307
+ ? ` - check for a release that resolves ${finding.pkg.name} to ${fixHint}+`
274
308
  : "";
275
309
  skippedByKey.set(`${finding.relationship}:${finding.pkg.name}@${finding.pkg.version}`, {
276
310
  package: finding.pkg.name,
@@ -359,7 +393,7 @@ function buildPnpmLockfileRefreshCommand(pkg, workspaces) {
359
393
  }
360
394
  return `pnpm -C ${workspace} update --no-save ${pkg}`;
361
395
  }
362
- function commandPrefix(packageManager) {
396
+ export function commandPrefix(packageManager) {
363
397
  if (packageManager === "npm")
364
398
  return "npm install";
365
399
  if (packageManager === "pnpm")
@@ -388,6 +422,10 @@ export function findSuggestedCommandForFinding(plan, finding) {
388
422
  looksLikeVersion(finding.recommendedParentUpgrade.targetVersion) &&
389
423
  compareVersions(item.targetVersion, finding.recommendedParentUpgrade.targetVersion) >= 0);
390
424
  }
425
+ if (finding.chainResolution) {
426
+ return (item.package === finding.chainResolution.directDep &&
427
+ item.targetVersion === finding.chainResolution.targetVersion);
428
+ }
391
429
  const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
392
430
  return item.package === finding.pkg.name && item.targetVersion === directTarget;
393
431
  });
@@ -444,6 +482,9 @@ function upsertTarget(targetsByPackage, next) {
444
482
  coveredPaths: mergePathArrays(existing.coveredPaths ?? [], next.coveredPaths ?? []),
445
483
  remainingPaths: mergePathArrays(existing.remainingPaths ?? [], next.remainingPaths ?? []),
446
484
  usage: existing.usage || next.usage,
485
+ chainProof: existing.chainProof ?? next.chainProof,
486
+ chainSafeVersion: existing.chainSafeVersion ?? next.chainSafeVersion,
487
+ chainVulnerablePackage: existing.chainVulnerablePackage ?? next.chainVulnerablePackage,
447
488
  };
448
489
  if (looksLikeVersion(existing.targetVersion) && looksLikeVersion(next.targetVersion)) {
449
490
  if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
@@ -456,6 +497,7 @@ function upsertTarget(targetsByPackage, next) {
456
497
  }
457
498
  merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
458
499
  merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
500
+ merged.fixVersionPublishedAt = next.fixVersionPublishedAt ?? merged.fixVersionPublishedAt ?? null;
459
501
  }
460
502
  targetsByPackage.set(next.package, merged);
461
503
  return;
@@ -467,6 +509,7 @@ function upsertTarget(targetsByPackage, next) {
467
509
  merged.adjustmentNote = next.adjustmentNote ?? merged.adjustmentNote;
468
510
  merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
469
511
  merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
512
+ merged.fixVersionPublishedAt = next.fixVersionPublishedAt ?? merged.fixVersionPublishedAt ?? null;
470
513
  }
471
514
  targetsByPackage.set(next.package, merged);
472
515
  }
@@ -525,6 +568,11 @@ function buildSections(targets, packageManager) {
525
568
  { kind: "parent-update", severity: "medium" },
526
569
  { kind: "parent-update", severity: "low" },
527
570
  { kind: "parent-update", severity: "unknown" },
571
+ { kind: "validated-chain-upgrade", severity: "critical" },
572
+ { kind: "validated-chain-upgrade", severity: "high" },
573
+ { kind: "validated-chain-upgrade", severity: "medium" },
574
+ { kind: "validated-chain-upgrade", severity: "low" },
575
+ { kind: "validated-chain-upgrade", severity: "unknown" },
528
576
  { kind: "parent-upgrade", severity: "medium" },
529
577
  { kind: "parent-upgrade", severity: "low" },
530
578
  { kind: "parent-upgrade", severity: "unknown" },
@@ -533,7 +581,10 @@ function buildSections(targets, packageManager) {
533
581
  const sectionTargets = targets.filter(target => {
534
582
  const targetKind = target.kind === "parent-update"
535
583
  ? "parent-update"
536
- : target.urgent ? "urgent" : target.adjusted ? "direct-adjusted" : target.kind;
584
+ : target.urgent ? "urgent"
585
+ : target.adjusted ? "direct-adjusted"
586
+ : target.chainProof !== undefined ? "validated-chain-upgrade"
587
+ : target.kind;
537
588
  return targetKind === entry.kind && target.severity === entry.severity;
538
589
  });
539
590
  if (sectionTargets.length === 0)
@@ -567,6 +618,9 @@ function buildSectionTitle(kind, severity) {
567
618
  if (kind === "parent-update") {
568
619
  return `${severityTitle} parent updates within range`;
569
620
  }
621
+ if (kind === "validated-chain-upgrade") {
622
+ return `${severityTitle} validated chain upgrades`;
623
+ }
570
624
  return `${severityTitle} parent upgrades`;
571
625
  }
572
626
  function groupByWorkspaceKey(targets) {
@@ -15,59 +15,60 @@ export function clearPackumentCache() {
15
15
  packumentCache.clear();
16
16
  }
17
17
  export async function fetchPackument(packageName) {
18
- if (packumentCache.has(packageName)) {
19
- return packumentCache.get(packageName) ?? null;
20
- }
21
- const url = `${DEFAULT_NPM_REGISTRY_URL}/${encodeURIComponent(packageName)
22
- .replace(/%40/g, "@")
23
- .replace(/%2F/g, "/")}`;
24
- const batchId = registryDebugLog ? nextRegistryBatchId() : "";
25
- const startedAt = registryDebugLog ? Date.now() : 0;
26
- if (registryDebugLog) {
27
- registryDebugLog("Registry fetch", { batchId, package: packageName, url });
28
- }
29
- try {
30
- const response = await fetch(url);
31
- if (!response.ok) {
18
+ const cached = packumentCache.get(packageName);
19
+ if (cached)
20
+ return cached;
21
+ const promise = (async () => {
22
+ const url = `${DEFAULT_NPM_REGISTRY_URL}/${encodeURIComponent(packageName)
23
+ .replace(/%40/g, "@")
24
+ .replace(/%2F/g, "/")}`;
25
+ const batchId = registryDebugLog ? nextRegistryBatchId() : "";
26
+ const startedAt = registryDebugLog ? Date.now() : 0;
27
+ if (registryDebugLog) {
28
+ registryDebugLog("Registry fetch", { batchId, package: packageName, url });
29
+ }
30
+ try {
31
+ const response = await fetch(url);
32
+ if (!response.ok) {
33
+ if (registryDebugLog) {
34
+ registryDebugLog("Registry response", {
35
+ batchId,
36
+ package: packageName,
37
+ status: response.status,
38
+ durationMs: Date.now() - startedAt,
39
+ versionsCount: 0,
40
+ });
41
+ }
42
+ return null;
43
+ }
44
+ const json = (await response.json());
32
45
  if (registryDebugLog) {
33
46
  registryDebugLog("Registry response", {
34
47
  batchId,
35
48
  package: packageName,
36
49
  status: response.status,
37
50
  durationMs: Date.now() - startedAt,
38
- versionsCount: 0,
51
+ versionsCount: Object.keys(json.versions ?? {}).length,
39
52
  });
40
53
  }
41
- packumentCache.set(packageName, null);
42
- return null;
54
+ return json;
43
55
  }
44
- const json = (await response.json());
45
- if (registryDebugLog) {
46
- registryDebugLog("Registry response", {
47
- batchId,
48
- package: packageName,
49
- status: response.status,
50
- durationMs: Date.now() - startedAt,
51
- versionsCount: Object.keys(json.versions ?? {}).length,
52
- });
53
- }
54
- packumentCache.set(packageName, json);
55
- return json;
56
- }
57
- catch (error) {
58
- if (registryDebugLog) {
59
- registryDebugLog("Registry fetch failed", {
60
- batchId,
61
- package: packageName,
62
- durationMs: Date.now() - startedAt,
63
- error: error instanceof Error
64
- ? { message: error.message, stack: error.stack }
65
- : String(error),
66
- });
56
+ catch (error) {
57
+ if (registryDebugLog) {
58
+ registryDebugLog("Registry fetch failed", {
59
+ batchId,
60
+ package: packageName,
61
+ durationMs: Date.now() - startedAt,
62
+ error: error instanceof Error
63
+ ? { message: error.message, stack: error.stack }
64
+ : String(error),
65
+ });
66
+ }
67
+ return null;
67
68
  }
68
- packumentCache.set(packageName, null);
69
- return null;
70
- }
69
+ })();
70
+ packumentCache.set(packageName, promise);
71
+ return promise;
71
72
  }
72
73
  export async function packageVersionExists(packageName, version) {
73
74
  const packument = await fetchPackument(packageName);
@@ -85,6 +86,7 @@ export async function resolvePublishedFixVersion(packageName, fixedVersionHint)
85
86
  candidatesChecked: 0,
86
87
  candidatesKnownVulnerable: 0,
87
88
  candidatesUnknownCoverage: 0,
89
+ publishedAt: null,
88
90
  };
89
91
  }
90
92
  const publishedVersions = Object.keys(packument.versions ?? {})
@@ -98,6 +100,7 @@ export async function resolvePublishedFixVersion(packageName, fixedVersionHint)
98
100
  candidatesChecked: 0,
99
101
  candidatesKnownVulnerable: 0,
100
102
  candidatesUnknownCoverage: 0,
103
+ publishedAt: packument.time?.[fixedVersionHint] ?? null,
101
104
  };
102
105
  }
103
106
  const nearestPublishedVersion = publishedVersions.find(version => compareVersions(version, fixedVersionHint) >= 0) ?? null;
@@ -109,6 +112,7 @@ export async function resolvePublishedFixVersion(packageName, fixedVersionHint)
109
112
  candidatesChecked: 0,
110
113
  candidatesKnownVulnerable: 0,
111
114
  candidatesUnknownCoverage: 0,
115
+ publishedAt: packument.time?.[nearestPublishedVersion] ?? null,
112
116
  };
113
117
  }
114
118
  return {
@@ -118,6 +122,7 @@ export async function resolvePublishedFixVersion(packageName, fixedVersionHint)
118
122
  candidatesChecked: 0,
119
123
  candidatesKnownVulnerable: 0,
120
124
  candidatesUnknownCoverage: 0,
125
+ publishedAt: null,
121
126
  };
122
127
  }
123
128
  export async function resolveLowestKnownNonVulnerableVersion(packageName, installedVersion, vulnerabilities) {
@@ -129,6 +134,7 @@ export async function resolveLowestKnownNonVulnerableVersion(packageName, instal
129
134
  candidatesChecked: 0,
130
135
  candidatesKnownVulnerable: 0,
131
136
  candidatesUnknownCoverage: 0,
137
+ publishedAt: null,
132
138
  };
133
139
  }
134
140
  if (vulnerabilities.length === 0) {
@@ -139,6 +145,7 @@ export async function resolveLowestKnownNonVulnerableVersion(packageName, instal
139
145
  candidatesChecked: 0,
140
146
  candidatesKnownVulnerable: 0,
141
147
  candidatesUnknownCoverage: 0,
148
+ publishedAt: null,
142
149
  };
143
150
  }
144
151
  const packument = await fetchPackument(packageName);
@@ -150,6 +157,7 @@ export async function resolveLowestKnownNonVulnerableVersion(packageName, instal
150
157
  candidatesChecked: 0,
151
158
  candidatesKnownVulnerable: 0,
152
159
  candidatesUnknownCoverage: 0,
160
+ publishedAt: null,
153
161
  };
154
162
  }
155
163
  const candidates = Object.keys(packument.versions ?? {})
@@ -165,6 +173,7 @@ export async function resolveLowestKnownNonVulnerableVersion(packageName, instal
165
173
  candidatesChecked: 0,
166
174
  candidatesKnownVulnerable: 0,
167
175
  candidatesUnknownCoverage: 0,
176
+ publishedAt: null,
168
177
  };
169
178
  }
170
179
  let candidatesChecked = 0;
@@ -201,6 +210,7 @@ export async function resolveLowestKnownNonVulnerableVersion(packageName, instal
201
210
  candidatesChecked,
202
211
  candidatesKnownVulnerable,
203
212
  candidatesUnknownCoverage,
213
+ publishedAt: packument.time?.[candidate] ?? null,
204
214
  };
205
215
  }
206
216
  if (sawUnknownCoverage) {
@@ -211,6 +221,7 @@ export async function resolveLowestKnownNonVulnerableVersion(packageName, instal
211
221
  candidatesChecked,
212
222
  candidatesKnownVulnerable,
213
223
  candidatesUnknownCoverage,
224
+ publishedAt: null,
214
225
  };
215
226
  }
216
227
  return {
@@ -220,6 +231,7 @@ export async function resolveLowestKnownNonVulnerableVersion(packageName, instal
220
231
  candidatesChecked,
221
232
  candidatesKnownVulnerable,
222
233
  candidatesUnknownCoverage,
234
+ publishedAt: null,
223
235
  };
224
236
  }
225
237
  function isVersionAffectedByVulnerability(packageName, version, vuln) {
@@ -228,11 +228,11 @@ function resolveParentNodeId(args) {
228
228
  }
229
229
  return candidateNodeIds[0] ?? null;
230
230
  }
231
- function highestVersionSatisfyingRange(candidates, rawRange) {
231
+ export function highestVersionSatisfyingRange(candidates, rawRange) {
232
232
  const matches = candidates.filter(candidate => versionSatisfiesRange(candidate, rawRange)).sort(compareVersions);
233
233
  return matches.at(-1) ?? null;
234
234
  }
235
- function versionSatisfiesRange(version, rawRange) {
235
+ export function versionSatisfiesRange(version, rawRange) {
236
236
  const range = rawRange.trim();
237
237
  if (!range)
238
238
  return false;
@@ -0,0 +1,100 @@
1
+ import { commandPrefix } from "./fix-commands.js";
2
+ import { fetchPackument } from "./npm-registry.js";
3
+ import { compareVersions, looksLikeVersion, isPreReleaseVersion } from "../utils/version.js";
4
+ import { versionSatisfiesRange, highestVersionSatisfyingRange } from "./npm-transitive-resolution.js";
5
+ export async function resolveChainFix(finding, installedVersions, packageManager, options) {
6
+ if (options.offline)
7
+ return null;
8
+ if (finding.relationship !== "transitive")
9
+ return null;
10
+ const fixedVersion = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
11
+ if (!fixedVersion)
12
+ return null;
13
+ const uniqueDirectDeps = [...new Set(finding.dependencyPaths
14
+ .filter(path => path.length >= 3)
15
+ .map(path => path[1]))];
16
+ for (const directDepName of uniqueDirectDeps) {
17
+ const directDepCurrentVersion = installedVersions.get(directDepName);
18
+ if (!directDepCurrentVersion)
19
+ continue;
20
+ const packument = await fetchPackument(directDepName);
21
+ if (!packument?.versions)
22
+ continue;
23
+ const candidateVersions = Object.keys(packument.versions)
24
+ .filter(looksLikeVersion)
25
+ .filter(v => !isPreReleaseVersion(v))
26
+ .filter(v => compareVersions(v, directDepCurrentVersion) > 0)
27
+ .sort(compareVersions);
28
+ const pathsForDep = finding.dependencyPaths.filter(p => p[1] === directDepName);
29
+ for (const candidateVersion of candidateVersions) {
30
+ const candidateDeps = packument.versions[candidateVersion]?.dependencies ?? {};
31
+ // hops = everything after the direct dep and before (and including) the vulnerable package
32
+ // For path ["root", "express", "send", "mime-types"]:
33
+ // directDep = path[1] = "express"
34
+ // hops = path.slice(2) = ["send", "mime-types"]
35
+ const hops = pathsForDep[0].slice(2);
36
+ const traced = await traceChain(candidateDeps, hops, finding.pkg.version, fixedVersion);
37
+ if (!traced)
38
+ continue;
39
+ return {
40
+ directDep: directDepName,
41
+ directDepCurrentVersion,
42
+ targetVersion: candidateVersion,
43
+ chain: traced.chain,
44
+ safeVersion: traced.safeVersion,
45
+ command: `${commandPrefix(packageManager)} ${directDepName}@${candidateVersion}`,
46
+ coveredPaths: 1,
47
+ totalPaths: finding.dependencyPaths.length,
48
+ };
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+ async function traceChain(deps, remainingPath, vulnerableInstalledVersion, fixedVersion) {
54
+ if (remainingPath.length === 0)
55
+ return null;
56
+ const nextName = remainingPath[0];
57
+ const range = deps[nextName];
58
+ if (!range)
59
+ return null;
60
+ if (remainingPath.length === 1) {
61
+ // Bottom of chain: nextName IS the vulnerable package.
62
+ // The range from the parent must exclude the vulnerable installed version.
63
+ if (versionSatisfiesRange(vulnerableInstalledVersion, range)) {
64
+ // Range still allows the vulnerable version - this candidate does not fix it.
65
+ return null;
66
+ }
67
+ // Range excludes the vulnerable version - find the highest safe published version.
68
+ const packument = await fetchPackument(nextName);
69
+ if (!packument?.versions)
70
+ return null;
71
+ const candidates = Object.keys(packument.versions)
72
+ .filter(looksLikeVersion)
73
+ .filter(v => !isPreReleaseVersion(v))
74
+ .filter(v => compareVersions(v, fixedVersion) >= 0)
75
+ .sort(compareVersions);
76
+ const safeVersion = highestVersionSatisfyingRange(candidates, range);
77
+ if (!safeVersion)
78
+ return null;
79
+ return { chain: [], safeVersion };
80
+ }
81
+ // Intermediate hop: resolve the highest version of nextName within range, then recurse.
82
+ const packument = await fetchPackument(nextName);
83
+ if (!packument?.versions)
84
+ return null;
85
+ const candidates = Object.keys(packument.versions)
86
+ .filter(looksLikeVersion)
87
+ .filter(v => !isPreReleaseVersion(v))
88
+ .sort(compareVersions);
89
+ const resolvedVersion = highestVersionSatisfyingRange(candidates, range);
90
+ if (!resolvedVersion)
91
+ return null;
92
+ const nextDeps = packument.versions[resolvedVersion]?.dependencies ?? {};
93
+ const result = await traceChain(nextDeps, remainingPath.slice(1), vulnerableInstalledVersion, fixedVersion);
94
+ if (!result)
95
+ return null;
96
+ return {
97
+ chain: [{ name: nextName, version: resolvedVersion }, ...result.chain],
98
+ safeVersion: result.safeVersion,
99
+ };
100
+ }
@@ -6,12 +6,15 @@ import { sortFindingsForOutput } from "../output/formatters.js";
6
6
  import { normalizeSeverity } from "../osv/severity.js";
7
7
  import { selectFindingsForTable } from "../output/finding-display.js";
8
8
  import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
9
- import { readDirectDependencyNames } from "../utils/package-json.js";
9
+ import { readDirectDependencyNames, hasOverrideEntries } from "../utils/package-json.js";
10
10
  import { DEFAULT_SEARCH_DEPTH, severityOrder } from "../constants.js";
11
11
  import { printMultiFolderResults } from "../output/multi-folder-printer.js";
12
+ import { printOverrideHint } from "../output/printers.js";
12
13
  import { writeMultiFolderHtmlReport } from "../output/multi-folder-html-reporter.js";
13
14
  import { chalk } from "../utils/chalk.js";
14
15
  import { getCliVersion } from "../utils/version-info.js";
16
+ import { buildOverrideContext, audit } from "../overrides/index.js";
17
+ import { NULL_AUDIT_LOG } from "../audit-log/index.js";
15
18
  export async function runMultiFolderScan(params) {
16
19
  const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
17
20
  const folders = loadMultiplePackages(params.projectRoot, !!params.options.prodOnly, searchDepth);
@@ -35,6 +38,17 @@ export async function runMultiFolderScan(params) {
35
38
  const minSeverity = normalizeSeverity(params.options.minSeverity || "medium");
36
39
  const tableFindings = params.options.all ? sorted : selectFindingsForTable(sorted, minSeverity);
37
40
  const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, scanInput, { offline, subfolder });
41
+ // Override hygiene per folder, mirroring the single-folder --check-overrides path.
42
+ let overrideFindings = [];
43
+ if (params.options.checkOverrides) {
44
+ const overrideCtx = buildOverrideContext(subfolderAbs, {
45
+ auditLog: NULL_AUDIT_LOG,
46
+ logger: { info: () => { }, warn: () => { }, error: () => { }, debug: () => { } },
47
+ checkNetwork: !!params.options.checkNetwork,
48
+ });
49
+ const overrideAudit = await audit(overrideCtx, { checkNetwork: !!params.options.checkNetwork });
50
+ overrideFindings = overrideAudit.findings;
51
+ }
38
52
  results.push({
39
53
  subfolder,
40
54
  scanInput,
@@ -44,6 +58,7 @@ export async function runMultiFolderScan(params) {
44
58
  minSeverity,
45
59
  tableFindings,
46
60
  allPackages: scanInput.packages,
61
+ overrideFindings,
47
62
  });
48
63
  }
49
64
  return results;
@@ -72,11 +87,32 @@ export async function handleMultiFolderScan(params) {
72
87
  multiFolder: true,
73
88
  folders: results.map(r => r.subfolder),
74
89
  findings: allFindings,
90
+ ...(params.options.checkOverrides
91
+ ? {
92
+ overrideFindings: results.flatMap(r => r.overrideFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
93
+ }
94
+ : {}),
75
95
  scannedAt: new Date().toISOString(),
76
96
  }, null, 2));
77
97
  }
78
98
  else {
79
99
  printMultiFolderResults(results, params.options);
100
+ if (params.options.checkOverrides) {
101
+ const { renderOverrideFindings } = await import("../output/override-findings-terminal.js");
102
+ for (const r of results) {
103
+ process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray("override hygiene")}\n`);
104
+ console.log(renderOverrideFindings(r.overrideFindings, { verbose: !!params.options.verbose }));
105
+ }
106
+ }
107
+ if (!params.options.checkOverrides && !params.options.ratchet) {
108
+ for (const r of results) {
109
+ const subfolderPath = path.join(params.projectRoot, r.subfolder);
110
+ if (hasOverrideEntries(subfolderPath)) {
111
+ printOverrideHint();
112
+ break; // one hint is enough even if multiple subfolders have overrides
113
+ }
114
+ }
115
+ }
80
116
  }
81
117
  if (params.options.report) {
82
118
  const outputDir = path.resolve(typeof params.options.report === "string" ? params.options.report : "./cve-report");