cve-lite-cli 1.40.0 → 1.41.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 (75) 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/override-fix-command.js +5 -7
  20. package/dist/output/printers.js +16 -5
  21. package/dist/output/sarif.js +131 -48
  22. package/dist/output/sbom-dependency-edges.js +16 -10
  23. package/dist/output/sbom-file.js +14 -6
  24. package/dist/output/scan-json.js +21 -3
  25. package/dist/output/spdx.js +61 -23
  26. package/dist/output/spinner.js +2 -1
  27. package/dist/output/write-outputs.js +142 -52
  28. package/dist/overrides/context-builder.js +23 -70
  29. package/dist/overrides/parsing/registry.js +19 -69
  30. package/dist/parsers/bun-lock.js +1 -2
  31. package/dist/parsers/index.js +22 -1
  32. package/dist/parsers/npm-lock-graph.js +39 -1
  33. package/dist/parsers/package-lock.js +25 -5
  34. package/dist/parsers/pnpm-lock.js +3 -2
  35. package/dist/parsers/utils.js +5 -3
  36. package/dist/parsers/yarn-lock-graph.js +36 -17
  37. package/dist/parsers/yarn-lock.js +92 -25
  38. package/dist/remediation/fix-commands.js +101 -45
  39. package/dist/remediation/npm-registry.js +10 -2
  40. package/dist/remediation/npm-transitive-graph.js +30 -72
  41. package/dist/remediation/npm-transitive-resolution.js +24 -77
  42. package/dist/remediation/parent-upgrade-blockers.js +51 -0
  43. package/dist/remediation/parent-upgrade.js +5 -79
  44. package/dist/remediation/registry-parent-ranges.js +21 -0
  45. package/dist/remediation/transitive-chain-resolver.js +3 -3
  46. package/dist/scan/completeness.js +10 -4
  47. package/dist/scan/multi-folder-scan.js +133 -58
  48. package/dist/scan/override-audit.js +6 -4
  49. package/dist/scan/single-scan.js +41 -25
  50. package/dist/scanner.js +263 -58
  51. package/dist/usage/scanner.js +19 -8
  52. package/dist/utils/array.js +11 -3
  53. package/dist/utils/checked-address-policy.js +44 -0
  54. package/dist/utils/debug-bundle.js +118 -0
  55. package/dist/utils/debug-project.js +102 -0
  56. package/dist/utils/debug-redaction.js +117 -0
  57. package/dist/utils/file.js +2 -1
  58. package/dist/utils/fix-runner.js +95 -13
  59. package/dist/utils/import-type-queries.js +322 -0
  60. package/dist/utils/network.js +14 -9
  61. package/dist/utils/npm-lockfile.js +12 -0
  62. package/dist/utils/osv-fetch.js +34 -0
  63. package/dist/utils/package-identity.js +43 -0
  64. package/dist/utils/package-manager-source.js +24 -0
  65. package/dist/utils/purl.js +37 -0
  66. package/dist/utils/registry-config.js +47 -15
  67. package/dist/utils/registry-fetch.js +42 -0
  68. package/dist/utils/shell-quote.js +12 -0
  69. package/dist/utils/string.js +8 -0
  70. package/dist/utils/validate-url.js +1 -1
  71. package/dist/utils/version.js +30 -7
  72. package/dist/utils/versions/osv-range.js +191 -0
  73. package/dist/utils/versions/pep440.js +246 -0
  74. package/dist/utils/versions/scheme.js +10 -0
  75. 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,16 +518,21 @@ 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();
528
+ let registryPolicyBlocked = false;
502
529
  const remediationFailures = new Map();
503
530
  let chainResolutionFailureCount = 0;
504
531
  let directCount = 0;
505
532
  let transitiveCount = 0;
506
533
  await runWithObserver({
507
534
  onTransientFailure(name) { packumentFailures.add(name); },
535
+ onPolicyBlocked() { registryPolicyBlocked = true; },
508
536
  }, async () => {
509
537
  const npmRemediationCache = new Map();
510
538
  const parentUpgradeCache = new Map();
@@ -541,6 +569,9 @@ export async function scanPackages(packages, batchSize, options, context, debugL
541
569
  for (const finding of findings) {
542
570
  if (finding.relationship !== "transitive")
543
571
  continue;
572
+ if (aliasRemediationFindings.has(finding)) {
573
+ continue;
574
+ }
544
575
  packumentsToPrewarm.add(finding.pkg.name);
545
576
  const paths = finding.dependencyPaths;
546
577
  if (paths.length > 0 && paths[0].length >= 2) {
@@ -557,6 +588,11 @@ export async function scanPackages(packages, batchSize, options, context, debugL
557
588
  if (finding.relationship !== "transitive")
558
589
  continue;
559
590
  updateAnalysisProgress("resolving remediation for", `${finding.pkg.name}@${finding.pkg.version}`);
591
+ if (aliasRemediationFindings.has(finding)) {
592
+ 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.`;
593
+ finding.fixVersionValidationNote = [finding.fixVersionValidationNote, aliasNote].filter(Boolean).join(" ");
594
+ continue;
595
+ }
560
596
  const remediationCacheKey = JSON.stringify({
561
597
  package: finding.pkg.name,
562
598
  version: finding.pkg.version,
@@ -591,6 +627,11 @@ export async function scanPackages(packages, batchSize, options, context, debugL
591
627
  confidence: "verified",
592
628
  reason: finding.recommendedNpmTransitiveRemediation.reason,
593
629
  };
630
+ finding.parentUpgradeBlockers = await blockersForParentUpgrade(finding, {
631
+ packages,
632
+ workspaceMemberNames,
633
+ npmGraph: npmTransitiveGraph,
634
+ });
594
635
  continue;
595
636
  }
596
637
  if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
@@ -609,6 +650,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
609
650
  packages,
610
651
  directDependencyNames: context?.directDependencyNames,
611
652
  workspaceMap: lockfileWorkspaceMap,
653
+ parentGraph: lockParentGraph,
612
654
  });
613
655
  npmRemediationCache.set(remediationCacheKey, finding.recommendedNpmTransitiveRemediation ?? null);
614
656
  }
@@ -624,6 +666,12 @@ export async function scanPackages(packages, batchSize, options, context, debugL
624
666
  finding.recommendedParentUpgrade = await resolveRecommendedParentUpgrade(finding, packages, context?.directDependencyNames, { offline });
625
667
  parentUpgradeCache.set(remediationCacheKey, finding.recommendedParentUpgrade ?? null);
626
668
  }
669
+ finding.parentUpgradeBlockers = await blockersForParentUpgrade(finding, {
670
+ packages,
671
+ workspaceMemberNames,
672
+ npmGraph: npmTransitiveGraph,
673
+ lockParentGraph,
674
+ });
627
675
  }
628
676
  catch (error) {
629
677
  const packageName = finding.pkg.name;
@@ -639,11 +687,11 @@ export async function scanPackages(packages, batchSize, options, context, debugL
639
687
  }
640
688
  analysisSpinner.succeed("Analyzed vulnerability findings");
641
689
  // Chain fix resolution: pre-compute validated chain for transitive findings
642
- const chainPm = inferPackageManagerForChain(context?.scanSource);
690
+ const chainPm = packageManagerForSource(context?.scanSource);
643
691
  if (chainPm) {
644
692
  const installedVersions = new Map(packages.map(p => [p.name, p.version]));
645
693
  await Promise.all(findings
646
- .filter(f => f.relationship === "transitive" && f.dependencyPaths?.length)
694
+ .filter(f => f.relationship === "transitive" && f.dependencyPaths?.length && !aliasRemediationFindings.has(f))
647
695
  .map(async (finding) => {
648
696
  try {
649
697
  finding.chainResolution = await resolveChainFix(finding, installedVersions, chainPm, { offline });
@@ -677,6 +725,10 @@ export async function scanPackages(packages, batchSize, options, context, debugL
677
725
  }
678
726
  }
679
727
  });
728
+ if (registryPolicyBlocked && registryConfig.sourceFile) {
729
+ const source = path.basename(registryConfig.sourceFile);
730
+ console.warn(`Warning: The registry from ${source} was blocked because repository settings cannot use plain HTTP or private addresses. To use it, set NPM_CONFIG_REGISTRY for the scan, or on Windows remove the registry from the project's config and set it in your user-level config (~/.npmrc or ~/.yarnrc.yml).`);
731
+ }
680
732
  const severityCounts = countBySeverity(findings);
681
733
  log("Findings classified", {
682
734
  total: findings.length,
@@ -695,6 +747,8 @@ export async function scanPackages(packages, batchSize, options, context, debugL
695
747
  packumentFailures,
696
748
  remediationFailures,
697
749
  chainResolutionFailureCount,
750
+ unreadableBoundaryPackages,
751
+ unreadableFixPackages: findings.filter(finding => finding.advisoryBoundaryUnreadable).length,
698
752
  });
699
753
  const completeness = {
700
754
  complete: diagnostics.length === 0,
@@ -713,6 +767,35 @@ export async function scanPackages(packages, batchSize, options, context, debugL
713
767
  sourceContext.cleanup();
714
768
  }
715
769
  }
770
+ // Direct dependencies that keep the vulnerable copy installed after the
771
+ // recommended parent upgrade, judged against the first safe version (#1457).
772
+ async function blockersForParentUpgrade(finding, graphs) {
773
+ const upgrade = finding.recommendedParentUpgrade;
774
+ // Without a known fixed version, test the child version the upgrade moves to.
775
+ const safeVersion = finding.validatedFirstFixedVersion
776
+ ?? finding.firstFixedVersion
777
+ ?? finding.recommendedNpmTransitiveRemediation?.targetChildVersion;
778
+ if (!upgrade || !safeVersion)
779
+ return undefined;
780
+ const blockers = await findParentUpgradeBlockers({
781
+ childName: finding.pkg.name,
782
+ childVersion: finding.pkg.version,
783
+ targetChildVersion: safeVersion,
784
+ upgradedParent: upgrade.package,
785
+ packages: graphs.packages,
786
+ workspaceMemberNames: graphs.workspaceMemberNames,
787
+ npmGraph: graphs.npmGraph,
788
+ lockParentGraph: graphs.lockParentGraph,
789
+ });
790
+ return blockers.length > 0 ? blockers : undefined;
791
+ }
792
+ function readWorkspaceMemberNames(scanFilePath) {
793
+ if (!scanFilePath)
794
+ return new Set();
795
+ return new Set(readWorkspaceMemberManifests(path.dirname(scanFilePath))
796
+ .map(member => member.manifest.name)
797
+ .filter((name) => typeof name === "string"));
798
+ }
716
799
  function createNpmTransitiveGraphFromLockfile(filePath, log, packageCount) {
717
800
  try {
718
801
  const lockGraph = loadNpmLockGraph(filePath, { includePaths: false });
@@ -733,6 +816,12 @@ function createNpmTransitiveGraphFromLockfile(filePath, log, packageCount) {
733
816
  rangeFor(parentNodeId, childName) {
734
817
  return lockGraph.rangeFor(parentNodeId, childName);
735
818
  },
819
+ parentsFor(nodeId) {
820
+ return lockGraph.parentsFor(nodeId);
821
+ },
822
+ peerRangesFor(nodeId) {
823
+ return lockGraph.peerRangesFor?.(nodeId) ?? [];
824
+ },
736
825
  };
737
826
  }
738
827
  catch (error) {
@@ -743,6 +832,25 @@ function createNpmTransitiveGraphFromLockfile(filePath, log, packageCount) {
743
832
  return null;
744
833
  }
745
834
  }
835
+ // Every parent of each package, for the lockfiles whose remediation goes through
836
+ // the registry. A within-range update has to suit all of them (#1291). Without
837
+ // it the route falls back to the one parent the recorded path names.
838
+ function loadLockParentGraph(source, filePath, log) {
839
+ if (!filePath)
840
+ return null;
841
+ try {
842
+ if (source === "pnpm-lock")
843
+ return loadPnpmLockGraph(filePath);
844
+ if (source === "yarn-lock")
845
+ return loadYarnLockGraph(filePath);
846
+ if (source === "bun-lock")
847
+ return loadBunLockGraph(filePath);
848
+ }
849
+ catch (error) {
850
+ log("lock parent graph", { status: "failed", error: extractErrorMessage(error) });
851
+ }
852
+ return null;
853
+ }
746
854
  async function validateDirectFixTargets(findings, onFinding, options) {
747
855
  const directCandidates = findings.filter(finding => finding.vulnerabilities.length > 0);
748
856
  const results = await runWithConcurrency(directCandidates, 8, async (finding) => {
@@ -752,6 +860,8 @@ async function validateDirectFixTargets(findings, onFinding, options) {
752
860
  return results.some(Boolean);
753
861
  }
754
862
  async function validateOneDirectFixTarget(finding, options) {
863
+ if (finding.advisoryBoundaryUnreadable)
864
+ return false;
755
865
  let npmVersionCacheUpdated = false;
756
866
  const debugLog = options?.debugLog;
757
867
  const logFixValidation = () => {
@@ -764,14 +874,14 @@ async function validateOneDirectFixTarget(finding, options) {
764
874
  };
765
875
  // The advisory source re-checks the proposed version for advisories
766
876
  // 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 });
877
+ const lowestKnownResolution = await resolveLowestKnownNonVulnerableVersion(registryPackageName(finding.pkg), finding.pkg.version, finding.vulnerabilities, { advisorySource: options?.advisorySource, proposedVersion: finding.firstFixedVersion });
768
878
  const fixedVersionHint = finding.firstFixedVersion;
769
879
  const setPublishedDate = (resolution) => {
770
880
  const date = resolution.publishedAt;
771
881
  finding.fixVersionPublishedAt = date;
772
882
  if (!date || !options?.cache)
773
883
  return;
774
- const cacheKey = `${finding.pkg.name}@${finding.validatedFirstFixedVersion}`;
884
+ const cacheKey = `${registryPackageName(finding.pkg)}@${finding.validatedFirstFixedVersion}`;
775
885
  const existing = options.cache.npmVersionEntries?.[cacheKey];
776
886
  if (!options.noCache && existing?.publishedAt === date)
777
887
  return;
@@ -792,7 +902,7 @@ async function validateOneDirectFixTarget(finding, options) {
792
902
  logFixValidation();
793
903
  return npmVersionCacheUpdated;
794
904
  }
795
- const hintResolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
905
+ const hintResolution = await resolvePublishedFixVersion(registryPackageName(finding.pkg), fixedVersionHint);
796
906
  if (hintResolution.resolvedVersion === lowestKnownResolution.resolvedVersion &&
797
907
  hintResolution.note) {
798
908
  finding.fixVersionValidationNote = hintResolution.note;
@@ -817,7 +927,7 @@ async function validateOneDirectFixTarget(finding, options) {
817
927
  logFixValidation();
818
928
  return npmVersionCacheUpdated;
819
929
  }
820
- const resolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
930
+ const resolution = await resolvePublishedFixVersion(registryPackageName(finding.pkg), fixedVersionHint);
821
931
  // Publication confirms availability, not that every advisory is fixed.
822
932
  finding.validatedFirstFixedVersion = null;
823
933
  finding.fixVersionValidationNote = [
@@ -888,18 +998,18 @@ function affectedEntryMatchesPackage(affected, packageName, ecosystem) {
888
998
  * `introduced` of "0" (or absent) means the window has no lower bound, which is
889
999
  * how OSV expresses "every version before the fix".
890
1000
  */
891
- function versionWithinAffectedWindow(version, introduced, fixed) {
1001
+ function versionWithinAffectedWindow(version, introduced, fixed, ecosystem) {
892
1002
  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);
1003
+ // Advisories write boundaries with fewer than three components. Semver pads
1004
+ // `2` to 2.0.0. PEP 440 keeps `2`, which compares equal to 2.0.0. A value
1005
+ // that is not a version at all still returns null and the window is skipped.
1006
+ const normalizedIntroduced = normalizeAdvisoryVersion(introduced, ecosystem);
897
1007
  if (!normalizedIntroduced)
898
1008
  return false;
899
- if (compareVersions(version, normalizedIntroduced) < 0)
1009
+ if (compareVersions(version, normalizedIntroduced, ecosystem) < 0)
900
1010
  return false;
901
1011
  }
902
- return compareVersions(version, fixed) < 0;
1012
+ return compareVersions(version, fixed, ecosystem) < 0;
903
1013
  }
904
1014
  /**
905
1015
  * Every usable fixed version one advisory declares for this package, split into
@@ -928,16 +1038,18 @@ function collectAdvisoryFixes(vuln, packageName, ecosystem, installedVersion) {
928
1038
  introduced = event.introduced;
929
1039
  continue;
930
1040
  }
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))
1041
+ // `fixed: "1.22"` is 1.22.0 for npm. PEP 440 keeps `1.22`, which compares
1042
+ // equal to 1.22.0, and a post-release such as `2026.3.post1` stays a fix.
1043
+ // Requiring a strict X.Y.Z here discarded the event, and a finding whose
1044
+ // every candidate was discarded reported "no fix available", which tells
1045
+ // a developer to stop looking for a fix that exists (#1192). A value that
1046
+ // cannot be read in full is still dropped, so a commit hash from a GIT
1047
+ // range never becomes a fix version.
1048
+ const fixed = normalizeAdvisoryVersion(event.fixed, ecosystem);
1049
+ if (!fixed || isPreReleaseVersion(fixed, ecosystem))
938
1050
  continue;
939
1051
  all.push(fixed);
940
- if (installedVersion && versionWithinAffectedWindow(installedVersion, introduced, fixed)) {
1052
+ if (installedVersion && versionWithinAffectedWindow(installedVersion, introduced, fixed, ecosystem)) {
941
1053
  onInstalledBranch.push(fixed);
942
1054
  }
943
1055
  introduced = null;
@@ -947,29 +1059,120 @@ function collectAdvisoryFixes(vuln, packageName, ecosystem, installedVersion) {
947
1059
  return { all, onInstalledBranch };
948
1060
  }
949
1061
  export function findFirstFixedVersion(vulns, packageName, ecosystem, installedVersion) {
1062
+ return selectFixedVersion(vulns, packageName, ecosystem, installedVersion).version;
1063
+ }
1064
+ /**
1065
+ * The fix to recommend, and whether a PyPI boundary that might contain the
1066
+ * installed version could not be read. An unreadable boundary leaves the
1067
+ * version null and does not stop the scan. npm never sets `unreadable`.
1068
+ */
1069
+ export function selectFixedVersion(vulns, packageName, ecosystem, installedVersion) {
1070
+ if (isPep440Ecosystem(ecosystem)) {
1071
+ return selectPep440FixedVersion(vulns, packageName, ecosystem, installedVersion);
1072
+ }
1073
+ return {
1074
+ version: selectNpmFixedVersion(vulns, packageName, ecosystem, installedVersion),
1075
+ unreadable: false,
1076
+ };
1077
+ }
1078
+ function selectNpmFixedVersion(vulns, packageName, ecosystem, installedVersion) {
950
1079
  const everyKnownFix = [];
951
1080
  // One entry per advisory: the earliest version clearing THAT advisory on the
952
1081
  // branch the install sits on.
953
1082
  const perAdvisoryFixes = [];
1083
+ const byVersion = (left, right) => compareVersions(left, right, ecosystem);
954
1084
  for (const vuln of vulns) {
955
1085
  const { all, onInstalledBranch } = collectAdvisoryFixes(vuln, packageName, ecosystem, installedVersion);
956
1086
  everyKnownFix.push(...all);
957
1087
  if (onInstalledBranch.length > 0) {
958
1088
  // Lowest WITHIN one advisory: the branch fix, not the other branch's.
959
- perAdvisoryFixes.push(onInstalledBranch.sort(compareVersions)[0]);
1089
+ perAdvisoryFixes.push(onInstalledBranch.sort(byVersion)[0]);
960
1090
  }
961
1091
  }
962
1092
  // Highest ACROSS advisories: the caller needs a version clear of all of them,
963
1093
  // and stopping at the lowest leaves every advisory fixed above it still live.
964
1094
  if (perAdvisoryFixes.length > 0) {
965
- return perAdvisoryFixes.sort(compareVersions)[perAdvisoryFixes.length - 1];
1095
+ return perAdvisoryFixes.sort(byVersion)[perAdvisoryFixes.length - 1];
966
1096
  }
967
1097
  // No declared window contains the installed version, so there is no branch to
968
1098
  // scope to. Falling back to every known fix keeps a finding's remediation
969
1099
  // visible rather than reporting none.
970
1100
  if (everyKnownFix.length === 0)
971
1101
  return null;
972
- return everyKnownFix.sort(compareVersions)[0];
1102
+ return everyKnownFix.sort(byVersion)[0];
1103
+ }
1104
+ function selectPep440FixedVersion(vulns, packageName, ecosystem, installedVersion) {
1105
+ if (installedVersion && !looksLikeVersion(installedVersion, ecosystem)) {
1106
+ return { version: null, unreadable: true };
1107
+ }
1108
+ const everyKnownFix = [];
1109
+ const perAdvisoryFixes = [];
1110
+ let unreadable = false;
1111
+ let blocked = false;
1112
+ const byVersion = (left, right) => compareVersions(left, right, ecosystem);
1113
+ for (const vuln of vulns) {
1114
+ const branchFixes = [];
1115
+ let advisoryUnreadable = false;
1116
+ let heldWithoutFix = false;
1117
+ for (const affected of vuln.affected ?? []) {
1118
+ if (!affectedEntryMatchesPackage(affected, packageName, ecosystem))
1119
+ continue;
1120
+ for (const range of affected.ranges ?? []) {
1121
+ const rangeType = range.type;
1122
+ if (rangeType === "GIT")
1123
+ continue;
1124
+ if (rangeType && rangeType !== "ECOSYSTEM" && rangeType !== "SEMVER")
1125
+ continue;
1126
+ const read = readPep440Range(range.events ?? []);
1127
+ if (!installedVersion) {
1128
+ if (read.unreadable.length > 0)
1129
+ advisoryUnreadable = true;
1130
+ }
1131
+ else if (read.unreadable.some(boundary => pep440UnreadableApplies(installedVersion, boundary))) {
1132
+ advisoryUnreadable = true;
1133
+ }
1134
+ for (const fix of read.fixes) {
1135
+ if (!isPreReleaseVersion(fix, ecosystem))
1136
+ everyKnownFix.push(fix);
1137
+ }
1138
+ if (!installedVersion)
1139
+ continue;
1140
+ for (const window of read.windows) {
1141
+ if (!versionInPep440Window(installedVersion, window))
1142
+ continue;
1143
+ if (window.fixed && !isPreReleaseVersion(window.fixed, ecosystem))
1144
+ branchFixes.push(window.fixed);
1145
+ else
1146
+ heldWithoutFix = true;
1147
+ }
1148
+ }
1149
+ }
1150
+ if (advisoryUnreadable) {
1151
+ unreadable = true;
1152
+ continue;
1153
+ }
1154
+ if (heldWithoutFix)
1155
+ blocked = true;
1156
+ else if (branchFixes.length > 0)
1157
+ perAdvisoryFixes.push(branchFixes.sort(byVersion)[0]);
1158
+ }
1159
+ if (unreadable)
1160
+ return { version: null, unreadable: true };
1161
+ if (blocked)
1162
+ return { version: null, unreadable: false };
1163
+ if (perAdvisoryFixes.length > 0) {
1164
+ return { version: perAdvisoryFixes.sort(byVersion)[perAdvisoryFixes.length - 1], unreadable: false };
1165
+ }
1166
+ // No window contains the installed version. A fix it has already reached can
1167
+ // still be named (a patched 2.x build still names the 1.x fix). A later fix
1168
+ // it has not reached belongs to another window, and recommending it would
1169
+ // treat an unaffected version as vulnerable.
1170
+ if (everyKnownFix.length === 0)
1171
+ return { version: null, unreadable: false };
1172
+ if (installedVersion && everyKnownFix.every(fix => byVersion(installedVersion, fix) < 0)) {
1173
+ return { version: null, unreadable: false };
1174
+ }
1175
+ return { version: everyKnownFix.sort(byVersion)[0], unreadable: false };
973
1176
  }
974
1177
  function buildCompletenessDiagnostics(params) {
975
1178
  const diagnostics = [];
@@ -979,7 +1182,7 @@ function buildCompletenessDiagnostics(params) {
979
1182
  diagnostics.push({
980
1183
  code,
981
1184
  severity: "warning",
982
- message: formatDiagnosticMessage(code, count, affectedPackageCount),
1185
+ message: formatDiagnosticMessage(code, count, affectedPackageCount, impact),
983
1186
  impact,
984
1187
  count,
985
1188
  ...(affectedPackageCount === undefined ? {} : { affectedPackageCount }),
@@ -992,6 +1195,8 @@ function buildCompletenessDiagnostics(params) {
992
1195
  addDiagnostic("PACKUMENT_FETCH_FAILURE", params.packumentFailures.size, "remediation");
993
1196
  addDiagnostic("REMEDIATION_FAILURE", remediationTotal, "remediation", params.remediationFailures.size);
994
1197
  addDiagnostic("CHAIN_RESOLUTION_FAILURE", params.chainResolutionFailureCount, "remediation");
1198
+ addDiagnostic("UNREADABLE_PYPI_BOUNDARY", params.unreadableBoundaryPackages, "detection");
1199
+ addDiagnostic("UNREADABLE_PYPI_BOUNDARY", params.unreadableFixPackages, "remediation");
995
1200
  return diagnostics;
996
1201
  }
997
1202
  async function enrichWithEpssScores(findings, fetchImpl) {