verdaccio-security-filter 1.7.0 → 1.9.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 +58 -5
- package/build/index.d.ts +3 -2
- package/build/index.js +74 -22
- package/build/lib/metrics.d.ts +1 -0
- package/build/lib/metrics.js +9 -0
- package/build/lib/provenance-checker.d.ts +17 -0
- package/build/lib/provenance-checker.js +57 -0
- package/build/lib/webhook.d.ts +3 -0
- package/build/lib/webhook.js +77 -7
- package/build/types.d.ts +9 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ This plugin implements **two independent security layers** for complete protecti
|
|
|
61
61
|
#### 📊 Monitoring & Observability
|
|
62
62
|
- **Enhanced Logging** - Configurable log levels (`debug`, `info`, `warn`, `error`)
|
|
63
63
|
- **Metrics Collection** - Track security events (blocks with their reason, author blocks)
|
|
64
|
-
- **Webhook Notifications** - POST block events to any HTTP endpoint or a Slack-compatible incoming webhook
|
|
64
|
+
- **Webhook Notifications** - POST block and optionally warn-only events to any HTTP endpoint or a Slack-compatible incoming webhook, signed with HMAC-SHA256 on request
|
|
65
65
|
- **Security Audit Trail** - Detailed logging of all security decisions
|
|
66
66
|
- **Customizable Output** - Log to stdout or file in JSON format
|
|
67
67
|
|
|
@@ -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,14 +110,15 @@ 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
|
-
- **
|
|
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
|
-
- [x] **Webhook notifications** - `webhook`: block events as JSON or as a Slack message
|
|
121
|
+
- [x] **Webhook notifications** - `webhook`: block and warn events as JSON or as a Slack message, optional HMAC signature
|
|
120
122
|
|
|
121
123
|
#### Not planned
|
|
122
124
|
- **Rate limiting** and **multi-registry fallback** - Verdaccio already provides both (`rateLimit`, uplinks)
|
|
@@ -490,7 +492,7 @@ The license check runs when `licenses.allowed` or `licenses.blocked` is not empt
|
|
|
490
492
|
|
|
491
493
|
### Webhook Options
|
|
492
494
|
|
|
493
|
-
Sends every block event to an HTTP endpoint. It does not depend on `metrics.enabled`.
|
|
495
|
+
Sends every block event, and on request every warn-only decision, to an HTTP endpoint. It does not depend on `metrics.enabled`.
|
|
494
496
|
|
|
495
497
|
| Option | Type | Default | Description |
|
|
496
498
|
|--------|------|---------|-------------|
|
|
@@ -500,6 +502,8 @@ Sends every block event to an HTTP endpoint. It does not depend on `metrics.enab
|
|
|
500
502
|
| `webhook.headers` | `object` | `{}` | Extra request headers, for example `Authorization` |
|
|
501
503
|
| `webhook.timeoutMs` | `number` | `5000` | Timeout of one delivery attempt |
|
|
502
504
|
| `webhook.repeatIntervalMinutes` | `number` | `60` | The same event is sent at most once per interval; `0` sends every occurrence |
|
|
505
|
+
| `webhook.secret` | `string` | - | Signs every request with HMAC-SHA256, see [Signature](#webhook-signature) |
|
|
506
|
+
| `webhook.events` | `('block' \| 'warn')[]` | `['block']` | `warn` adds the decisions that are only logged: warn-only modes, unsigned versions, provenance warnings, CVEs with `autoBlock` off |
|
|
503
507
|
|
|
504
508
|
```yaml
|
|
505
509
|
webhook:
|
|
@@ -522,6 +526,29 @@ webhook:
|
|
|
522
526
|
|
|
523
527
|
**Repeats.** A blocked package is requested again on every `npm install`. An event with the same package, version(s) and reason is therefore sent once per `repeatIntervalMinutes`; the metrics output still records every attempt.
|
|
524
528
|
|
|
529
|
+
**Warnings.** With `events: [block, warn]`, every decision that is only logged is sent as an event with `"event": "warn"`: `warnOnly` of age, author, typosquatting and signatures, `onMissing: warn` of signatures and provenance, `onDowngrade: warn`, and CVEs found while `autoBlock` is off. Each kind of warning about a package is logged and sent at most once per 10 minutes, shared by both layers, and then once per `repeatIntervalMinutes` by the webhook. Warnings go to the webhook only; the metrics output and its counters keep block events alone. `events: [warn]` sends warnings without blocks, for example to a separate channel.
|
|
530
|
+
|
|
531
|
+
<a id="webhook-signature"></a>**Signature.** With `secret` set (`${NAME}` works here too), every request carries two headers:
|
|
532
|
+
|
|
533
|
+
- `X-Webhook-Timestamp`: Unix time in seconds when the request was sent
|
|
534
|
+
- `X-Webhook-Signature`: `sha256=` and the hex HMAC-SHA256 of `<timestamp>.<raw body>` with the secret
|
|
535
|
+
|
|
536
|
+
Every attempt, retries included, is signed afresh. The receiver recomputes the HMAC over the raw body, compares in constant time and rejects old timestamps, so a captured request cannot be replayed later:
|
|
537
|
+
|
|
538
|
+
```js
|
|
539
|
+
const crypto = require('crypto');
|
|
540
|
+
|
|
541
|
+
function verify(rawBody, headers, secret, toleranceSeconds = 300) {
|
|
542
|
+
const timestamp = headers['x-webhook-timestamp'];
|
|
543
|
+
const received = Buffer.from(String(headers['x-webhook-signature'] || ''));
|
|
544
|
+
const expected = Buffer.from('sha256=' + crypto.createHmac('sha256', secret).update(`${timestamp}.${rawBody}`).digest('hex'));
|
|
545
|
+
const fresh = Math.abs(Date.now() / 1000 - Number(timestamp)) <= toleranceSeconds;
|
|
546
|
+
return fresh && received.length === expected.length && crypto.timingSafeEqual(received, expected);
|
|
547
|
+
}
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
Slack incoming webhooks ignore the headers; signing matters for your own receivers.
|
|
551
|
+
|
|
525
552
|
**With both layers configured**, put `webhook` in the `filters` and the `middlewares` block, like the rest of the configuration: name, scope and tarball blocks are reported by the middleware, removed versions by the filter.
|
|
526
553
|
|
|
527
554
|
The `json` body. Each entry of `events` has the fields described in [Metrics & Monitoring](#-metrics--monitoring):
|
|
@@ -538,6 +565,13 @@ The `json` body. Each entry of `events` has the fields described in [Metrics & M
|
|
|
538
565
|
"packageName": "evil-pkg",
|
|
539
566
|
"version": "*",
|
|
540
567
|
"reason": "Package name matches blocked pattern"
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
"timestamp": "2026-01-15T10:30:02.000Z",
|
|
571
|
+
"event": "warn",
|
|
572
|
+
"packageName": "left-pad",
|
|
573
|
+
"reason": "Missing provenance",
|
|
574
|
+
"metadata": { "versions": ["1.0.0", "1.1.0"] }
|
|
541
575
|
}
|
|
542
576
|
]
|
|
543
577
|
}
|
|
@@ -549,7 +583,7 @@ The `slack` body:
|
|
|
549
583
|
|
|
550
584
|
```json
|
|
551
585
|
{
|
|
552
|
-
"text": "*Verdaccio security filter*:
|
|
586
|
+
"text": "*Verdaccio security filter*: 3 event(s)\n• blocked `evil-pkg`: Package name matches blocked pattern\n• blocked `lodash` (2 version(s): 4.17.19, 4.17.20): Package has 2 vulnerable version(s)\n• warning `left-pad` (2 version(s): 1.0.0, 1.1.0): Missing provenance"
|
|
553
587
|
}
|
|
554
588
|
```
|
|
555
589
|
|
|
@@ -617,6 +651,25 @@ signatures:
|
|
|
617
651
|
onMissing: warn
|
|
618
652
|
```
|
|
619
653
|
|
|
654
|
+
### Provenance Options
|
|
655
|
+
|
|
656
|
+
| Option | Type | Default | Description |
|
|
657
|
+
|--------|------|---------|-------------|
|
|
658
|
+
| `provenance.enabled` | `boolean` | `false` | Check npm provenance attestations |
|
|
659
|
+
| `provenance.onDowngrade` | `'allow' \| 'warn' \| 'block'` | `'block'` | Versions without provenance published after the first version with it |
|
|
660
|
+
| `provenance.onMissing` | `'allow' \| 'warn' \| 'block'` | `'allow'` | Packages that never published with provenance |
|
|
661
|
+
|
|
662
|
+
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.
|
|
663
|
+
|
|
664
|
+
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.
|
|
665
|
+
|
|
666
|
+
```yaml
|
|
667
|
+
provenance:
|
|
668
|
+
enabled: true
|
|
669
|
+
onDowngrade: block
|
|
670
|
+
onMissing: allow
|
|
671
|
+
```
|
|
672
|
+
|
|
620
673
|
### Error Handling Options
|
|
621
674
|
|
|
622
675
|
| Option | Type | Default | Description |
|
package/build/index.d.ts
CHANGED
|
@@ -16,8 +16,7 @@ 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
|
|
20
|
-
private readonly typosquatWarnedAt;
|
|
19
|
+
private readonly provenanceChecker;
|
|
21
20
|
constructor(config: SecurityConfig, options: PluginOptions<SecurityConfig>);
|
|
22
21
|
private _parseVersionRangeRules;
|
|
23
22
|
private _logInitialization;
|
|
@@ -32,6 +31,7 @@ export default class SecurityFilterPlugin implements IPluginMiddleware<SecurityC
|
|
|
32
31
|
filter_metadata(packageInfo: Package): Promise<Package>;
|
|
33
32
|
private _filterMetadata;
|
|
34
33
|
private _versionBlockReason;
|
|
34
|
+
private _warnDue;
|
|
35
35
|
private _checkPackageBlock;
|
|
36
36
|
private _getAppliedRules;
|
|
37
37
|
destroy(): void;
|
|
@@ -46,4 +46,5 @@ export { PackageAgeChecker } from './lib/package-age-checker';
|
|
|
46
46
|
export { AuthorChecker } from './lib/author-checker';
|
|
47
47
|
export { TyposquatChecker } from './lib/typosquat-checker';
|
|
48
48
|
export { SignatureChecker } from './lib/signature-checker';
|
|
49
|
+
export { ProvenanceChecker } from './lib/provenance-checker';
|
|
49
50
|
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,18 +58,18 @@ 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;
|
|
64
65
|
const filterBlocks = new lru_cache_1.LRUCache(1000);
|
|
66
|
+
const warnedAt = new lru_cache_1.LRUCache(10000);
|
|
65
67
|
const WARN_REPEAT_MS = 10 * 60 * 1000;
|
|
66
68
|
function forbiddenBody(packageName, reason, extra = {}) {
|
|
67
69
|
return Object.assign(Object.assign({ error: `Package blocked by security filter: ${reason}`, package: packageName, reason }, extra), { timestamp: new Date().toISOString() });
|
|
68
70
|
}
|
|
69
71
|
class SecurityFilterPlugin {
|
|
70
72
|
constructor(config, options) {
|
|
71
|
-
this.unsignedWarnedAt = new lru_cache_1.LRUCache(5000);
|
|
72
|
-
this.typosquatWarnedAt = new lru_cache_1.LRUCache(5000);
|
|
73
73
|
this.config = config || {};
|
|
74
74
|
if (!this.config.errorHandling) {
|
|
75
75
|
this.config.errorHandling = {
|
|
@@ -87,6 +87,7 @@ class SecurityFilterPlugin {
|
|
|
87
87
|
this.authorChecker = new author_checker_1.AuthorChecker(this.config.authorFilter);
|
|
88
88
|
this.typosquatChecker = new typosquat_checker_1.TyposquatChecker(this.config.typosquatting);
|
|
89
89
|
this.signatureChecker = new signature_checker_1.SignatureChecker(this.config.signatures);
|
|
90
|
+
this.provenanceChecker = new provenance_checker_1.ProvenanceChecker(this.config.provenance);
|
|
90
91
|
this.securityRules = {
|
|
91
92
|
blockedVersions: this.config.blockedVersions || [],
|
|
92
93
|
blockedPatterns: this.config.blockedPatterns || [],
|
|
@@ -158,7 +159,7 @@ class SecurityFilterPlugin {
|
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
_getEnabledFeatures() {
|
|
161
|
-
var _a, _b, _c, _d, _e, _f;
|
|
162
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
162
163
|
const features = [];
|
|
163
164
|
if (this.config.dryRun)
|
|
164
165
|
features.push('dry-run');
|
|
@@ -180,6 +181,8 @@ class SecurityFilterPlugin {
|
|
|
180
181
|
features.push('typosquat-detection');
|
|
181
182
|
if ((_f = this.config.signatures) === null || _f === void 0 ? void 0 : _f.enabled)
|
|
182
183
|
features.push('registry-signatures');
|
|
184
|
+
if ((_g = this.config.provenance) === null || _g === void 0 ? void 0 : _g.enabled)
|
|
185
|
+
features.push('provenance');
|
|
183
186
|
if (this.securityRules.versionRangeRules.length > 0)
|
|
184
187
|
features.push('version-range-rules');
|
|
185
188
|
if (this.securityRules.blockedPatterns.length > 0)
|
|
@@ -370,7 +373,7 @@ class SecurityFilterPlugin {
|
|
|
370
373
|
}
|
|
371
374
|
_filterMetadata(packageInfo) {
|
|
372
375
|
return __awaiter(this, void 0, void 0, function* () {
|
|
373
|
-
var _a, _b, _c, _d, _e
|
|
376
|
+
var _a, _b, _c, _d, _e;
|
|
374
377
|
let pkg = packageInfo;
|
|
375
378
|
const packageName = pkg.name;
|
|
376
379
|
this.logger.debug(`[filter_metadata] --> Processing: ${packageName}`);
|
|
@@ -406,8 +409,9 @@ class SecurityFilterPlugin {
|
|
|
406
409
|
return this._blockedPackage(pkg, reason);
|
|
407
410
|
}
|
|
408
411
|
}
|
|
409
|
-
if (vulnerableVersions.length > 0 && !this.config.cveCheck.autoBlock) {
|
|
412
|
+
if (vulnerableVersions.length > 0 && !this.config.cveCheck.autoBlock && this._warnDue('cve', packageName)) {
|
|
410
413
|
this.logger.warn(`[filter_metadata] CVE found in ${packageName}: ${vulnerableVersions.length} vulnerable version(s), autoBlock is off`);
|
|
414
|
+
this.metrics.recordWarning(packageName, `Package has ${vulnerableVersions.length} vulnerable version(s)`, vulnerableVersions);
|
|
411
415
|
}
|
|
412
416
|
if (this.config.cveCheck.autoBlock && vulnerableVersions.length > 0) {
|
|
413
417
|
const reason = `Package has ${vulnerableVersions.length} vulnerable version(s)`;
|
|
@@ -443,15 +447,14 @@ class SecurityFilterPlugin {
|
|
|
443
447
|
});
|
|
444
448
|
const versionsWith = (match) => statuses.filter(([, r]) => match(r)).map(([v]) => v);
|
|
445
449
|
const unsigned = versionsWith(r => r.status === 'missing');
|
|
446
|
-
|
|
447
|
-
if (unsigned.length > 0 && this.signatureChecker.onMissing === 'warn'
|
|
448
|
-
&& now - ((_c = this.unsignedWarnedAt.get(packageName)) !== null && _c !== void 0 ? _c : -Infinity) >= WARN_REPEAT_MS) {
|
|
449
|
-
this.unsignedWarnedAt.set(packageName, now);
|
|
450
|
+
if (unsigned.length > 0 && this.signatureChecker.onMissing === 'warn' && this._warnDue('unsigned', packageName)) {
|
|
450
451
|
this.logger.warn(`[filter_metadata] SIGNATURE WARNING: ${packageName}: ${unsigned.length} unsigned version(s)`);
|
|
452
|
+
this.metrics.recordWarning(packageName, 'Missing registry signature', unsigned);
|
|
451
453
|
}
|
|
452
454
|
const tolerated = versionsWith(r => r.status === 'invalid' && r.allowed);
|
|
453
|
-
if (tolerated.length > 0) {
|
|
455
|
+
if (tolerated.length > 0 && this._warnDue('invalid-signature', packageName)) {
|
|
454
456
|
this.logger.warn(`[filter_metadata] SIGNATURE WARNING: ${packageName}: invalid signature on ${tolerated.join(', ')} (warn-only mode)`);
|
|
457
|
+
this.metrics.recordWarning(packageName, 'Invalid registry signature', tolerated);
|
|
455
458
|
}
|
|
456
459
|
const invalid = versionsWith(r => !r.allowed && r.status === 'invalid');
|
|
457
460
|
const missing = versionsWith(r => !r.allowed && r.status === 'missing');
|
|
@@ -469,7 +472,36 @@ class SecurityFilterPlugin {
|
|
|
469
472
|
}
|
|
470
473
|
pkg = this._removeVersions(pkg, [...invalid, ...missing]);
|
|
471
474
|
}
|
|
472
|
-
if (
|
|
475
|
+
if (this.provenanceChecker.enabled
|
|
476
|
+
&& !(this.config.mode !== 'whitelist' && this.config.whitelist
|
|
477
|
+
&& this.whitelistChecker.isWhitelisted(packageName).allowed)) {
|
|
478
|
+
const remaining = new Set(Object.keys(pkg.versions || {}));
|
|
479
|
+
const results = this.provenanceChecker.check(packageInfo).filter(r => remaining.has(r.version));
|
|
480
|
+
const warned = results.filter(r => r.warn);
|
|
481
|
+
if (warned.length > 0 && this._warnDue('provenance', packageName)) {
|
|
482
|
+
this.logger.warn(`[filter_metadata] PROVENANCE WARNING: ${packageName}: ${warned.length} version(s) - ${warned[0].reason}`);
|
|
483
|
+
this.metrics.recordWarning(packageName, warned[0].reason || 'Provenance check failed', warned.map(r => r.version));
|
|
484
|
+
}
|
|
485
|
+
const rejected = results.filter(r => !r.allowed);
|
|
486
|
+
if (results.length > 0 && rejected.length === results.length) {
|
|
487
|
+
const reason = rejected[0].reason || 'Provenance check failed';
|
|
488
|
+
this.logger.warn(`[filter_metadata] PROVENANCE BLOCKED: ${packageName} - ${reason}`);
|
|
489
|
+
this.metrics.recordBlock(packageName, '*', reason);
|
|
490
|
+
return this._blockedPackage(pkg, reason);
|
|
491
|
+
}
|
|
492
|
+
const byReason = new Map();
|
|
493
|
+
rejected.forEach((r) => {
|
|
494
|
+
var _a;
|
|
495
|
+
const reason = r.reason || 'Provenance check failed';
|
|
496
|
+
byReason.set(reason, [...((_a = byReason.get(reason)) !== null && _a !== void 0 ? _a : []), r.version]);
|
|
497
|
+
});
|
|
498
|
+
for (const [reason, versions] of byReason) {
|
|
499
|
+
this.logger.warn(`[filter_metadata] PROVENANCE FILTERED: ${packageName}: ${versions.join(', ')} - ${reason}`);
|
|
500
|
+
this.metrics.recordFiltered(packageName, versions, reason);
|
|
501
|
+
}
|
|
502
|
+
pkg = this._removeVersions(pkg, rejected.map(r => r.version));
|
|
503
|
+
}
|
|
504
|
+
if ((_c = this.config.packageAge) === null || _c === void 0 ? void 0 : _c.enabled) {
|
|
473
505
|
const ageResult = this.packageAgeChecker.checkPackageAge(pkg);
|
|
474
506
|
if (!ageResult.allowed && !ageResult.warnOnly) {
|
|
475
507
|
const reason = ageResult.reason || 'Package too new';
|
|
@@ -477,20 +509,28 @@ class SecurityFilterPlugin {
|
|
|
477
509
|
this.metrics.recordBlock(packageName, '*', reason);
|
|
478
510
|
return this._blockedPackage(pkg, reason, { ageDays: ageResult.ageDays });
|
|
479
511
|
}
|
|
480
|
-
else if (
|
|
512
|
+
else if (ageResult.warnOnly && this._warnDue('age', packageName)) {
|
|
481
513
|
this.logger.warn(`[filter_metadata] AGE WARNING: ${packageName} - ${ageResult.reason} (warn-only mode)`);
|
|
514
|
+
this.metrics.recordWarning(packageName, ageResult.reason || 'Package too new');
|
|
482
515
|
}
|
|
483
516
|
if (this.config.packageAge.minVersionAgeDays) {
|
|
484
517
|
const removedVersions = [];
|
|
518
|
+
const warnedVersions = [];
|
|
485
519
|
for (const version of Object.keys(pkg.versions || {})) {
|
|
486
520
|
const versionAgeResult = this.packageAgeChecker.checkVersionAge(pkg, version);
|
|
487
521
|
if (!versionAgeResult.allowed && !versionAgeResult.warnOnly) {
|
|
488
522
|
removedVersions.push(version);
|
|
489
523
|
}
|
|
490
|
-
else if (
|
|
491
|
-
|
|
524
|
+
else if (versionAgeResult.warnOnly) {
|
|
525
|
+
warnedVersions.push([version, versionAgeResult.reason]);
|
|
492
526
|
}
|
|
493
527
|
}
|
|
528
|
+
if (warnedVersions.length > 0 && this._warnDue('version-age', packageName)) {
|
|
529
|
+
for (const [version, reason] of warnedVersions) {
|
|
530
|
+
this.logger.warn(`[filter_metadata] VERSION AGE WARNING: ${packageName}@${version} - ${reason} (warn-only mode)`);
|
|
531
|
+
}
|
|
532
|
+
this.metrics.recordWarning(packageName, 'Version too new', warnedVersions.map(([version]) => version));
|
|
533
|
+
}
|
|
494
534
|
if (removedVersions.length > 0) {
|
|
495
535
|
this.logger.warn(`[filter_metadata] VERSION AGE FILTERED: ${packageName}: ${removedVersions.join(', ')}`);
|
|
496
536
|
this.metrics.recordFiltered(packageName, removedVersions, 'Version too new');
|
|
@@ -498,10 +538,11 @@ class SecurityFilterPlugin {
|
|
|
498
538
|
}
|
|
499
539
|
}
|
|
500
540
|
}
|
|
501
|
-
if ((
|
|
541
|
+
if ((_d = this.config.authorFilter) === null || _d === void 0 ? void 0 : _d.enabled) {
|
|
502
542
|
const rejected = this._rejectedVersions(pkg, data => this.authorChecker.checkAuthor(data));
|
|
503
|
-
if (rejected.versions.length > 0 && this.config.authorFilter.warnOnly) {
|
|
543
|
+
if (rejected.versions.length > 0 && this.config.authorFilter.warnOnly && this._warnDue('author', packageName)) {
|
|
504
544
|
this.logger.warn(`[filter_metadata] AUTHOR WARNING: ${packageName}: ${rejected.versions.join(', ')} - ${rejected.first.reason} (warn-only mode)`);
|
|
545
|
+
this.metrics.recordWarning(packageName, rejected.first.reason || 'Author not allowed', rejected.versions);
|
|
505
546
|
}
|
|
506
547
|
else if (rejected.versions.length > 0) {
|
|
507
548
|
const reason = rejected.first.reason || 'Author not allowed';
|
|
@@ -528,7 +569,7 @@ class SecurityFilterPlugin {
|
|
|
528
569
|
}
|
|
529
570
|
catch (error) {
|
|
530
571
|
this.logger.error(`[filter_metadata] Error processing ${packageName}: ${error.message}`);
|
|
531
|
-
const errorStrategy = ((
|
|
572
|
+
const errorStrategy = ((_e = this.config.errorHandling) === null || _e === void 0 ? void 0 : _e.onFilterError) || 'fail-open';
|
|
532
573
|
if (errorStrategy === 'fail-closed') {
|
|
533
574
|
this.logger.warn(`[filter_metadata] Error handling: fail-closed - BLOCKING ${packageName}`);
|
|
534
575
|
this.metrics.recordBlock(packageName, '*', `Error during processing: ${error.message}`);
|
|
@@ -546,9 +587,18 @@ class SecurityFilterPlugin {
|
|
|
546
587
|
const rangeRule = this._getVersionRangeRule(packageName, version);
|
|
547
588
|
return rangeRule ? `Version matches blocked range: ${rangeRule.range}` : null;
|
|
548
589
|
}
|
|
590
|
+
_warnDue(kind, packageName) {
|
|
591
|
+
var _a;
|
|
592
|
+
const key = `${kind}|${packageName}`;
|
|
593
|
+
const now = Date.now();
|
|
594
|
+
if (now - ((_a = warnedAt.get(key)) !== null && _a !== void 0 ? _a : -Infinity) < WARN_REPEAT_MS) {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
warnedAt.set(key, now);
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
549
600
|
_checkPackageBlock(packageName, version) {
|
|
550
601
|
return __awaiter(this, void 0, void 0, function* () {
|
|
551
|
-
var _a;
|
|
552
602
|
const whitelistMode = this.config.mode === 'whitelist';
|
|
553
603
|
if (whitelistMode) {
|
|
554
604
|
const whitelistCheck = this.whitelistChecker.isWhitelisted(packageName, version);
|
|
@@ -564,10 +614,9 @@ class SecurityFilterPlugin {
|
|
|
564
614
|
}
|
|
565
615
|
const typosquat = whitelistMode ? { allowed: true } : this.typosquatChecker.check(packageName);
|
|
566
616
|
if (typosquat.warnOnly && typosquat.reason) {
|
|
567
|
-
|
|
568
|
-
if (now - ((_a = this.typosquatWarnedAt.get(packageName)) !== null && _a !== void 0 ? _a : -Infinity) >= WARN_REPEAT_MS) {
|
|
569
|
-
this.typosquatWarnedAt.set(packageName, now);
|
|
617
|
+
if (this._warnDue('typosquat', packageName)) {
|
|
570
618
|
this.logger.warn(`TYPOSQUAT WARNING: ${packageName} - ${typosquat.reason} (warn-only mode)`);
|
|
619
|
+
this.metrics.recordWarning(packageName, typosquat.reason || 'Possible typosquat');
|
|
571
620
|
}
|
|
572
621
|
}
|
|
573
622
|
else if (!typosquat.allowed) {
|
|
@@ -617,6 +666,7 @@ class SecurityFilterPlugin {
|
|
|
617
666
|
return rules;
|
|
618
667
|
}
|
|
619
668
|
destroy() {
|
|
669
|
+
warnedAt.clear();
|
|
620
670
|
this.logger.info('[Cleanup] Shutting down security filter plugin');
|
|
621
671
|
try {
|
|
622
672
|
this.cveChecker.destroy();
|
|
@@ -649,4 +699,6 @@ var typosquat_checker_2 = require("./lib/typosquat-checker");
|
|
|
649
699
|
Object.defineProperty(exports, "TyposquatChecker", { enumerable: true, get: function () { return typosquat_checker_2.TyposquatChecker; } });
|
|
650
700
|
var signature_checker_2 = require("./lib/signature-checker");
|
|
651
701
|
Object.defineProperty(exports, "SignatureChecker", { enumerable: true, get: function () { return signature_checker_2.SignatureChecker; } });
|
|
702
|
+
var provenance_checker_2 = require("./lib/provenance-checker");
|
|
703
|
+
Object.defineProperty(exports, "ProvenanceChecker", { enumerable: true, get: function () { return provenance_checker_2.ProvenanceChecker; } });
|
|
652
704
|
__exportStar(require("./types"), exports);
|
package/build/lib/metrics.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class MetricsCollector {
|
|
|
18
18
|
record(event: MetricsData): void;
|
|
19
19
|
recordBlock(packageName: string, version: string, reason: string, metadata?: Record<string, any>): void;
|
|
20
20
|
recordFiltered(packageName: string, versions: string[], reason: string, event?: MetricsData['event'], metadata?: Record<string, any>): void;
|
|
21
|
+
recordWarning(packageName: string, reason: string, versions?: string[]): void;
|
|
21
22
|
flush(): void;
|
|
22
23
|
private writeToFile;
|
|
23
24
|
getSummary(): Record<string, number>;
|
package/build/lib/metrics.js
CHANGED
|
@@ -105,6 +105,15 @@ class MetricsCollector {
|
|
|
105
105
|
metadata: Object.assign(Object.assign({}, metadata), { versions }),
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
+
recordWarning(packageName, reason, versions) {
|
|
109
|
+
var _a;
|
|
110
|
+
if (!((_a = this.webhook) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const event = Object.assign({ timestamp: new Date().toISOString(), event: 'warn', packageName,
|
|
114
|
+
reason }, (versions && versions.length > 0 ? { metadata: { versions } } : { version: '*' }));
|
|
115
|
+
this.webhook.notify(this.dryRun ? Object.assign(Object.assign({}, event), { dryRun: true }) : event);
|
|
116
|
+
}
|
|
108
117
|
flush() {
|
|
109
118
|
if (this.metricsBuffer.length === 0) {
|
|
110
119
|
return;
|
|
@@ -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/lib/webhook.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare class WebhookNotifier {
|
|
|
11
11
|
private readonly headers;
|
|
12
12
|
private readonly timeoutMs;
|
|
13
13
|
private readonly repeatMs;
|
|
14
|
+
private readonly secret;
|
|
15
|
+
private readonly events;
|
|
14
16
|
private readonly recent;
|
|
15
17
|
private queue;
|
|
16
18
|
private dropped;
|
|
@@ -23,5 +25,6 @@ export declare class WebhookNotifier {
|
|
|
23
25
|
flush(): Promise<void>;
|
|
24
26
|
cleanup(): void;
|
|
25
27
|
private drain;
|
|
28
|
+
private signatureHeaders;
|
|
26
29
|
private deliver;
|
|
27
30
|
}
|
package/build/lib/webhook.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -12,6 +45,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
45
|
exports.WebhookNotifier = void 0;
|
|
13
46
|
exports.expandEnv = expandEnv;
|
|
14
47
|
exports.formatSlackText = formatSlackText;
|
|
48
|
+
const crypto = __importStar(require("crypto"));
|
|
15
49
|
const lru_cache_1 = require("./lru-cache");
|
|
16
50
|
const BATCH_DELAY_MS = 5000;
|
|
17
51
|
const MAX_BATCH_SIZE = 50;
|
|
@@ -48,7 +82,9 @@ function describeTarget(event) {
|
|
|
48
82
|
}
|
|
49
83
|
function formatSlackText(events, dropped = 0) {
|
|
50
84
|
const lines = events.slice(0, SLACK_MAX_LINES).map(event => {
|
|
51
|
-
const action = event.
|
|
85
|
+
const action = event.event === 'warn'
|
|
86
|
+
? (event.dryRun ? '[DRY RUN] warning' : 'warning')
|
|
87
|
+
: (event.dryRun ? '[DRY RUN] would block' : 'blocked');
|
|
52
88
|
return `• ${action} ${describeTarget(event)}: ${escapeSlack(event.reason)}`;
|
|
53
89
|
});
|
|
54
90
|
if (events.length > SLACK_MAX_LINES) {
|
|
@@ -67,7 +103,12 @@ class WebhookNotifier {
|
|
|
67
103
|
this.url = null;
|
|
68
104
|
this.host = '';
|
|
69
105
|
this.headers = {};
|
|
70
|
-
this.
|
|
106
|
+
this.secret = null;
|
|
107
|
+
this.events = new Set(['block']);
|
|
108
|
+
this.recent = {
|
|
109
|
+
block: new lru_cache_1.LRUCache(5000),
|
|
110
|
+
warn: new lru_cache_1.LRUCache(5000),
|
|
111
|
+
};
|
|
71
112
|
this.queue = [];
|
|
72
113
|
this.dropped = 0;
|
|
73
114
|
this.timer = null;
|
|
@@ -81,6 +122,20 @@ class WebhookNotifier {
|
|
|
81
122
|
if (config.format && config.format !== 'json' && config.format !== 'slack') {
|
|
82
123
|
this.log.warn(`Unknown webhook format "${config.format}", using "json"`);
|
|
83
124
|
}
|
|
125
|
+
if (config.events !== undefined) {
|
|
126
|
+
this.events.clear();
|
|
127
|
+
for (const kind of [].concat(config.events)) {
|
|
128
|
+
if (kind === 'block' || kind === 'warn') {
|
|
129
|
+
this.events.add(kind);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this.log.warn(`Unknown webhook event "${String(kind)}" ignored; use "block" or "warn"`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (this.events.size === 0) {
|
|
136
|
+
this.log.warn('webhook.events selects no events; nothing will be sent');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
84
139
|
try {
|
|
85
140
|
if (!config.url) {
|
|
86
141
|
throw new Error('webhook.url is not set');
|
|
@@ -96,6 +151,11 @@ class WebhookNotifier {
|
|
|
96
151
|
for (const [name, value] of Object.entries(config.headers || {})) {
|
|
97
152
|
this.headers[name] = expandEnv(String(value), env);
|
|
98
153
|
}
|
|
154
|
+
if ('secret' in config && !config.secret) {
|
|
155
|
+
throw new Error('webhook.secret is empty');
|
|
156
|
+
}
|
|
157
|
+
const secret = config.secret ? expandEnv(String(config.secret), env) : null;
|
|
158
|
+
this.secret = secret;
|
|
99
159
|
this.url = url.toString();
|
|
100
160
|
this.host = url.host;
|
|
101
161
|
}
|
|
@@ -111,16 +171,18 @@ class WebhookNotifier {
|
|
|
111
171
|
}
|
|
112
172
|
notify(event) {
|
|
113
173
|
var _a, _b, _c;
|
|
114
|
-
|
|
174
|
+
const kind = event.event === 'warn' ? 'warn' : 'block';
|
|
175
|
+
if (!this.enabled || !this.events.has(kind)) {
|
|
115
176
|
return;
|
|
116
177
|
}
|
|
117
178
|
const versions = (_a = event.version) !== null && _a !== void 0 ? _a : (Array.isArray((_b = event.metadata) === null || _b === void 0 ? void 0 : _b.versions) ? event.metadata.versions.join(',') : '');
|
|
118
179
|
const key = `${event.event}|${event.packageName}|${versions}|${event.reason}|${event.dryRun ? 'dry' : ''}`;
|
|
119
180
|
const now = Date.now();
|
|
120
|
-
|
|
181
|
+
const recent = this.recent[kind];
|
|
182
|
+
if (this.repeatMs > 0 && now - ((_c = recent.get(key)) !== null && _c !== void 0 ? _c : -Infinity) < this.repeatMs) {
|
|
121
183
|
return;
|
|
122
184
|
}
|
|
123
|
-
|
|
185
|
+
recent.set(key, now);
|
|
124
186
|
if (this.queue.length >= MAX_QUEUE_SIZE) {
|
|
125
187
|
this.queue.shift();
|
|
126
188
|
this.dropped++;
|
|
@@ -159,13 +221,21 @@ class WebhookNotifier {
|
|
|
159
221
|
yield this.deliver(batch.map(item => item.event), dropped);
|
|
160
222
|
}
|
|
161
223
|
catch (error) {
|
|
162
|
-
batch.forEach(item => this.recent.delete(item.key));
|
|
224
|
+
batch.forEach(item => this.recent[item.event.event === 'warn' ? 'warn' : 'block'].delete(item.key));
|
|
163
225
|
const message = error instanceof Error ? error.message : String(error);
|
|
164
226
|
this.log.warn(`Webhook delivery to ${this.host} failed, ${batch.length} event(s) dropped: ${message}`);
|
|
165
227
|
}
|
|
166
228
|
}
|
|
167
229
|
});
|
|
168
230
|
}
|
|
231
|
+
signatureHeaders(body) {
|
|
232
|
+
if (!this.secret) {
|
|
233
|
+
return {};
|
|
234
|
+
}
|
|
235
|
+
const timestamp = String(Math.floor(Date.now() / 1000));
|
|
236
|
+
const signature = crypto.createHmac('sha256', this.secret).update(`${timestamp}.${body}`).digest('hex');
|
|
237
|
+
return { 'X-Webhook-Timestamp': timestamp, 'X-Webhook-Signature': `sha256=${signature}` };
|
|
238
|
+
}
|
|
169
239
|
deliver(events, dropped) {
|
|
170
240
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
241
|
var _a;
|
|
@@ -177,7 +247,7 @@ class WebhookNotifier {
|
|
|
177
247
|
try {
|
|
178
248
|
const response = yield fetch(this.url, {
|
|
179
249
|
method: 'POST',
|
|
180
|
-
headers: Object.assign({ 'Content-Type': 'application/json', 'User-Agent': `verdaccio-security-filter/${this.pluginVersion}` }, this.headers),
|
|
250
|
+
headers: Object.assign(Object.assign({ 'Content-Type': 'application/json', 'User-Agent': `verdaccio-security-filter/${this.pluginVersion}` }, this.headers), this.signatureHeaders(body)),
|
|
181
251
|
body,
|
|
182
252
|
signal: AbortSignal.timeout(this.timeoutMs),
|
|
183
253
|
});
|
package/build/types.d.ts
CHANGED
|
@@ -41,6 +41,13 @@ export interface WebhookConfig {
|
|
|
41
41
|
headers?: Record<string, string>;
|
|
42
42
|
timeoutMs?: number;
|
|
43
43
|
repeatIntervalMinutes?: number;
|
|
44
|
+
secret?: string;
|
|
45
|
+
events?: ('block' | 'warn')[];
|
|
46
|
+
}
|
|
47
|
+
export interface ProvenanceConfig {
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
onDowngrade?: 'allow' | 'warn' | 'block';
|
|
50
|
+
onMissing?: 'allow' | 'warn' | 'block';
|
|
44
51
|
}
|
|
45
52
|
export interface PackageAgeConfig {
|
|
46
53
|
enabled: boolean;
|
|
@@ -92,6 +99,7 @@ export interface SecurityConfig extends Config {
|
|
|
92
99
|
logger?: LoggerConfig;
|
|
93
100
|
metrics?: MetricsConfig;
|
|
94
101
|
webhook?: WebhookConfig;
|
|
102
|
+
provenance?: ProvenanceConfig;
|
|
95
103
|
packageAge?: PackageAgeConfig;
|
|
96
104
|
authorFilter?: AuthorFilterConfig;
|
|
97
105
|
typosquatting?: TyposquatConfig;
|
|
@@ -126,7 +134,7 @@ export interface CVECheckResult {
|
|
|
126
134
|
}
|
|
127
135
|
export interface MetricsData {
|
|
128
136
|
timestamp: string;
|
|
129
|
-
event: 'block' | 'author_blocked';
|
|
137
|
+
event: 'block' | 'author_blocked' | 'warn';
|
|
130
138
|
packageName: string;
|
|
131
139
|
version?: string;
|
|
132
140
|
reason: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "verdaccio-security-filter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.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",
|