verdaccio-security-filter 1.9.1 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -130,7 +130,7 @@ These wait for a concrete request:
130
130
  ### Prerequisites
131
131
 
132
132
  - Node.js >= 22.0.0
133
- - Verdaccio >= 5.0.0; 7.x recommended. Verdaccio 6 depends on a `minimatch` version with a known denial-of-service issue ([GHSA-g3hv-75wg-m249](https://github.com/advisories/GHSA-g3hv-75wg-m249)), fixed in Verdaccio 7.
133
+ - Verdaccio >= 5.0.0; 7.x or 6.11.4+ recommended. Verdaccio 6 releases before 6.11.4 depend on a `minimatch` version with known denial-of-service issues ([GHSA-g3hv-75wg-m249](https://github.com/advisories/GHSA-g3hv-75wg-m249)); 6.11.4 ships `minimatch` 11.0.9, outside the affected ranges.
134
134
 
135
135
  ```bash
136
136
  npm install -g verdaccio
@@ -165,7 +165,7 @@ npm then resolves ranges against the versions that are left.
165
165
  ### Layer 2: Middleware (`register_middlewares`)
166
166
  Runs first on every `GET` request:
167
167
  1. Blocks packages by name: whitelist, patterns, scopes
168
- 2. Blocks tarball downloads of blocked versions, even if a client has stale metadata or a lockfile. This covers the versions layer 1 removed (CVE, license, signatures, provenance, age, author): `npm ci` downloads the tarballs pinned in `package-lock.json` without asking for the metadata, so for a tarball without a decision younger than 5 minutes, or one for a version published after the decision, the middleware loads the package metadata through Verdaccio's storage, which runs layer 1. Parallel requests for a package share one load, and only clients that may read the package trigger it. The cost is one metadata load per package per 5 minutes during `npm ci`, which reaches the uplink when Verdaccio's cached copy is older than the uplink's `maxage`. If the metadata cannot be loaded, the tarball is served, or refused with `errorHandling.onFilterError: fail-closed`; the load is retried after 30 seconds. Needs both layers configured.
168
+ 2. Blocks tarball downloads of blocked versions, even if a client has stale metadata or a lockfile. This covers the versions layer 1 removed (CVE, license, signatures, provenance, age, author): `npm ci` downloads the tarballs pinned in `package-lock.json` without asking for the metadata, so for a tarball without a decision younger than 5 minutes, or one for a version published after the decision, the middleware loads the package metadata through Verdaccio's storage, which runs layer 1. Parallel requests for a package share one load, and only clients that may read the package trigger it. The cost is one metadata load per package per 5 minutes during `npm ci`, which reaches the uplink when Verdaccio's cached copy is older than the uplink's `maxage`. If the metadata cannot be loaded, the tarball is served, or refused with `errorHandling.onFilterError: fail-closed`; the load is retried after 30 seconds. The 403 names the check that removed the version, e.g. `Version 1.0.0 was removed by the security filter: License 'GPL-3.0' is not in allowed list`. Needs both layers configured.
169
169
  3. Turns a whole-package block from layer 1 into an HTTP error that carries the reason
170
170
 
171
171
  ### What a client sees
package/build/index.js CHANGED
@@ -67,6 +67,7 @@ const warnedAt = new lru_cache_1.LRUCache(10000);
67
67
  const WARN_REPEAT_MS = 10 * 60 * 1000;
68
68
  const TARBALL_DECISION_MS = 5 * 60 * 1000;
69
69
  const RETRY_LOAD_MS = 30 * 1000;
70
+ const REMOVAL_REASONS = Symbol('removalReasons');
70
71
  const tarballDecisions = new lru_cache_1.LRUCache(5000);
71
72
  const metadataLoads = new Map();
72
73
  const loadAttempts = new lru_cache_1.LRUCache(10000);
@@ -334,10 +335,14 @@ class SecurityFilterPlugin {
334
335
  mode: this.config.mode || 'blacklist',
335
336
  }, blockedAt: new Date().toISOString() }) });
336
337
  }
337
- _removeVersions(pkg, removed) {
338
+ _removeVersions(pkg, removed, reason) {
338
339
  if (removed.length === 0) {
339
340
  return pkg;
340
341
  }
342
+ const reasons = Object.assign({}, pkg[REMOVAL_REASONS]);
343
+ for (const version of removed) {
344
+ reasons[version] = typeof reason === 'function' ? reason(version) : reason;
345
+ }
341
346
  const gone = new Set(removed);
342
347
  const versions = Object.assign({}, pkg.versions);
343
348
  for (const version of gone) {
@@ -350,7 +355,7 @@ class SecurityFilterPlugin {
350
355
  this.logger.debug(`[filter_metadata] Removed dist-tag "${tag}" pointing to filtered version ${tagVersion}`);
351
356
  }
352
357
  }
353
- return Object.assign(Object.assign({}, pkg), { versions, 'dist-tags': distTags });
358
+ return Object.assign(Object.assign({}, pkg), { versions, 'dist-tags': distTags, [REMOVAL_REASONS]: reasons });
354
359
  }
355
360
  _rejectedVersions(pkg, check) {
356
361
  var _a;
@@ -368,13 +373,15 @@ class SecurityFilterPlugin {
368
373
  }
369
374
  filter_metadata(packageInfo) {
370
375
  return __awaiter(this, void 0, void 0, function* () {
376
+ var _a;
371
377
  const filtered = yield this._filterMetadata(packageInfo);
372
378
  if (!this.config.dryRun) {
373
379
  const left = filtered.versions || {};
374
380
  const seen = Object.keys(packageInfo.versions || {});
381
+ const reasons = (_a = filtered[REMOVAL_REASONS]) !== null && _a !== void 0 ? _a : {};
375
382
  tarballDecisions.set(packageInfo.name, {
376
383
  seen: new Set(seen),
377
- removed: new Set(seen.filter(version => !(version in left))),
384
+ removed: new Map(seen.filter(version => !(version in left)).map(version => { var _a; return [version, (_a = reasons[version]) !== null && _a !== void 0 ? _a : '']; })),
378
385
  filtered: true,
379
386
  at: Date.now(),
380
387
  });
@@ -416,7 +423,7 @@ class SecurityFilterPlugin {
416
423
  if (ruleBlocked.length > 0) {
417
424
  this.logger.warn(`[filter_metadata] RULE FILTERED: ${packageName}: ${ruleBlocked.join(', ')}`);
418
425
  this.metrics.recordFiltered(packageName, ruleBlocked, 'Version blocked by rules');
419
- pkg = this._removeVersions(pkg, ruleBlocked);
426
+ pkg = this._removeVersions(pkg, ruleBlocked, 'Version blocked by rules');
420
427
  }
421
428
  }
422
429
  if ((_a = this.config.cveCheck) === null || _a === void 0 ? void 0 : _a.enabled) {
@@ -447,7 +454,7 @@ class SecurityFilterPlugin {
447
454
  }
448
455
  this.logger.warn(`[filter_metadata] CVE FILTERED: ${packageName} - ${reason}: ${vulnerableVersions.join(', ')}`);
449
456
  this.metrics.recordFiltered(packageName, vulnerableVersions, reason);
450
- pkg = this._removeVersions(pkg, vulnerableVersions);
457
+ pkg = this._removeVersions(pkg, vulnerableVersions, reason);
451
458
  }
452
459
  }
453
460
  if (this.licenseChecker.enabled) {
@@ -461,7 +468,8 @@ class SecurityFilterPlugin {
461
468
  if (rejected.versions.length > 0) {
462
469
  this.logger.warn(`[filter_metadata] LICENSE FILTERED: ${packageName}: ${rejected.versions.join(', ')}`);
463
470
  this.metrics.recordFiltered(packageName, rejected.versions, 'License not allowed');
464
- pkg = this._removeVersions(pkg, rejected.versions);
471
+ const licenseReasons = new Map(rejected.results.map(([version, result]) => [version, result.reason]));
472
+ pkg = this._removeVersions(pkg, rejected.versions, version => licenseReasons.get(version) || 'License not allowed');
465
473
  }
466
474
  }
467
475
  if (this.signatureChecker.enabled) {
@@ -493,9 +501,9 @@ class SecurityFilterPlugin {
493
501
  if (versions.length > 0) {
494
502
  this.logger.warn(`[filter_metadata] SIGNATURE FILTERED: ${packageName}: ${versions.join(', ')} - ${reason}`);
495
503
  this.metrics.recordFiltered(packageName, versions, reason);
504
+ pkg = this._removeVersions(pkg, versions, reason);
496
505
  }
497
506
  }
498
- pkg = this._removeVersions(pkg, [...invalid, ...missing]);
499
507
  }
500
508
  if (this.provenanceChecker.enabled
501
509
  && !(this.config.mode !== 'whitelist' && this.config.whitelist
@@ -523,8 +531,8 @@ class SecurityFilterPlugin {
523
531
  for (const [reason, versions] of byReason) {
524
532
  this.logger.warn(`[filter_metadata] PROVENANCE FILTERED: ${packageName}: ${versions.join(', ')} - ${reason}`);
525
533
  this.metrics.recordFiltered(packageName, versions, reason);
534
+ pkg = this._removeVersions(pkg, versions, reason);
526
535
  }
527
- pkg = this._removeVersions(pkg, rejected.map(r => r.version));
528
536
  }
529
537
  if ((_c = this.config.packageAge) === null || _c === void 0 ? void 0 : _c.enabled) {
530
538
  const ageResult = this.packageAgeChecker.checkPackageAge(pkg);
@@ -559,7 +567,7 @@ class SecurityFilterPlugin {
559
567
  if (removedVersions.length > 0) {
560
568
  this.logger.warn(`[filter_metadata] VERSION AGE FILTERED: ${packageName}: ${removedVersions.join(', ')}`);
561
569
  this.metrics.recordFiltered(packageName, removedVersions, 'Version too new');
562
- pkg = this._removeVersions(pkg, removedVersions);
570
+ pkg = this._removeVersions(pkg, removedVersions, 'Version too new');
563
571
  }
564
572
  }
565
573
  }
@@ -586,7 +594,8 @@ class SecurityFilterPlugin {
586
594
  }
587
595
  this.logger.warn(`[filter_metadata] AUTHOR FILTERED: ${packageName}: ${rejected.versions.join(', ')}`);
588
596
  this.metrics.recordFiltered(packageName, rejected.versions, reason, 'author_blocked', details);
589
- pkg = this._removeVersions(pkg, rejected.versions);
597
+ const authorReasons = new Map(rejected.results.map(([version, result]) => [version, result.reason]));
598
+ pkg = this._removeVersions(pkg, rejected.versions, version => authorReasons.get(version) || reason);
590
599
  }
591
600
  }
592
601
  this.logger.debug(`[filter_metadata] [OK] ALLOWED: ${packageName}`);
@@ -644,14 +653,17 @@ class SecurityFilterPlugin {
644
653
  }
645
654
  decision = tarballDecisions.get(packageName);
646
655
  if (!isFresh(decision)) {
647
- tarballDecisions.set(packageName, { seen: new Set(), removed: new Set(), filtered: false, at: Date.now() });
656
+ tarballDecisions.set(packageName, { seen: new Set(), removed: new Map(), filtered: false, at: Date.now() });
648
657
  return null;
649
658
  }
650
659
  }
651
660
  if (!decision.removed.has(version)) {
652
661
  return null;
653
662
  }
654
- return ((_b = (_a = filterBlocks.get(packageName)) === null || _a === void 0 ? void 0 : _a.security) === null || _b === void 0 ? void 0 : _b.reason) || `Version ${version} was removed by the security filter`;
663
+ const reason = decision.removed.get(version) || ((_b = (_a = filterBlocks.get(packageName)) === null || _a === void 0 ? void 0 : _a.security) === null || _b === void 0 ? void 0 : _b.reason);
664
+ return reason
665
+ ? `Version ${version} was removed by the security filter: ${reason}`
666
+ : `Version ${version} was removed by the security filter`;
655
667
  });
656
668
  }
657
669
  _unchecked() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verdaccio-security-filter",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Verdaccio security plugin: block vulnerable (CVE/OSV), malicious and newly published npm packages in your private registry to stop supply chain attacks",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",