verdaccio-security-filter 1.7.0 → 1.8.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
@@ -72,6 +72,7 @@ This plugin implements **two independent security layers** for complete protecti
72
72
  - **Minimum Version Age** - Require specific versions to exist for a minimum number of days
73
73
  - **Warn-Only Mode** - Log warnings without blocking
74
74
  - **Registry Signature Verification** - Remove versions whose npm registry signature does not verify
75
+ - **Provenance Downgrade Detection** - Remove versions published without npm provenance after the package started publishing with it
75
76
  - **Typosquatting Detection** - Block names one typo away from a popular npm package or your own protected names (`lodahs`, `expres`)
76
77
  - **Author Filtering** - Block packages based on author information
77
78
  - **Block by Author Name** - Block specific author names or patterns
@@ -109,12 +110,13 @@ Nothing right now; open an issue with a request.
109
110
  These wait for a concrete request:
110
111
  - **Snyk integration** - OSV already includes GitHub Security Advisories, so a second source only helps if it knows more
111
112
  - **Auto-approve criteria** - approve by npm statistics; needs external requests on the request path
112
- - **Provenance attestations** - verify Sigstore provenance; needs a new dependency and requests to the registry
113
+ - **Sigstore verification of provenance** - verify the attestation bundle itself; needs a new dependency and requests to the registry
113
114
  - **CLI tool** and **GitHub Action** for checking a rule set outside Verdaccio
114
115
 
115
116
  #### Done
116
117
  - [x] **Dry-run mode** - `dryRun: true`
117
118
  - [x] **Registry signature verification** - `signatures`: npm registry signatures (ECDSA)
119
+ - [x] **Provenance attestations** - `provenance`: presence and downgrade detection
118
120
  - [x] **Typosquatting detection** - `typosquatting`: names within a small edit distance of popular packages
119
121
  - [x] **Webhook notifications** - `webhook`: block events as JSON or as a Slack message
120
122
 
@@ -617,6 +619,25 @@ signatures:
617
619
  onMissing: warn
618
620
  ```
619
621
 
622
+ ### Provenance Options
623
+
624
+ | Option | Type | Default | Description |
625
+ |--------|------|---------|-------------|
626
+ | `provenance.enabled` | `boolean` | `false` | Check npm provenance attestations |
627
+ | `provenance.onDowngrade` | `'allow' \| 'warn' \| 'block'` | `'block'` | Versions without provenance published after the first version with it |
628
+ | `provenance.onMissing` | `'allow' \| 'warn' \| 'block'` | `'allow'` | Packages that never published with provenance |
629
+
630
+ A version published from CI with `npm publish --provenance` carries a [provenance attestation](https://docs.npmjs.com/generating-provenance-statements) (`dist.attestations`, SLSA predicate type). Registry signatures do not help when an author's account or token is stolen: npm signs such a version honestly. A stolen token is usually used outside the project's CI, so the new version arrives without provenance while earlier versions had it. That is a *downgrade*: a version without provenance published after the earliest version with it. With the default `onDowngrade: block` it is removed from the metadata, so npm resolves the previous version; the package is blocked only when no version is left.
631
+
632
+ Versions published before the package adopted provenance are kept. A version without a publish time counts as published last, and when any attested version has no publish time, every version without provenance counts as a downgrade. Most packages have never published with provenance, hence `onMissing: allow`; `warn` logs one warning per package at most every 10 minutes. A maintainer who once publishes by hand triggers a downgrade: in blacklist mode, add the package to `whitelist.packages` or `whitelist.patterns` to skip the check. In whitelist mode every served package is on the list, so all of them are checked; use `onDowngrade: warn` there if a skip is needed. The attestation is detected, not cryptographically verified, and tarball requests are not checked, the same as registry signatures.
633
+
634
+ ```yaml
635
+ provenance:
636
+ enabled: true
637
+ onDowngrade: block
638
+ onMissing: allow
639
+ ```
640
+
620
641
  ### Error Handling Options
621
642
 
622
643
  | Option | Type | Default | Description |
package/build/index.d.ts CHANGED
@@ -16,7 +16,9 @@ export default class SecurityFilterPlugin implements IPluginMiddleware<SecurityC
16
16
  private readonly authorChecker;
17
17
  private readonly typosquatChecker;
18
18
  private readonly signatureChecker;
19
+ private readonly provenanceChecker;
19
20
  private readonly unsignedWarnedAt;
21
+ private readonly provenanceWarnedAt;
20
22
  private readonly typosquatWarnedAt;
21
23
  constructor(config: SecurityConfig, options: PluginOptions<SecurityConfig>);
22
24
  private _parseVersionRangeRules;
@@ -46,4 +48,5 @@ export { PackageAgeChecker } from './lib/package-age-checker';
46
48
  export { AuthorChecker } from './lib/author-checker';
47
49
  export { TyposquatChecker } from './lib/typosquat-checker';
48
50
  export { SignatureChecker } from './lib/signature-checker';
51
+ export { ProvenanceChecker } from './lib/provenance-checker';
49
52
  export * from './types';
package/build/index.js CHANGED
@@ -45,7 +45,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
45
45
  });
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.SignatureChecker = exports.TyposquatChecker = exports.AuthorChecker = exports.PackageAgeChecker = exports.LicenseChecker = exports.CVEChecker = exports.WhitelistChecker = exports.WebhookNotifier = exports.MetricsCollector = exports.SecurityLogger = void 0;
48
+ exports.ProvenanceChecker = exports.SignatureChecker = exports.TyposquatChecker = exports.AuthorChecker = exports.PackageAgeChecker = exports.LicenseChecker = exports.CVEChecker = exports.WhitelistChecker = exports.WebhookNotifier = exports.MetricsCollector = exports.SecurityLogger = void 0;
49
49
  const semver = __importStar(require("semver"));
50
50
  const fs_1 = require("fs");
51
51
  const path_1 = require("path");
@@ -58,6 +58,7 @@ const package_age_checker_1 = require("./lib/package-age-checker");
58
58
  const author_checker_1 = require("./lib/author-checker");
59
59
  const typosquat_checker_1 = require("./lib/typosquat-checker");
60
60
  const signature_checker_1 = require("./lib/signature-checker");
61
+ const provenance_checker_1 = require("./lib/provenance-checker");
61
62
  const lru_cache_1 = require("./lib/lru-cache");
62
63
  const webhook_1 = require("./lib/webhook");
63
64
  const PLUGIN_VERSION = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', 'package.json'), 'utf8')).version;
@@ -69,6 +70,7 @@ function forbiddenBody(packageName, reason, extra = {}) {
69
70
  class SecurityFilterPlugin {
70
71
  constructor(config, options) {
71
72
  this.unsignedWarnedAt = new lru_cache_1.LRUCache(5000);
73
+ this.provenanceWarnedAt = new lru_cache_1.LRUCache(5000);
72
74
  this.typosquatWarnedAt = new lru_cache_1.LRUCache(5000);
73
75
  this.config = config || {};
74
76
  if (!this.config.errorHandling) {
@@ -87,6 +89,7 @@ class SecurityFilterPlugin {
87
89
  this.authorChecker = new author_checker_1.AuthorChecker(this.config.authorFilter);
88
90
  this.typosquatChecker = new typosquat_checker_1.TyposquatChecker(this.config.typosquatting);
89
91
  this.signatureChecker = new signature_checker_1.SignatureChecker(this.config.signatures);
92
+ this.provenanceChecker = new provenance_checker_1.ProvenanceChecker(this.config.provenance);
90
93
  this.securityRules = {
91
94
  blockedVersions: this.config.blockedVersions || [],
92
95
  blockedPatterns: this.config.blockedPatterns || [],
@@ -158,7 +161,7 @@ class SecurityFilterPlugin {
158
161
  }
159
162
  }
160
163
  _getEnabledFeatures() {
161
- var _a, _b, _c, _d, _e, _f;
164
+ var _a, _b, _c, _d, _e, _f, _g;
162
165
  const features = [];
163
166
  if (this.config.dryRun)
164
167
  features.push('dry-run');
@@ -180,6 +183,8 @@ class SecurityFilterPlugin {
180
183
  features.push('typosquat-detection');
181
184
  if ((_f = this.config.signatures) === null || _f === void 0 ? void 0 : _f.enabled)
182
185
  features.push('registry-signatures');
186
+ if ((_g = this.config.provenance) === null || _g === void 0 ? void 0 : _g.enabled)
187
+ features.push('provenance');
183
188
  if (this.securityRules.versionRangeRules.length > 0)
184
189
  features.push('version-range-rules');
185
190
  if (this.securityRules.blockedPatterns.length > 0)
@@ -370,7 +375,7 @@ class SecurityFilterPlugin {
370
375
  }
371
376
  _filterMetadata(packageInfo) {
372
377
  return __awaiter(this, void 0, void 0, function* () {
373
- var _a, _b, _c, _d, _e, _f;
378
+ var _a, _b, _c, _d, _e, _f, _g;
374
379
  let pkg = packageInfo;
375
380
  const packageName = pkg.name;
376
381
  this.logger.debug(`[filter_metadata] --> Processing: ${packageName}`);
@@ -469,7 +474,37 @@ class SecurityFilterPlugin {
469
474
  }
470
475
  pkg = this._removeVersions(pkg, [...invalid, ...missing]);
471
476
  }
472
- if ((_d = this.config.packageAge) === null || _d === void 0 ? void 0 : _d.enabled) {
477
+ if (this.provenanceChecker.enabled
478
+ && !(this.config.mode !== 'whitelist' && this.config.whitelist
479
+ && this.whitelistChecker.isWhitelisted(packageName).allowed)) {
480
+ const remaining = new Set(Object.keys(pkg.versions || {}));
481
+ const results = this.provenanceChecker.check(packageInfo).filter(r => remaining.has(r.version));
482
+ const warned = results.filter(r => r.warn);
483
+ const now = Date.now();
484
+ if (warned.length > 0 && now - ((_d = this.provenanceWarnedAt.get(packageName)) !== null && _d !== void 0 ? _d : -Infinity) >= WARN_REPEAT_MS) {
485
+ this.provenanceWarnedAt.set(packageName, now);
486
+ this.logger.warn(`[filter_metadata] PROVENANCE WARNING: ${packageName}: ${warned.length} version(s) - ${warned[0].reason}`);
487
+ }
488
+ const rejected = results.filter(r => !r.allowed);
489
+ if (results.length > 0 && rejected.length === results.length) {
490
+ const reason = rejected[0].reason || 'Provenance check failed';
491
+ this.logger.warn(`[filter_metadata] PROVENANCE BLOCKED: ${packageName} - ${reason}`);
492
+ this.metrics.recordBlock(packageName, '*', reason);
493
+ return this._blockedPackage(pkg, reason);
494
+ }
495
+ const byReason = new Map();
496
+ rejected.forEach((r) => {
497
+ var _a;
498
+ const reason = r.reason || 'Provenance check failed';
499
+ byReason.set(reason, [...((_a = byReason.get(reason)) !== null && _a !== void 0 ? _a : []), r.version]);
500
+ });
501
+ for (const [reason, versions] of byReason) {
502
+ this.logger.warn(`[filter_metadata] PROVENANCE FILTERED: ${packageName}: ${versions.join(', ')} - ${reason}`);
503
+ this.metrics.recordFiltered(packageName, versions, reason);
504
+ }
505
+ pkg = this._removeVersions(pkg, rejected.map(r => r.version));
506
+ }
507
+ if ((_e = this.config.packageAge) === null || _e === void 0 ? void 0 : _e.enabled) {
473
508
  const ageResult = this.packageAgeChecker.checkPackageAge(pkg);
474
509
  if (!ageResult.allowed && !ageResult.warnOnly) {
475
510
  const reason = ageResult.reason || 'Package too new';
@@ -498,7 +533,7 @@ class SecurityFilterPlugin {
498
533
  }
499
534
  }
500
535
  }
501
- if ((_e = this.config.authorFilter) === null || _e === void 0 ? void 0 : _e.enabled) {
536
+ if ((_f = this.config.authorFilter) === null || _f === void 0 ? void 0 : _f.enabled) {
502
537
  const rejected = this._rejectedVersions(pkg, data => this.authorChecker.checkAuthor(data));
503
538
  if (rejected.versions.length > 0 && this.config.authorFilter.warnOnly) {
504
539
  this.logger.warn(`[filter_metadata] AUTHOR WARNING: ${packageName}: ${rejected.versions.join(', ')} - ${rejected.first.reason} (warn-only mode)`);
@@ -528,7 +563,7 @@ class SecurityFilterPlugin {
528
563
  }
529
564
  catch (error) {
530
565
  this.logger.error(`[filter_metadata] Error processing ${packageName}: ${error.message}`);
531
- const errorStrategy = ((_f = this.config.errorHandling) === null || _f === void 0 ? void 0 : _f.onFilterError) || 'fail-open';
566
+ const errorStrategy = ((_g = this.config.errorHandling) === null || _g === void 0 ? void 0 : _g.onFilterError) || 'fail-open';
532
567
  if (errorStrategy === 'fail-closed') {
533
568
  this.logger.warn(`[filter_metadata] Error handling: fail-closed - BLOCKING ${packageName}`);
534
569
  this.metrics.recordBlock(packageName, '*', `Error during processing: ${error.message}`);
@@ -649,4 +684,6 @@ var typosquat_checker_2 = require("./lib/typosquat-checker");
649
684
  Object.defineProperty(exports, "TyposquatChecker", { enumerable: true, get: function () { return typosquat_checker_2.TyposquatChecker; } });
650
685
  var signature_checker_2 = require("./lib/signature-checker");
651
686
  Object.defineProperty(exports, "SignatureChecker", { enumerable: true, get: function () { return signature_checker_2.SignatureChecker; } });
687
+ var provenance_checker_2 = require("./lib/provenance-checker");
688
+ Object.defineProperty(exports, "ProvenanceChecker", { enumerable: true, get: function () { return provenance_checker_2.ProvenanceChecker; } });
652
689
  __exportStar(require("./types"), exports);
@@ -0,0 +1,17 @@
1
+ import { Package } from '@verdaccio/types';
2
+ import { ProvenanceConfig } from '../types';
3
+ export type ProvenanceStatus = 'present' | 'downgrade' | 'missing';
4
+ export interface ProvenanceResult {
5
+ version: string;
6
+ status: ProvenanceStatus;
7
+ allowed: boolean;
8
+ warn: boolean;
9
+ reason?: string;
10
+ }
11
+ export declare class ProvenanceChecker {
12
+ readonly enabled: boolean;
13
+ private readonly actions;
14
+ constructor(config?: ProvenanceConfig);
15
+ check(pkg: Package): ProvenanceResult[];
16
+ private result;
17
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProvenanceChecker = void 0;
4
+ const SLSA_PROVENANCE = 'https://slsa.dev/provenance/';
5
+ const REASONS = {
6
+ present: undefined,
7
+ downgrade: 'Provenance downgrade',
8
+ missing: 'Missing provenance',
9
+ };
10
+ class ProvenanceChecker {
11
+ constructor(config) {
12
+ var _a, _b, _c;
13
+ this.enabled = (_a = config === null || config === void 0 ? void 0 : config.enabled) !== null && _a !== void 0 ? _a : false;
14
+ this.actions = {
15
+ present: 'allow',
16
+ downgrade: (_b = config === null || config === void 0 ? void 0 : config.onDowngrade) !== null && _b !== void 0 ? _b : 'block',
17
+ missing: (_c = config === null || config === void 0 ? void 0 : config.onMissing) !== null && _c !== void 0 ? _c : 'allow',
18
+ };
19
+ }
20
+ check(pkg) {
21
+ const versions = Object.entries(pkg.versions || {}).map(([version, data]) => {
22
+ var _a, _b;
23
+ return ({
24
+ version,
25
+ attested: hasProvenance(data),
26
+ published: Date.parse((_b = (_a = pkg.time) === null || _a === void 0 ? void 0 : _a[version]) !== null && _b !== void 0 ? _b : ''),
27
+ });
28
+ });
29
+ const attested = versions.filter(v => v.attested);
30
+ const baseline = Math.min(...attested.map(v => (Number.isNaN(v.published) ? -Infinity : v.published)));
31
+ return versions.map(({ version, attested: hasIt, published }) => {
32
+ let status;
33
+ if (attested.length === 0) {
34
+ status = 'missing';
35
+ }
36
+ else if (hasIt) {
37
+ status = 'present';
38
+ }
39
+ else {
40
+ status = (Number.isNaN(published) ? Infinity : published) > baseline ? 'downgrade' : 'present';
41
+ }
42
+ return this.result(version, status);
43
+ });
44
+ }
45
+ result(version, status) {
46
+ const action = this.actions[status];
47
+ const reason = REASONS[status];
48
+ const result = { version, status, allowed: action !== 'block', warn: action === 'warn' };
49
+ return reason ? Object.assign(Object.assign({}, result), { reason }) : result;
50
+ }
51
+ }
52
+ exports.ProvenanceChecker = ProvenanceChecker;
53
+ function hasProvenance(data) {
54
+ var _a, _b, _c;
55
+ const predicateType = (_c = (_b = (_a = data === null || data === void 0 ? void 0 : data.dist) === null || _a === void 0 ? void 0 : _a.attestations) === null || _b === void 0 ? void 0 : _b.provenance) === null || _c === void 0 ? void 0 : _c.predicateType;
56
+ return typeof predicateType === 'string' && predicateType.startsWith(SLSA_PROVENANCE);
57
+ }
package/build/types.d.ts CHANGED
@@ -42,6 +42,11 @@ export interface WebhookConfig {
42
42
  timeoutMs?: number;
43
43
  repeatIntervalMinutes?: number;
44
44
  }
45
+ export interface ProvenanceConfig {
46
+ enabled: boolean;
47
+ onDowngrade?: 'allow' | 'warn' | 'block';
48
+ onMissing?: 'allow' | 'warn' | 'block';
49
+ }
45
50
  export interface PackageAgeConfig {
46
51
  enabled: boolean;
47
52
  minPackageAgeDays: number;
@@ -92,6 +97,7 @@ export interface SecurityConfig extends Config {
92
97
  logger?: LoggerConfig;
93
98
  metrics?: MetricsConfig;
94
99
  webhook?: WebhookConfig;
100
+ provenance?: ProvenanceConfig;
95
101
  packageAge?: PackageAgeConfig;
96
102
  authorFilter?: AuthorFilterConfig;
97
103
  typosquatting?: TyposquatConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verdaccio-security-filter",
3
- "version": "1.7.0",
3
+ "version": "1.8.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",