cve-lite-cli 1.40.0 → 1.41.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 (68) hide show
  1. package/README.md +17 -11
  2. package/dist/advisory/local-advisory-source.js +9 -5
  3. package/dist/advisory/local-db.js +91 -13
  4. package/dist/advisory/osv-sync.js +187 -56
  5. package/dist/advisory/staging-directory.js +112 -0
  6. package/dist/cli/advisories-sync.js +16 -2
  7. package/dist/cli/args.js +46 -35
  8. package/dist/cli/config.js +4 -1
  9. package/dist/cli/help.js +4 -3
  10. package/dist/cli/validate.js +23 -1
  11. package/dist/constants.js +11 -25
  12. package/dist/index.js +8 -3
  13. package/dist/output/cyclonedx.js +23 -14
  14. package/dist/output/debug.js +68 -18
  15. package/dist/output/formatters.js +33 -5
  16. package/dist/output/html-reporter.js +55 -5
  17. package/dist/output/multi-folder-html-reporter.js +59 -3
  18. package/dist/output/output-dir.js +193 -7
  19. package/dist/output/printers.js +16 -5
  20. package/dist/output/sarif.js +131 -48
  21. package/dist/output/sbom-dependency-edges.js +16 -10
  22. package/dist/output/sbom-file.js +14 -6
  23. package/dist/output/scan-json.js +21 -3
  24. package/dist/output/spdx.js +61 -23
  25. package/dist/output/spinner.js +2 -1
  26. package/dist/output/write-outputs.js +142 -52
  27. package/dist/overrides/context-builder.js +23 -70
  28. package/dist/parsers/bun-lock.js +1 -2
  29. package/dist/parsers/index.js +22 -1
  30. package/dist/parsers/npm-lock-graph.js +39 -1
  31. package/dist/parsers/package-lock.js +25 -5
  32. package/dist/parsers/pnpm-lock.js +3 -2
  33. package/dist/parsers/utils.js +5 -3
  34. package/dist/parsers/yarn-lock-graph.js +5 -2
  35. package/dist/parsers/yarn-lock.js +1 -2
  36. package/dist/remediation/fix-commands.js +105 -44
  37. package/dist/remediation/npm-transitive-graph.js +30 -72
  38. package/dist/remediation/npm-transitive-resolution.js +24 -77
  39. package/dist/remediation/parent-upgrade-blockers.js +51 -0
  40. package/dist/remediation/parent-upgrade.js +5 -79
  41. package/dist/remediation/registry-parent-ranges.js +21 -0
  42. package/dist/remediation/transitive-chain-resolver.js +3 -3
  43. package/dist/scan/completeness.js +10 -4
  44. package/dist/scan/multi-folder-scan.js +133 -58
  45. package/dist/scan/single-scan.js +41 -25
  46. package/dist/scanner.js +257 -58
  47. package/dist/usage/scanner.js +19 -8
  48. package/dist/utils/array.js +11 -3
  49. package/dist/utils/debug-bundle.js +118 -0
  50. package/dist/utils/debug-project.js +102 -0
  51. package/dist/utils/debug-redaction.js +117 -0
  52. package/dist/utils/file.js +2 -1
  53. package/dist/utils/fix-runner.js +95 -13
  54. package/dist/utils/import-type-queries.js +322 -0
  55. package/dist/utils/network.js +13 -9
  56. package/dist/utils/npm-lockfile.js +12 -0
  57. package/dist/utils/osv-fetch.js +70 -0
  58. package/dist/utils/package-identity.js +43 -0
  59. package/dist/utils/package-manager-source.js +24 -0
  60. package/dist/utils/purl.js +37 -0
  61. package/dist/utils/registry-config.js +1 -16
  62. package/dist/utils/string.js +8 -0
  63. package/dist/utils/validate-url.js +1 -1
  64. package/dist/utils/version.js +30 -7
  65. package/dist/utils/versions/osv-range.js +191 -0
  66. package/dist/utils/versions/pep440.js +246 -0
  67. package/dist/utils/versions/scheme.js +10 -0
  68. package/package.json +3 -2
package/dist/scanner.js CHANGED
@@ -1,8 +1,11 @@
1
+ import { findParentUpgradeBlockers } from "./remediation/parent-upgrade-blockers.js";
2
+ import { readWorkspaceMemberManifests } from "./utils/package-json.js";
1
3
  import { fetchEpssScores } from "./epss/client.js";
2
4
  import { chunk, runWithConcurrency } from "./utils/array.js";
3
5
  import { isPrivateRegistrySource, isGitSource, hasCommitShaPinning } from "./utils/advisory.js";
4
6
  import { collapseAliasedDuplicates, extractCveAliases, hasMaliciousAdvisory } from "./utils/vuln.js";
5
- import { compareVersions, isPreReleaseVersion, normalizeAdvisoryVersion } from "./utils/version.js";
7
+ import { compareVersions, isPep440Ecosystem, isPreReleaseVersion, looksLikeVersion, normalizeAdvisoryVersion } from "./utils/version.js";
8
+ import { pep440UnreadableApplies, readPep440Range, versionInPep440Window } from "./utils/versions/osv-range.js";
6
9
  import { loadCache, saveCache, isEntryStale } from "./osv/cache.js";
7
10
  import { maxSeverity } from "./osv/severity.js";
8
11
  import { createSpinner } from "./output/spinner.js";
@@ -14,9 +17,13 @@ import { ADVISORY_DB_STALE_AFTER_MS, getDefaultAdvisoryDbPath } from "./advisory
14
17
  import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js";
15
18
  import { configureNpmRegistry, configureNpmRegistryDebug, fetchPackument, resolveLowestKnownNonVulnerableVersion, resolvePublishedFixVersion, runWithObserver, } from "./remediation/npm-registry.js";
16
19
  import { countBySeverity } from "./utils/severity.js";
17
- import { resolveNpmTransitiveRemediation, resolveTransitiveRemediationViaRegistry } from "./remediation/npm-transitive-resolution.js";
20
+ import { isNpmLockSource, packageManagerForSource } from "./utils/package-manager-source.js";
21
+ import { resolveNpmTransitiveRemediation, resolveTransitiveRemediationViaRegistry, } from "./remediation/npm-transitive-resolution.js";
18
22
  import { resolveChainFix } from "./remediation/transitive-chain-resolver.js";
19
23
  import { loadNpmLockGraph } from "./parsers/npm-lock-graph.js";
24
+ import { loadPnpmLockGraph } from "./parsers/pnpm-lock-graph.js";
25
+ import { loadYarnLockGraph } from "./parsers/yarn-lock-graph.js";
26
+ import { loadBunLockGraph } from "./parsers/bun-lock-graph.js";
20
27
  import { buildPnpmWorkspaceMap } from "./parsers/pnpm-lock.js";
21
28
  import { buildNpmWorkspaceMap } from "./parsers/package-lock.js";
22
29
  import { buildBunWorkspaceMap } from "./parsers/bun-lock.js";
@@ -26,6 +33,7 @@ import { resolveRegistryConfig } from "./utils/registry-config.js";
26
33
  import { extractErrorMessage } from "./utils/network.js";
27
34
  import { logWarn } from "./output/formatters.js";
28
35
  import { formatDiagnosticMessage } from "./scan/completeness.js";
36
+ import { packageInstanceKey, registryPackage, registryPackageName } from "./utils/package-identity.js";
29
37
  /**
30
38
  * Advisory id namespaces OSV does not serve. Ids with these prefixes come from
31
39
  * a different source, so OSV failing to resolve them is expected and must not
@@ -58,18 +66,7 @@ export function createAdvisorySource(options) {
58
66
  };
59
67
  }
60
68
  function getPackageCacheKey(pkg) {
61
- return `${pkg.ecosystem}:${pkg.name}@${pkg.version}`;
62
- }
63
- function inferPackageManagerForChain(source) {
64
- if (source === "package-lock" || source === "npm-shrinkwrap")
65
- return "npm";
66
- if (source === "pnpm-lock")
67
- return "pnpm";
68
- if (source === "yarn-lock")
69
- return "yarn";
70
- if (source === "bun-lock")
71
- return "bun";
72
- return null;
69
+ return `${pkg.ecosystem}:${registryPackageName(pkg)}@${pkg.version}`;
73
70
  }
74
71
  function isTransientFailure(error) {
75
72
  if (!(error instanceof Error))
@@ -82,16 +79,22 @@ function isTransientFailure(error) {
82
79
  function mergeResultsByPackage(results) {
83
80
  const map = new Map();
84
81
  for (const result of results) {
85
- const key = `${result.pkg.name}@${result.pkg.version}`;
82
+ const key = packageInstanceKey(result.pkg);
86
83
  const existing = map.get(key);
87
84
  if (existing) {
88
85
  for (const id of result.vulnIds) {
89
86
  if (!existing.vulnIds.includes(id))
90
87
  existing.vulnIds.push(id);
91
88
  }
89
+ if (result.unreadable)
90
+ existing.unreadable = true;
92
91
  }
93
92
  else {
94
- map.set(key, { pkg: result.pkg, vulnIds: [...result.vulnIds] });
93
+ map.set(key, {
94
+ pkg: result.pkg,
95
+ vulnIds: [...result.vulnIds],
96
+ ...(result.unreadable ? { unreadable: true } : {}),
97
+ });
95
98
  }
96
99
  }
97
100
  return [...map.values()];
@@ -120,7 +123,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
120
123
  // public registry, which is the previous behaviour.
121
124
  const registryConfig = resolveRegistryConfig({
122
125
  projectPath: context?.scanFilePath ? path.dirname(context.scanFilePath) : process.cwd(),
123
- packageManager: inferPackageManagerForChain(context?.scanSource),
126
+ packageManager: packageManagerForSource(context?.scanSource),
124
127
  });
125
128
  configureNpmRegistry(registryConfig);
126
129
  if (options.debug) {
@@ -133,6 +136,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
133
136
  const cache = loadCache(cacheDirOverride, options.debug ? log : undefined);
134
137
  try {
135
138
  const results = [];
139
+ let unreadableBoundaryPackages = 0;
136
140
  const uncachedPackages = [];
137
141
  if (!offline) {
138
142
  const nowMs = Date.now();
@@ -162,8 +166,8 @@ export async function scanPackages(packages, batchSize, options, context, debugL
162
166
  const allAdvisoryResults = await runWithConcurrency(chunks, 5, c => {
163
167
  batchCounter += 1;
164
168
  const batchId = `b-${String(batchCounter).padStart(2, "0")}`;
165
- return advisorySource.queryBatch(c, { batchId });
166
- });
169
+ return advisorySource.queryBatch(c.map(registryPackage), { batchId });
170
+ }, { onError: "stop" });
167
171
  const cachedAt = new Date().toISOString();
168
172
  for (let i = 0; i < chunks.length; i++) {
169
173
  const chunkItems = chunks[i];
@@ -171,8 +175,8 @@ export async function scanPackages(packages, batchSize, options, context, debugL
171
175
  for (let j = 0; j < chunkItems.length; j++) {
172
176
  const pkg = chunkItems[j];
173
177
  const row = rows[j];
174
- if (row && (row.package !== pkg.name || row.version !== pkg.version)) {
175
- throw new Error(`OSV result identity mismatch at index ${j}: expected ${pkg.name}@${pkg.version}, got ${row.package}@${row.version}`);
178
+ if (row && (row.package !== registryPackageName(pkg) || row.version !== pkg.version)) {
179
+ throw new Error(`OSV result identity mismatch at index ${j}: expected ${registryPackageName(pkg)}@${pkg.version}, got ${row.package}@${row.version}`);
176
180
  }
177
181
  const vulnIds = (row?.vulnerabilities ?? []).map(v => v.id).filter(Boolean);
178
182
  cache.queryEntries[getPackageCacheKey(pkg)] = { vulnIds, cachedAt };
@@ -196,14 +200,17 @@ export async function scanPackages(packages, batchSize, options, context, debugL
196
200
  }
197
201
  }
198
202
  else {
199
- const advisoryResult = await advisorySource.queryBatch(packages, { batchId: "offline" });
203
+ const advisoryResult = await advisorySource.queryBatch(packages.map(registryPackage), { batchId: "offline" });
200
204
  const rows = advisoryResult ?? [];
201
205
  for (let i = 0; i < packages.length; i++) {
202
206
  const pkg = packages[i];
203
207
  const row = rows[i];
204
208
  const vulnIds = (row?.vulnerabilities ?? []).map(v => v.id).filter(Boolean);
209
+ const unreadable = row?.unreadableBoundary === true;
210
+ if (unreadable)
211
+ unreadableBoundaryPackages += 1;
205
212
  if (vulnIds.length > 0) {
206
- results.push({ pkg, vulnIds });
213
+ results.push({ pkg, vulnIds, ...(unreadable ? { unreadable: true } : {}) });
207
214
  }
208
215
  }
209
216
  spinner.succeed("Loaded package matches from the local advisory database");
@@ -245,13 +252,13 @@ export async function scanPackages(packages, batchSize, options, context, debugL
245
252
  }
246
253
  }
247
254
  if (uncachedForNpm.length > 0) {
248
- const npmResults = await queryNpmAdvisoryGaps(uncachedForNpm, {
255
+ const npmResults = await queryNpmAdvisoryGaps(uncachedForNpm.map(registryPackage), {
249
256
  fetchImpl,
250
257
  offline,
251
258
  debugLog: log,
252
259
  });
253
260
  for (const pkg of uncachedForNpm) {
254
- const found = npmResults.find(r => r.pkg.name === pkg.name && r.pkg.version === pkg.version);
261
+ const found = npmResults.find(r => r.pkg.name === registryPackageName(pkg) && r.pkg.version === pkg.version);
255
262
  const vulns = found?.vulns ?? [];
256
263
  // Store the full advisories in cache, not just their ids, so a later scan
257
264
  // can restore the detail rather than going looking for it in OSV, which
@@ -390,7 +397,8 @@ export async function scanPackages(packages, batchSize, options, context, debugL
390
397
  const cveAliases = extractCveAliases(vulnerabilities);
391
398
  const dependencyPaths = result.pkg.paths ?? [];
392
399
  const relationship = classifyRelationship(dependencyPaths, result.pkg.name, context?.directDependencyNames);
393
- const firstFixedVersion = findFirstFixedVersion(vulnerabilities, result.pkg.name, result.pkg.ecosystem, result.pkg.version);
400
+ const selectedFix = selectFixedVersion(vulnerabilities, registryPackageName(result.pkg), result.pkg.ecosystem, result.pkg.version);
401
+ const advisoryBoundaryUnreadable = selectedFix.unreadable || result.unreadable === true;
394
402
  return {
395
403
  pkg: result.pkg,
396
404
  vulnerabilities,
@@ -398,7 +406,8 @@ export async function scanPackages(packages, batchSize, options, context, debugL
398
406
  cveAliases,
399
407
  dependencyPaths,
400
408
  relationship,
401
- firstFixedVersion,
409
+ firstFixedVersion: advisoryBoundaryUnreadable ? null : selectedFix.version,
410
+ ...(advisoryBoundaryUnreadable ? { advisoryBoundaryUnreadable: true } : {}),
402
411
  validatedFirstFixedVersion: null,
403
412
  fixVersionValidationNote: null,
404
413
  fixVersionPublishedAt: null,
@@ -409,6 +418,12 @@ export async function scanPackages(packages, batchSize, options, context, debugL
409
418
  ...(unresolvedIds.length > 0 ? { unresolvedAdvisoryIds: unresolvedIds } : {}),
410
419
  };
411
420
  });
421
+ // Parent resolvers interpret path segments as registry names. Until they
422
+ // support aliases, do not let them recommend a different package that
423
+ // happens to be published under an installed alias's name.
424
+ const aliasNames = new Set(packages.filter(pkg => pkg.registryName).map(pkg => pkg.name));
425
+ const aliasRemediationFindings = new Set(findings.filter(finding => finding.relationship === "transitive"
426
+ && finding.dependencyPaths.some(dependencyPath => dependencyPath.some(name => aliasNames.has(name)))));
412
427
  const unresolvedDetailIds = idSet.size > 0
413
428
  ? [...idSet].filter(id => !vulnMap.has(id))
414
429
  : [];
@@ -430,7 +445,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
430
445
  if (otherCount > 0) {
431
446
  parts.push(`${otherCount} could not be resolved`);
432
447
  }
433
- logWarn(`⚠ ${unresolvedDetailIds.length} advisory detail ${pluralize(unresolvedDetailIds.length, "lookup")} missing from findings. ${parts.join("; ")}.`, { json: options.json });
448
+ logWarn(`⚠ ${unresolvedDetailIds.length} advisory detail ${pluralize(unresolvedDetailIds.length, "lookup")} missing from findings. ${parts.join("; ")}.`, { json: options.json, output: options.output });
434
449
  }
435
450
  for (const finding of findings) {
436
451
  if (hasMaliciousAdvisory(finding.vulnerabilities)) {
@@ -443,12 +458,14 @@ export async function scanPackages(packages, batchSize, options, context, debugL
443
458
  }
444
459
  }
445
460
  }
446
- const npmTransitiveGraph = context?.scanSource === "package-lock" && context.scanFilePath
461
+ const npmTransitiveGraph = isNpmLockSource(context?.scanSource) && context?.scanFilePath
447
462
  ? createNpmTransitiveGraphFromLockfile(context.scanFilePath, log, packages.length)
448
463
  : null;
464
+ const lockParentGraph = loadLockParentGraph(context?.scanSource, context?.scanFilePath, log);
465
+ const workspaceMemberNames = readWorkspaceMemberNames(context?.scanFilePath);
449
466
  const npmWorkspaceMap = (() => {
450
467
  try {
451
- return context?.scanSource === "package-lock" && context.scanFilePath
468
+ return isNpmLockSource(context?.scanSource) && context?.scanFilePath
452
469
  ? buildNpmWorkspaceMap(context.scanFilePath) : null;
453
470
  }
454
471
  catch (error) {
@@ -461,7 +478,10 @@ export async function scanPackages(packages, batchSize, options, context, debugL
461
478
  }
462
479
  })();
463
480
  if (npmWorkspaceMap) {
464
- log("Workspace map", { type: "npm", workspaces: npmWorkspaceMap.size });
481
+ log("Workspace map", {
482
+ type: "npm",
483
+ dependencyCount: npmWorkspaceMap.size,
484
+ });
465
485
  }
466
486
  const pnpmWorkspaceMap = (() => {
467
487
  try {
@@ -478,7 +498,10 @@ export async function scanPackages(packages, batchSize, options, context, debugL
478
498
  }
479
499
  })();
480
500
  if (pnpmWorkspaceMap) {
481
- log("Workspace map", { type: "pnpm", workspaces: pnpmWorkspaceMap.size });
501
+ log("Workspace map", {
502
+ type: "pnpm",
503
+ dependencyCount: pnpmWorkspaceMap.size,
504
+ });
482
505
  }
483
506
  const bunWorkspaceMap = (() => {
484
507
  try {
@@ -495,7 +518,10 @@ export async function scanPackages(packages, batchSize, options, context, debugL
495
518
  }
496
519
  })();
497
520
  if (bunWorkspaceMap) {
498
- log("Workspace map", { type: "bun", workspaces: bunWorkspaceMap.size });
521
+ log("Workspace map", {
522
+ type: "bun",
523
+ dependencyCount: bunWorkspaceMap.size,
524
+ });
499
525
  }
500
526
  const lockfileWorkspaceMap = pnpmWorkspaceMap ?? bunWorkspaceMap ?? null;
501
527
  const packumentFailures = new Set();
@@ -541,6 +567,9 @@ export async function scanPackages(packages, batchSize, options, context, debugL
541
567
  for (const finding of findings) {
542
568
  if (finding.relationship !== "transitive")
543
569
  continue;
570
+ if (aliasRemediationFindings.has(finding)) {
571
+ continue;
572
+ }
544
573
  packumentsToPrewarm.add(finding.pkg.name);
545
574
  const paths = finding.dependencyPaths;
546
575
  if (paths.length > 0 && paths[0].length >= 2) {
@@ -557,6 +586,11 @@ export async function scanPackages(packages, batchSize, options, context, debugL
557
586
  if (finding.relationship !== "transitive")
558
587
  continue;
559
588
  updateAnalysisProgress("resolving remediation for", `${finding.pkg.name}@${finding.pkg.version}`);
589
+ if (aliasRemediationFindings.has(finding)) {
590
+ const aliasNote = `Automatic parent remediation is unavailable for paths containing an npm alias. Run \`npm ls ${finding.pkg.name}\` to inspect the declaring dependency, then rescan after updating it.`;
591
+ finding.fixVersionValidationNote = [finding.fixVersionValidationNote, aliasNote].filter(Boolean).join(" ");
592
+ continue;
593
+ }
560
594
  const remediationCacheKey = JSON.stringify({
561
595
  package: finding.pkg.name,
562
596
  version: finding.pkg.version,
@@ -591,6 +625,11 @@ export async function scanPackages(packages, batchSize, options, context, debugL
591
625
  confidence: "verified",
592
626
  reason: finding.recommendedNpmTransitiveRemediation.reason,
593
627
  };
628
+ finding.parentUpgradeBlockers = await blockersForParentUpgrade(finding, {
629
+ packages,
630
+ workspaceMemberNames,
631
+ npmGraph: npmTransitiveGraph,
632
+ });
594
633
  continue;
595
634
  }
596
635
  if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
@@ -609,6 +648,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
609
648
  packages,
610
649
  directDependencyNames: context?.directDependencyNames,
611
650
  workspaceMap: lockfileWorkspaceMap,
651
+ parentGraph: lockParentGraph,
612
652
  });
613
653
  npmRemediationCache.set(remediationCacheKey, finding.recommendedNpmTransitiveRemediation ?? null);
614
654
  }
@@ -624,6 +664,12 @@ export async function scanPackages(packages, batchSize, options, context, debugL
624
664
  finding.recommendedParentUpgrade = await resolveRecommendedParentUpgrade(finding, packages, context?.directDependencyNames, { offline });
625
665
  parentUpgradeCache.set(remediationCacheKey, finding.recommendedParentUpgrade ?? null);
626
666
  }
667
+ finding.parentUpgradeBlockers = await blockersForParentUpgrade(finding, {
668
+ packages,
669
+ workspaceMemberNames,
670
+ npmGraph: npmTransitiveGraph,
671
+ lockParentGraph,
672
+ });
627
673
  }
628
674
  catch (error) {
629
675
  const packageName = finding.pkg.name;
@@ -639,11 +685,11 @@ export async function scanPackages(packages, batchSize, options, context, debugL
639
685
  }
640
686
  analysisSpinner.succeed("Analyzed vulnerability findings");
641
687
  // Chain fix resolution: pre-compute validated chain for transitive findings
642
- const chainPm = inferPackageManagerForChain(context?.scanSource);
688
+ const chainPm = packageManagerForSource(context?.scanSource);
643
689
  if (chainPm) {
644
690
  const installedVersions = new Map(packages.map(p => [p.name, p.version]));
645
691
  await Promise.all(findings
646
- .filter(f => f.relationship === "transitive" && f.dependencyPaths?.length)
692
+ .filter(f => f.relationship === "transitive" && f.dependencyPaths?.length && !aliasRemediationFindings.has(f))
647
693
  .map(async (finding) => {
648
694
  try {
649
695
  finding.chainResolution = await resolveChainFix(finding, installedVersions, chainPm, { offline });
@@ -695,6 +741,8 @@ export async function scanPackages(packages, batchSize, options, context, debugL
695
741
  packumentFailures,
696
742
  remediationFailures,
697
743
  chainResolutionFailureCount,
744
+ unreadableBoundaryPackages,
745
+ unreadableFixPackages: findings.filter(finding => finding.advisoryBoundaryUnreadable).length,
698
746
  });
699
747
  const completeness = {
700
748
  complete: diagnostics.length === 0,
@@ -713,6 +761,35 @@ export async function scanPackages(packages, batchSize, options, context, debugL
713
761
  sourceContext.cleanup();
714
762
  }
715
763
  }
764
+ // Direct dependencies that keep the vulnerable copy installed after the
765
+ // recommended parent upgrade, judged against the first safe version (#1457).
766
+ async function blockersForParentUpgrade(finding, graphs) {
767
+ const upgrade = finding.recommendedParentUpgrade;
768
+ // Without a known fixed version, test the child version the upgrade moves to.
769
+ const safeVersion = finding.validatedFirstFixedVersion
770
+ ?? finding.firstFixedVersion
771
+ ?? finding.recommendedNpmTransitiveRemediation?.targetChildVersion;
772
+ if (!upgrade || !safeVersion)
773
+ return undefined;
774
+ const blockers = await findParentUpgradeBlockers({
775
+ childName: finding.pkg.name,
776
+ childVersion: finding.pkg.version,
777
+ targetChildVersion: safeVersion,
778
+ upgradedParent: upgrade.package,
779
+ packages: graphs.packages,
780
+ workspaceMemberNames: graphs.workspaceMemberNames,
781
+ npmGraph: graphs.npmGraph,
782
+ lockParentGraph: graphs.lockParentGraph,
783
+ });
784
+ return blockers.length > 0 ? blockers : undefined;
785
+ }
786
+ function readWorkspaceMemberNames(scanFilePath) {
787
+ if (!scanFilePath)
788
+ return new Set();
789
+ return new Set(readWorkspaceMemberManifests(path.dirname(scanFilePath))
790
+ .map(member => member.manifest.name)
791
+ .filter((name) => typeof name === "string"));
792
+ }
716
793
  function createNpmTransitiveGraphFromLockfile(filePath, log, packageCount) {
717
794
  try {
718
795
  const lockGraph = loadNpmLockGraph(filePath, { includePaths: false });
@@ -733,6 +810,12 @@ function createNpmTransitiveGraphFromLockfile(filePath, log, packageCount) {
733
810
  rangeFor(parentNodeId, childName) {
734
811
  return lockGraph.rangeFor(parentNodeId, childName);
735
812
  },
813
+ parentsFor(nodeId) {
814
+ return lockGraph.parentsFor(nodeId);
815
+ },
816
+ peerRangesFor(nodeId) {
817
+ return lockGraph.peerRangesFor?.(nodeId) ?? [];
818
+ },
736
819
  };
737
820
  }
738
821
  catch (error) {
@@ -743,6 +826,25 @@ function createNpmTransitiveGraphFromLockfile(filePath, log, packageCount) {
743
826
  return null;
744
827
  }
745
828
  }
829
+ // Every parent of each package, for the lockfiles whose remediation goes through
830
+ // the registry. A within-range update has to suit all of them (#1291). Without
831
+ // it the route falls back to the one parent the recorded path names.
832
+ function loadLockParentGraph(source, filePath, log) {
833
+ if (!filePath)
834
+ return null;
835
+ try {
836
+ if (source === "pnpm-lock")
837
+ return loadPnpmLockGraph(filePath);
838
+ if (source === "yarn-lock")
839
+ return loadYarnLockGraph(filePath);
840
+ if (source === "bun-lock")
841
+ return loadBunLockGraph(filePath);
842
+ }
843
+ catch (error) {
844
+ log("lock parent graph", { status: "failed", error: extractErrorMessage(error) });
845
+ }
846
+ return null;
847
+ }
746
848
  async function validateDirectFixTargets(findings, onFinding, options) {
747
849
  const directCandidates = findings.filter(finding => finding.vulnerabilities.length > 0);
748
850
  const results = await runWithConcurrency(directCandidates, 8, async (finding) => {
@@ -752,6 +854,8 @@ async function validateDirectFixTargets(findings, onFinding, options) {
752
854
  return results.some(Boolean);
753
855
  }
754
856
  async function validateOneDirectFixTarget(finding, options) {
857
+ if (finding.advisoryBoundaryUnreadable)
858
+ return false;
755
859
  let npmVersionCacheUpdated = false;
756
860
  const debugLog = options?.debugLog;
757
861
  const logFixValidation = () => {
@@ -764,14 +868,14 @@ async function validateOneDirectFixTarget(finding, options) {
764
868
  };
765
869
  // The advisory source re-checks the proposed version for advisories
766
870
  // introduced above the installed one, which never matched this finding.
767
- const lowestKnownResolution = await resolveLowestKnownNonVulnerableVersion(finding.pkg.name, finding.pkg.version, finding.vulnerabilities, { advisorySource: options?.advisorySource, proposedVersion: finding.firstFixedVersion });
871
+ const lowestKnownResolution = await resolveLowestKnownNonVulnerableVersion(registryPackageName(finding.pkg), finding.pkg.version, finding.vulnerabilities, { advisorySource: options?.advisorySource, proposedVersion: finding.firstFixedVersion });
768
872
  const fixedVersionHint = finding.firstFixedVersion;
769
873
  const setPublishedDate = (resolution) => {
770
874
  const date = resolution.publishedAt;
771
875
  finding.fixVersionPublishedAt = date;
772
876
  if (!date || !options?.cache)
773
877
  return;
774
- const cacheKey = `${finding.pkg.name}@${finding.validatedFirstFixedVersion}`;
878
+ const cacheKey = `${registryPackageName(finding.pkg)}@${finding.validatedFirstFixedVersion}`;
775
879
  const existing = options.cache.npmVersionEntries?.[cacheKey];
776
880
  if (!options.noCache && existing?.publishedAt === date)
777
881
  return;
@@ -792,7 +896,7 @@ async function validateOneDirectFixTarget(finding, options) {
792
896
  logFixValidation();
793
897
  return npmVersionCacheUpdated;
794
898
  }
795
- const hintResolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
899
+ const hintResolution = await resolvePublishedFixVersion(registryPackageName(finding.pkg), fixedVersionHint);
796
900
  if (hintResolution.resolvedVersion === lowestKnownResolution.resolvedVersion &&
797
901
  hintResolution.note) {
798
902
  finding.fixVersionValidationNote = hintResolution.note;
@@ -817,7 +921,7 @@ async function validateOneDirectFixTarget(finding, options) {
817
921
  logFixValidation();
818
922
  return npmVersionCacheUpdated;
819
923
  }
820
- const resolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
924
+ const resolution = await resolvePublishedFixVersion(registryPackageName(finding.pkg), fixedVersionHint);
821
925
  // Publication confirms availability, not that every advisory is fixed.
822
926
  finding.validatedFirstFixedVersion = null;
823
927
  finding.fixVersionValidationNote = [
@@ -888,18 +992,18 @@ function affectedEntryMatchesPackage(affected, packageName, ecosystem) {
888
992
  * `introduced` of "0" (or absent) means the window has no lower bound, which is
889
993
  * how OSV expresses "every version before the fix".
890
994
  */
891
- function versionWithinAffectedWindow(version, introduced, fixed) {
995
+ function versionWithinAffectedWindow(version, introduced, fixed, ecosystem) {
892
996
  if (introduced && introduced !== "0") {
893
- // Advisories write boundaries with fewer than three components, so `2` means
894
- // 2.0.0. Normalizing rather than rejecting keeps the window usable, and a
895
- // value that is not a version at all still returns null and bails (#1192).
896
- const normalizedIntroduced = normalizeAdvisoryVersion(introduced);
997
+ // Advisories write boundaries with fewer than three components. Semver pads
998
+ // `2` to 2.0.0. PEP 440 keeps `2`, which compares equal to 2.0.0. A value
999
+ // that is not a version at all still returns null and the window is skipped.
1000
+ const normalizedIntroduced = normalizeAdvisoryVersion(introduced, ecosystem);
897
1001
  if (!normalizedIntroduced)
898
1002
  return false;
899
- if (compareVersions(version, normalizedIntroduced) < 0)
1003
+ if (compareVersions(version, normalizedIntroduced, ecosystem) < 0)
900
1004
  return false;
901
1005
  }
902
- return compareVersions(version, fixed) < 0;
1006
+ return compareVersions(version, fixed, ecosystem) < 0;
903
1007
  }
904
1008
  /**
905
1009
  * Every usable fixed version one advisory declares for this package, split into
@@ -928,16 +1032,18 @@ function collectAdvisoryFixes(vuln, packageName, ecosystem, installedVersion) {
928
1032
  introduced = event.introduced;
929
1033
  continue;
930
1034
  }
931
- // `fixed: "1.22"` is 1.22.0. Requiring a strict X.Y.Z here discarded the
932
- // event, and a finding whose every candidate was discarded reported "no
933
- // fix available", which tells a developer to stop looking for a fix that
934
- // exists (#1192). A value that cannot be read in full is still dropped,
935
- // so a commit hash from a GIT range never becomes a fix version.
936
- const fixed = normalizeAdvisoryVersion(event.fixed);
937
- if (!fixed || isPreReleaseVersion(fixed))
1035
+ // `fixed: "1.22"` is 1.22.0 for npm. PEP 440 keeps `1.22`, which compares
1036
+ // equal to 1.22.0, and a post-release such as `2026.3.post1` stays a fix.
1037
+ // Requiring a strict X.Y.Z here discarded the event, and a finding whose
1038
+ // every candidate was discarded reported "no fix available", which tells
1039
+ // a developer to stop looking for a fix that exists (#1192). A value that
1040
+ // cannot be read in full is still dropped, so a commit hash from a GIT
1041
+ // range never becomes a fix version.
1042
+ const fixed = normalizeAdvisoryVersion(event.fixed, ecosystem);
1043
+ if (!fixed || isPreReleaseVersion(fixed, ecosystem))
938
1044
  continue;
939
1045
  all.push(fixed);
940
- if (installedVersion && versionWithinAffectedWindow(installedVersion, introduced, fixed)) {
1046
+ if (installedVersion && versionWithinAffectedWindow(installedVersion, introduced, fixed, ecosystem)) {
941
1047
  onInstalledBranch.push(fixed);
942
1048
  }
943
1049
  introduced = null;
@@ -947,29 +1053,120 @@ function collectAdvisoryFixes(vuln, packageName, ecosystem, installedVersion) {
947
1053
  return { all, onInstalledBranch };
948
1054
  }
949
1055
  export function findFirstFixedVersion(vulns, packageName, ecosystem, installedVersion) {
1056
+ return selectFixedVersion(vulns, packageName, ecosystem, installedVersion).version;
1057
+ }
1058
+ /**
1059
+ * The fix to recommend, and whether a PyPI boundary that might contain the
1060
+ * installed version could not be read. An unreadable boundary leaves the
1061
+ * version null and does not stop the scan. npm never sets `unreadable`.
1062
+ */
1063
+ export function selectFixedVersion(vulns, packageName, ecosystem, installedVersion) {
1064
+ if (isPep440Ecosystem(ecosystem)) {
1065
+ return selectPep440FixedVersion(vulns, packageName, ecosystem, installedVersion);
1066
+ }
1067
+ return {
1068
+ version: selectNpmFixedVersion(vulns, packageName, ecosystem, installedVersion),
1069
+ unreadable: false,
1070
+ };
1071
+ }
1072
+ function selectNpmFixedVersion(vulns, packageName, ecosystem, installedVersion) {
950
1073
  const everyKnownFix = [];
951
1074
  // One entry per advisory: the earliest version clearing THAT advisory on the
952
1075
  // branch the install sits on.
953
1076
  const perAdvisoryFixes = [];
1077
+ const byVersion = (left, right) => compareVersions(left, right, ecosystem);
954
1078
  for (const vuln of vulns) {
955
1079
  const { all, onInstalledBranch } = collectAdvisoryFixes(vuln, packageName, ecosystem, installedVersion);
956
1080
  everyKnownFix.push(...all);
957
1081
  if (onInstalledBranch.length > 0) {
958
1082
  // Lowest WITHIN one advisory: the branch fix, not the other branch's.
959
- perAdvisoryFixes.push(onInstalledBranch.sort(compareVersions)[0]);
1083
+ perAdvisoryFixes.push(onInstalledBranch.sort(byVersion)[0]);
960
1084
  }
961
1085
  }
962
1086
  // Highest ACROSS advisories: the caller needs a version clear of all of them,
963
1087
  // and stopping at the lowest leaves every advisory fixed above it still live.
964
1088
  if (perAdvisoryFixes.length > 0) {
965
- return perAdvisoryFixes.sort(compareVersions)[perAdvisoryFixes.length - 1];
1089
+ return perAdvisoryFixes.sort(byVersion)[perAdvisoryFixes.length - 1];
966
1090
  }
967
1091
  // No declared window contains the installed version, so there is no branch to
968
1092
  // scope to. Falling back to every known fix keeps a finding's remediation
969
1093
  // visible rather than reporting none.
970
1094
  if (everyKnownFix.length === 0)
971
1095
  return null;
972
- return everyKnownFix.sort(compareVersions)[0];
1096
+ return everyKnownFix.sort(byVersion)[0];
1097
+ }
1098
+ function selectPep440FixedVersion(vulns, packageName, ecosystem, installedVersion) {
1099
+ if (installedVersion && !looksLikeVersion(installedVersion, ecosystem)) {
1100
+ return { version: null, unreadable: true };
1101
+ }
1102
+ const everyKnownFix = [];
1103
+ const perAdvisoryFixes = [];
1104
+ let unreadable = false;
1105
+ let blocked = false;
1106
+ const byVersion = (left, right) => compareVersions(left, right, ecosystem);
1107
+ for (const vuln of vulns) {
1108
+ const branchFixes = [];
1109
+ let advisoryUnreadable = false;
1110
+ let heldWithoutFix = false;
1111
+ for (const affected of vuln.affected ?? []) {
1112
+ if (!affectedEntryMatchesPackage(affected, packageName, ecosystem))
1113
+ continue;
1114
+ for (const range of affected.ranges ?? []) {
1115
+ const rangeType = range.type;
1116
+ if (rangeType === "GIT")
1117
+ continue;
1118
+ if (rangeType && rangeType !== "ECOSYSTEM" && rangeType !== "SEMVER")
1119
+ continue;
1120
+ const read = readPep440Range(range.events ?? []);
1121
+ if (!installedVersion) {
1122
+ if (read.unreadable.length > 0)
1123
+ advisoryUnreadable = true;
1124
+ }
1125
+ else if (read.unreadable.some(boundary => pep440UnreadableApplies(installedVersion, boundary))) {
1126
+ advisoryUnreadable = true;
1127
+ }
1128
+ for (const fix of read.fixes) {
1129
+ if (!isPreReleaseVersion(fix, ecosystem))
1130
+ everyKnownFix.push(fix);
1131
+ }
1132
+ if (!installedVersion)
1133
+ continue;
1134
+ for (const window of read.windows) {
1135
+ if (!versionInPep440Window(installedVersion, window))
1136
+ continue;
1137
+ if (window.fixed && !isPreReleaseVersion(window.fixed, ecosystem))
1138
+ branchFixes.push(window.fixed);
1139
+ else
1140
+ heldWithoutFix = true;
1141
+ }
1142
+ }
1143
+ }
1144
+ if (advisoryUnreadable) {
1145
+ unreadable = true;
1146
+ continue;
1147
+ }
1148
+ if (heldWithoutFix)
1149
+ blocked = true;
1150
+ else if (branchFixes.length > 0)
1151
+ perAdvisoryFixes.push(branchFixes.sort(byVersion)[0]);
1152
+ }
1153
+ if (unreadable)
1154
+ return { version: null, unreadable: true };
1155
+ if (blocked)
1156
+ return { version: null, unreadable: false };
1157
+ if (perAdvisoryFixes.length > 0) {
1158
+ return { version: perAdvisoryFixes.sort(byVersion)[perAdvisoryFixes.length - 1], unreadable: false };
1159
+ }
1160
+ // No window contains the installed version. A fix it has already reached can
1161
+ // still be named (a patched 2.x build still names the 1.x fix). A later fix
1162
+ // it has not reached belongs to another window, and recommending it would
1163
+ // treat an unaffected version as vulnerable.
1164
+ if (everyKnownFix.length === 0)
1165
+ return { version: null, unreadable: false };
1166
+ if (installedVersion && everyKnownFix.every(fix => byVersion(installedVersion, fix) < 0)) {
1167
+ return { version: null, unreadable: false };
1168
+ }
1169
+ return { version: everyKnownFix.sort(byVersion)[0], unreadable: false };
973
1170
  }
974
1171
  function buildCompletenessDiagnostics(params) {
975
1172
  const diagnostics = [];
@@ -979,7 +1176,7 @@ function buildCompletenessDiagnostics(params) {
979
1176
  diagnostics.push({
980
1177
  code,
981
1178
  severity: "warning",
982
- message: formatDiagnosticMessage(code, count, affectedPackageCount),
1179
+ message: formatDiagnosticMessage(code, count, affectedPackageCount, impact),
983
1180
  impact,
984
1181
  count,
985
1182
  ...(affectedPackageCount === undefined ? {} : { affectedPackageCount }),
@@ -992,6 +1189,8 @@ function buildCompletenessDiagnostics(params) {
992
1189
  addDiagnostic("PACKUMENT_FETCH_FAILURE", params.packumentFailures.size, "remediation");
993
1190
  addDiagnostic("REMEDIATION_FAILURE", remediationTotal, "remediation", params.remediationFailures.size);
994
1191
  addDiagnostic("CHAIN_RESOLUTION_FAILURE", params.chainResolutionFailureCount, "remediation");
1192
+ addDiagnostic("UNREADABLE_PYPI_BOUNDARY", params.unreadableBoundaryPackages, "detection");
1193
+ addDiagnostic("UNREADABLE_PYPI_BOUNDARY", params.unreadableFixPackages, "remediation");
995
1194
  return diagnostics;
996
1195
  }
997
1196
  async function enrichWithEpssScores(findings, fetchImpl) {