verdaccio-security-filter 1.6.0 → 1.7.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 +24 -2
- package/build/index.d.ts +4 -0
- package/build/index.js +61 -7
- package/build/lib/npm-keys.d.ts +2 -0
- package/build/lib/npm-keys.js +15 -0
- package/build/lib/signature-checker.d.ts +19 -0
- package/build/lib/signature-checker.js +103 -0
- package/build/types.d.ts +12 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -71,6 +71,7 @@ This plugin implements **two independent security layers** for complete protecti
|
|
|
71
71
|
- **Minimum Package Age** - Require packages to exist for a minimum number of days
|
|
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
|
+
- **Registry Signature Verification** - Remove versions whose npm registry signature does not verify
|
|
74
75
|
- **Typosquatting Detection** - Block names one typo away from a popular npm package or your own protected names (`lodahs`, `expres`)
|
|
75
76
|
- **Author Filtering** - Block packages based on author information
|
|
76
77
|
- **Block by Author Name** - Block specific author names or patterns
|
|
@@ -102,16 +103,18 @@ This plugin implements **two independent security layers** for complete protecti
|
|
|
102
103
|
### 🔮 Roadmap
|
|
103
104
|
|
|
104
105
|
#### Planned
|
|
105
|
-
|
|
106
|
+
Nothing right now; open an issue with a request.
|
|
106
107
|
|
|
107
108
|
#### Under consideration
|
|
108
109
|
These wait for a concrete request:
|
|
109
110
|
- **Snyk integration** - OSV already includes GitHub Security Advisories, so a second source only helps if it knows more
|
|
110
111
|
- **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
|
|
111
113
|
- **CLI tool** and **GitHub Action** for checking a rule set outside Verdaccio
|
|
112
114
|
|
|
113
115
|
#### Done
|
|
114
116
|
- [x] **Dry-run mode** - `dryRun: true`
|
|
117
|
+
- [x] **Registry signature verification** - `signatures`: npm registry signatures (ECDSA)
|
|
115
118
|
- [x] **Typosquatting detection** - `typosquatting`: names within a small edit distance of popular packages
|
|
116
119
|
- [x] **Webhook notifications** - `webhook`: block events as JSON or as a Slack message
|
|
117
120
|
|
|
@@ -125,7 +128,7 @@ These wait for a concrete request:
|
|
|
125
128
|
### Prerequisites
|
|
126
129
|
|
|
127
130
|
- Node.js >= 22.0.0
|
|
128
|
-
- Verdaccio >= 5.0.0
|
|
131
|
+
- 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.
|
|
129
132
|
|
|
130
133
|
```bash
|
|
131
134
|
npm install -g verdaccio
|
|
@@ -595,6 +598,25 @@ typosquatting:
|
|
|
595
598
|
ignore: ['lodash-ext']
|
|
596
599
|
```
|
|
597
600
|
|
|
601
|
+
### Signature Options
|
|
602
|
+
|
|
603
|
+
| Option | Type | Default | Description |
|
|
604
|
+
|--------|------|---------|-------------|
|
|
605
|
+
| `signatures.enabled` | `boolean` | `false` | Verify npm registry signatures |
|
|
606
|
+
| `signatures.onMissing` | `'allow' \| 'warn' \| 'block'` | `'warn'` | What to do with versions that have no verifiable signature |
|
|
607
|
+
| `signatures.warnOnly` | `boolean` | `false` | Log invalid signatures instead of removing the version |
|
|
608
|
+
| `signatures.keys` | `{ keyid, key, expires }[]` | npm's keys | Replaces the bundled keys, in the shape of `registry.npmjs.org/-/npm/v1/keys` |
|
|
609
|
+
|
|
610
|
+
npm signs every version: the signature covers `<name>@<version>:<integrity>`. A version whose signature does not verify is removed from the metadata, and the package is blocked when no version is left. This catches accidental or naive corruption of `integrity` in Verdaccio's cache or on the way from the registry. Someone who can rewrite metadata deliberately can also delete the signature or point it at an unknown key, which turns the version into an *unsigned* one: only `onMissing: block` stops that. A signed manifest copied under another version number fails, because the version number is part of the signed text. The check does not catch a compromised author account, because npm signs those versions honestly.
|
|
611
|
+
|
|
612
|
+
A version is *unsigned* when it has no signature, no `integrity`, or only signatures by unknown keys. Packages published straight to Verdaccio are unsigned. With the default `onMissing: warn` they are served, and one warning per package is logged at most every 10 minutes. An unknown key never blocks, so a key rotation at npm does not break installs; add the new key to `keys` to verify it. An expired key is accepted only for versions published before it expired. Tarball requests are not checked because they carry no metadata, the same as license and author filtering.
|
|
613
|
+
|
|
614
|
+
```yaml
|
|
615
|
+
signatures:
|
|
616
|
+
enabled: true
|
|
617
|
+
onMissing: warn
|
|
618
|
+
```
|
|
619
|
+
|
|
598
620
|
### Error Handling Options
|
|
599
621
|
|
|
600
622
|
| Option | Type | Default | Description |
|
package/build/index.d.ts
CHANGED
|
@@ -15,6 +15,9 @@ export default class SecurityFilterPlugin implements IPluginMiddleware<SecurityC
|
|
|
15
15
|
private readonly packageAgeChecker;
|
|
16
16
|
private readonly authorChecker;
|
|
17
17
|
private readonly typosquatChecker;
|
|
18
|
+
private readonly signatureChecker;
|
|
19
|
+
private readonly unsignedWarnedAt;
|
|
20
|
+
private readonly typosquatWarnedAt;
|
|
18
21
|
constructor(config: SecurityConfig, options: PluginOptions<SecurityConfig>);
|
|
19
22
|
private _parseVersionRangeRules;
|
|
20
23
|
private _logInitialization;
|
|
@@ -42,4 +45,5 @@ export { LicenseChecker } from './lib/license-checker';
|
|
|
42
45
|
export { PackageAgeChecker } from './lib/package-age-checker';
|
|
43
46
|
export { AuthorChecker } from './lib/author-checker';
|
|
44
47
|
export { TyposquatChecker } from './lib/typosquat-checker';
|
|
48
|
+
export { SignatureChecker } from './lib/signature-checker';
|
|
45
49
|
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.TyposquatChecker = exports.AuthorChecker = exports.PackageAgeChecker = exports.LicenseChecker = exports.CVEChecker = exports.WhitelistChecker = exports.WebhookNotifier = exports.MetricsCollector = exports.SecurityLogger = void 0;
|
|
48
|
+
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");
|
|
@@ -57,15 +57,19 @@ const license_checker_1 = require("./lib/license-checker");
|
|
|
57
57
|
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
|
+
const signature_checker_1 = require("./lib/signature-checker");
|
|
60
61
|
const lru_cache_1 = require("./lib/lru-cache");
|
|
61
62
|
const webhook_1 = require("./lib/webhook");
|
|
62
63
|
const PLUGIN_VERSION = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', 'package.json'), 'utf8')).version;
|
|
63
64
|
const filterBlocks = new lru_cache_1.LRUCache(1000);
|
|
65
|
+
const WARN_REPEAT_MS = 10 * 60 * 1000;
|
|
64
66
|
function forbiddenBody(packageName, reason, extra = {}) {
|
|
65
67
|
return Object.assign(Object.assign({ error: `Package blocked by security filter: ${reason}`, package: packageName, reason }, extra), { timestamp: new Date().toISOString() });
|
|
66
68
|
}
|
|
67
69
|
class SecurityFilterPlugin {
|
|
68
70
|
constructor(config, options) {
|
|
71
|
+
this.unsignedWarnedAt = new lru_cache_1.LRUCache(5000);
|
|
72
|
+
this.typosquatWarnedAt = new lru_cache_1.LRUCache(5000);
|
|
69
73
|
this.config = config || {};
|
|
70
74
|
if (!this.config.errorHandling) {
|
|
71
75
|
this.config.errorHandling = {
|
|
@@ -82,6 +86,7 @@ class SecurityFilterPlugin {
|
|
|
82
86
|
this.packageAgeChecker = new package_age_checker_1.PackageAgeChecker(this.config.packageAge);
|
|
83
87
|
this.authorChecker = new author_checker_1.AuthorChecker(this.config.authorFilter);
|
|
84
88
|
this.typosquatChecker = new typosquat_checker_1.TyposquatChecker(this.config.typosquatting);
|
|
89
|
+
this.signatureChecker = new signature_checker_1.SignatureChecker(this.config.signatures);
|
|
85
90
|
this.securityRules = {
|
|
86
91
|
blockedVersions: this.config.blockedVersions || [],
|
|
87
92
|
blockedPatterns: this.config.blockedPatterns || [],
|
|
@@ -153,7 +158,7 @@ class SecurityFilterPlugin {
|
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
160
|
_getEnabledFeatures() {
|
|
156
|
-
var _a, _b, _c, _d, _e;
|
|
161
|
+
var _a, _b, _c, _d, _e, _f;
|
|
157
162
|
const features = [];
|
|
158
163
|
if (this.config.dryRun)
|
|
159
164
|
features.push('dry-run');
|
|
@@ -173,6 +178,8 @@ class SecurityFilterPlugin {
|
|
|
173
178
|
features.push('author-filtering');
|
|
174
179
|
if ((_e = this.config.typosquatting) === null || _e === void 0 ? void 0 : _e.enabled)
|
|
175
180
|
features.push('typosquat-detection');
|
|
181
|
+
if ((_f = this.config.signatures) === null || _f === void 0 ? void 0 : _f.enabled)
|
|
182
|
+
features.push('registry-signatures');
|
|
176
183
|
if (this.securityRules.versionRangeRules.length > 0)
|
|
177
184
|
features.push('version-range-rules');
|
|
178
185
|
if (this.securityRules.blockedPatterns.length > 0)
|
|
@@ -363,7 +370,7 @@ class SecurityFilterPlugin {
|
|
|
363
370
|
}
|
|
364
371
|
_filterMetadata(packageInfo) {
|
|
365
372
|
return __awaiter(this, void 0, void 0, function* () {
|
|
366
|
-
var _a, _b, _c, _d, _e;
|
|
373
|
+
var _a, _b, _c, _d, _e, _f;
|
|
367
374
|
let pkg = packageInfo;
|
|
368
375
|
const packageName = pkg.name;
|
|
369
376
|
this.logger.debug(`[filter_metadata] --> Processing: ${packageName}`);
|
|
@@ -428,7 +435,41 @@ class SecurityFilterPlugin {
|
|
|
428
435
|
pkg = this._removeVersions(pkg, rejected.versions);
|
|
429
436
|
}
|
|
430
437
|
}
|
|
431
|
-
if (
|
|
438
|
+
if (this.signatureChecker.enabled) {
|
|
439
|
+
const statuses = Object.entries(pkg.versions || {}).map(([version, data]) => {
|
|
440
|
+
var _a;
|
|
441
|
+
return [version,
|
|
442
|
+
this.signatureChecker.check(packageName, Object.assign(Object.assign({}, data), { version }), (_a = pkg.time) === null || _a === void 0 ? void 0 : _a[version])];
|
|
443
|
+
});
|
|
444
|
+
const versionsWith = (match) => statuses.filter(([, r]) => match(r)).map(([v]) => v);
|
|
445
|
+
const unsigned = versionsWith(r => r.status === 'missing');
|
|
446
|
+
const now = Date.now();
|
|
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
|
+
this.logger.warn(`[filter_metadata] SIGNATURE WARNING: ${packageName}: ${unsigned.length} unsigned version(s)`);
|
|
451
|
+
}
|
|
452
|
+
const tolerated = versionsWith(r => r.status === 'invalid' && r.allowed);
|
|
453
|
+
if (tolerated.length > 0) {
|
|
454
|
+
this.logger.warn(`[filter_metadata] SIGNATURE WARNING: ${packageName}: invalid signature on ${tolerated.join(', ')} (warn-only mode)`);
|
|
455
|
+
}
|
|
456
|
+
const invalid = versionsWith(r => !r.allowed && r.status === 'invalid');
|
|
457
|
+
const missing = versionsWith(r => !r.allowed && r.status === 'missing');
|
|
458
|
+
if (statuses.length > 0 && invalid.length + missing.length === statuses.length) {
|
|
459
|
+
const reason = invalid.length > 0 ? 'Invalid registry signature' : 'Missing registry signature';
|
|
460
|
+
this.logger.warn(`[filter_metadata] SIGNATURE BLOCKED: ${packageName} - ${reason}`);
|
|
461
|
+
this.metrics.recordBlock(packageName, '*', reason);
|
|
462
|
+
return this._blockedPackage(pkg, reason);
|
|
463
|
+
}
|
|
464
|
+
for (const [versions, reason] of [[invalid, 'Invalid registry signature'], [missing, 'Missing registry signature']]) {
|
|
465
|
+
if (versions.length > 0) {
|
|
466
|
+
this.logger.warn(`[filter_metadata] SIGNATURE FILTERED: ${packageName}: ${versions.join(', ')} - ${reason}`);
|
|
467
|
+
this.metrics.recordFiltered(packageName, versions, reason);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
pkg = this._removeVersions(pkg, [...invalid, ...missing]);
|
|
471
|
+
}
|
|
472
|
+
if ((_d = this.config.packageAge) === null || _d === void 0 ? void 0 : _d.enabled) {
|
|
432
473
|
const ageResult = this.packageAgeChecker.checkPackageAge(pkg);
|
|
433
474
|
if (!ageResult.allowed && !ageResult.warnOnly) {
|
|
434
475
|
const reason = ageResult.reason || 'Package too new';
|
|
@@ -457,7 +498,7 @@ class SecurityFilterPlugin {
|
|
|
457
498
|
}
|
|
458
499
|
}
|
|
459
500
|
}
|
|
460
|
-
if ((
|
|
501
|
+
if ((_e = this.config.authorFilter) === null || _e === void 0 ? void 0 : _e.enabled) {
|
|
461
502
|
const rejected = this._rejectedVersions(pkg, data => this.authorChecker.checkAuthor(data));
|
|
462
503
|
if (rejected.versions.length > 0 && this.config.authorFilter.warnOnly) {
|
|
463
504
|
this.logger.warn(`[filter_metadata] AUTHOR WARNING: ${packageName}: ${rejected.versions.join(', ')} - ${rejected.first.reason} (warn-only mode)`);
|
|
@@ -487,7 +528,7 @@ class SecurityFilterPlugin {
|
|
|
487
528
|
}
|
|
488
529
|
catch (error) {
|
|
489
530
|
this.logger.error(`[filter_metadata] Error processing ${packageName}: ${error.message}`);
|
|
490
|
-
const errorStrategy = ((
|
|
531
|
+
const errorStrategy = ((_f = this.config.errorHandling) === null || _f === void 0 ? void 0 : _f.onFilterError) || 'fail-open';
|
|
491
532
|
if (errorStrategy === 'fail-closed') {
|
|
492
533
|
this.logger.warn(`[filter_metadata] Error handling: fail-closed - BLOCKING ${packageName}`);
|
|
493
534
|
this.metrics.recordBlock(packageName, '*', `Error during processing: ${error.message}`);
|
|
@@ -507,6 +548,7 @@ class SecurityFilterPlugin {
|
|
|
507
548
|
}
|
|
508
549
|
_checkPackageBlock(packageName, version) {
|
|
509
550
|
return __awaiter(this, void 0, void 0, function* () {
|
|
551
|
+
var _a;
|
|
510
552
|
const whitelistMode = this.config.mode === 'whitelist';
|
|
511
553
|
if (whitelistMode) {
|
|
512
554
|
const whitelistCheck = this.whitelistChecker.isWhitelisted(packageName, version);
|
|
@@ -522,7 +564,11 @@ class SecurityFilterPlugin {
|
|
|
522
564
|
}
|
|
523
565
|
const typosquat = whitelistMode ? { allowed: true } : this.typosquatChecker.check(packageName);
|
|
524
566
|
if (typosquat.warnOnly && typosquat.reason) {
|
|
525
|
-
|
|
567
|
+
const now = Date.now();
|
|
568
|
+
if (now - ((_a = this.typosquatWarnedAt.get(packageName)) !== null && _a !== void 0 ? _a : -Infinity) >= WARN_REPEAT_MS) {
|
|
569
|
+
this.typosquatWarnedAt.set(packageName, now);
|
|
570
|
+
this.logger.warn(`TYPOSQUAT WARNING: ${packageName} - ${typosquat.reason} (warn-only mode)`);
|
|
571
|
+
}
|
|
526
572
|
}
|
|
527
573
|
else if (!typosquat.allowed) {
|
|
528
574
|
return { blocked: true, reason: typosquat.reason };
|
|
@@ -554,6 +600,12 @@ class SecurityFilterPlugin {
|
|
|
554
600
|
rules.allowedScopes = this.securityRules.allowedScopes;
|
|
555
601
|
}
|
|
556
602
|
}
|
|
603
|
+
if (this.config.mode !== 'whitelist') {
|
|
604
|
+
const typosquat = this.typosquatChecker.check(packageName);
|
|
605
|
+
if (!typosquat.allowed && typosquat.target) {
|
|
606
|
+
rules.typosquat = { target: typosquat.target, distance: typosquat.distance };
|
|
607
|
+
}
|
|
608
|
+
}
|
|
557
609
|
const versionRules = this.securityRules.versionRangeRules.filter(rule => rule.package === packageName);
|
|
558
610
|
if (versionRules.length > 0) {
|
|
559
611
|
rules.versionRangeRules = versionRules.map(rule => ({
|
|
@@ -595,4 +647,6 @@ var author_checker_2 = require("./lib/author-checker");
|
|
|
595
647
|
Object.defineProperty(exports, "AuthorChecker", { enumerable: true, get: function () { return author_checker_2.AuthorChecker; } });
|
|
596
648
|
var typosquat_checker_2 = require("./lib/typosquat-checker");
|
|
597
649
|
Object.defineProperty(exports, "TyposquatChecker", { enumerable: true, get: function () { return typosquat_checker_2.TyposquatChecker; } });
|
|
650
|
+
var signature_checker_2 = require("./lib/signature-checker");
|
|
651
|
+
Object.defineProperty(exports, "SignatureChecker", { enumerable: true, get: function () { return signature_checker_2.SignatureChecker; } });
|
|
598
652
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NPM_REGISTRY_KEYS = void 0;
|
|
4
|
+
exports.NPM_REGISTRY_KEYS = [
|
|
5
|
+
{
|
|
6
|
+
expires: '2025-01-29T00:00:00.000Z',
|
|
7
|
+
keyid: 'SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA',
|
|
8
|
+
key: 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1Olb3zMAFFxXKHiIkQO5cJ3Yhl5i6UPp+IhuteBJbuHcA5UogKo0EWtlWwW6KSaKoTNEYL7JlCQiVnkhBktUgg==',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
expires: null,
|
|
12
|
+
keyid: 'SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U',
|
|
13
|
+
key: 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEY6Ya7W++7aUPzvMTrezH6Ycx3c+HOKYCcNGybJZSCJq/fd7Qa8uuAKtdIkUQtQiEKERhAmE5lMMJhP8OkDOa2g==',
|
|
14
|
+
},
|
|
15
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Version } from '@verdaccio/types';
|
|
2
|
+
import { SignatureConfig } from '../types';
|
|
3
|
+
export type SignatureStatus = 'valid' | 'invalid' | 'missing';
|
|
4
|
+
export interface SignatureResult {
|
|
5
|
+
allowed: boolean;
|
|
6
|
+
status: SignatureStatus;
|
|
7
|
+
reason?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class SignatureChecker {
|
|
10
|
+
readonly enabled: boolean;
|
|
11
|
+
readonly onMissing: 'allow' | 'warn' | 'block';
|
|
12
|
+
private readonly warnOnly;
|
|
13
|
+
private readonly keys;
|
|
14
|
+
private readonly statuses;
|
|
15
|
+
constructor(config?: SignatureConfig);
|
|
16
|
+
check(name: string, data: Version, publishedAt?: string): SignatureResult;
|
|
17
|
+
private status;
|
|
18
|
+
private verify;
|
|
19
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SignatureChecker = void 0;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
const npm_keys_1 = require("./npm-keys");
|
|
39
|
+
const lru_cache_1 = require("./lru-cache");
|
|
40
|
+
const REASONS = {
|
|
41
|
+
valid: undefined,
|
|
42
|
+
invalid: 'Invalid registry signature',
|
|
43
|
+
missing: 'Missing registry signature',
|
|
44
|
+
};
|
|
45
|
+
class SignatureChecker {
|
|
46
|
+
constructor(config) {
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
|
+
this.statuses = new lru_cache_1.LRUCache(100000);
|
|
49
|
+
this.enabled = (_a = config === null || config === void 0 ? void 0 : config.enabled) !== null && _a !== void 0 ? _a : false;
|
|
50
|
+
this.onMissing = (_b = config === null || config === void 0 ? void 0 : config.onMissing) !== null && _b !== void 0 ? _b : 'warn';
|
|
51
|
+
this.warnOnly = (_c = config === null || config === void 0 ? void 0 : config.warnOnly) !== null && _c !== void 0 ? _c : false;
|
|
52
|
+
this.keys = new Map(((_d = config === null || config === void 0 ? void 0 : config.keys) !== null && _d !== void 0 ? _d : npm_keys_1.NPM_REGISTRY_KEYS).map((k) => [k.keyid, {
|
|
53
|
+
key: crypto.createPublicKey({ key: Buffer.from(k.key, 'base64'), format: 'der', type: 'spki' }),
|
|
54
|
+
expires: k.expires ? Date.parse(k.expires) : Infinity,
|
|
55
|
+
}]));
|
|
56
|
+
}
|
|
57
|
+
check(name, data, publishedAt) {
|
|
58
|
+
if (!this.enabled) {
|
|
59
|
+
return { allowed: true, status: 'valid' };
|
|
60
|
+
}
|
|
61
|
+
const status = this.status(name, data, publishedAt);
|
|
62
|
+
const allowed = status === 'valid'
|
|
63
|
+
|| (status === 'invalid' && this.warnOnly)
|
|
64
|
+
|| (status === 'missing' && this.onMissing !== 'block');
|
|
65
|
+
const reason = REASONS[status];
|
|
66
|
+
return reason ? { allowed, status, reason } : { allowed, status };
|
|
67
|
+
}
|
|
68
|
+
status(name, data, publishedAt) {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
const integrity = (_a = data.dist) === null || _a === void 0 ? void 0 : _a.integrity;
|
|
71
|
+
const signatures = (_c = (_b = data.dist) === null || _b === void 0 ? void 0 : _b.signatures) !== null && _c !== void 0 ? _c : [];
|
|
72
|
+
const cacheKey = crypto.createHash('sha256')
|
|
73
|
+
.update(JSON.stringify([name, data.version, integrity, publishedAt, signatures.map(s => [s.keyid, s.sig])]))
|
|
74
|
+
.digest('base64');
|
|
75
|
+
let status = this.statuses.get(cacheKey);
|
|
76
|
+
if (status === undefined) {
|
|
77
|
+
status = this.verify(`${name}@${data.version}:${integrity}`, integrity, signatures, publishedAt);
|
|
78
|
+
this.statuses.set(cacheKey, status);
|
|
79
|
+
}
|
|
80
|
+
return status;
|
|
81
|
+
}
|
|
82
|
+
verify(message, integrity, signatures, publishedAt) {
|
|
83
|
+
const published = publishedAt ? Date.parse(publishedAt) : NaN;
|
|
84
|
+
const usable = signatures.flatMap(s => {
|
|
85
|
+
const key = this.keys.get(s.keyid);
|
|
86
|
+
const inDate = key && (key.expires === Infinity || published < key.expires);
|
|
87
|
+
return key && inDate ? [{ key: key.key, sig: s.sig }] : [];
|
|
88
|
+
});
|
|
89
|
+
if (!integrity || usable.length === 0) {
|
|
90
|
+
return 'missing';
|
|
91
|
+
}
|
|
92
|
+
const valid = usable.some(({ key, sig }) => {
|
|
93
|
+
try {
|
|
94
|
+
return crypto.verify('sha256', Buffer.from(message), key, Buffer.from(sig, 'base64'));
|
|
95
|
+
}
|
|
96
|
+
catch (_a) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return valid ? 'valid' : 'invalid';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.SignatureChecker = SignatureChecker;
|
package/build/types.d.ts
CHANGED
|
@@ -56,6 +56,17 @@ export interface TyposquatConfig {
|
|
|
56
56
|
ignore?: string[];
|
|
57
57
|
warnOnly?: boolean;
|
|
58
58
|
}
|
|
59
|
+
export interface RegistryKey {
|
|
60
|
+
keyid: string;
|
|
61
|
+
key: string;
|
|
62
|
+
expires: string | null;
|
|
63
|
+
}
|
|
64
|
+
export interface SignatureConfig {
|
|
65
|
+
enabled: boolean;
|
|
66
|
+
onMissing?: 'allow' | 'warn' | 'block';
|
|
67
|
+
warnOnly?: boolean;
|
|
68
|
+
keys?: RegistryKey[];
|
|
69
|
+
}
|
|
59
70
|
export interface AuthorFilterConfig {
|
|
60
71
|
enabled: boolean;
|
|
61
72
|
blockedAuthors?: string[];
|
|
@@ -84,6 +95,7 @@ export interface SecurityConfig extends Config {
|
|
|
84
95
|
packageAge?: PackageAgeConfig;
|
|
85
96
|
authorFilter?: AuthorFilterConfig;
|
|
86
97
|
typosquatting?: TyposquatConfig;
|
|
98
|
+
signatures?: SignatureConfig;
|
|
87
99
|
errorHandling?: {
|
|
88
100
|
onFilterError?: 'fail-open' | 'fail-closed';
|
|
89
101
|
onCveCheckError?: 'fail-open' | 'fail-closed';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "verdaccio-security-filter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.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",
|
|
@@ -63,11 +63,13 @@
|
|
|
63
63
|
"npm-high-impact": "^1.13.0",
|
|
64
64
|
"ts-jest": "^29.2.5",
|
|
65
65
|
"typescript": "^6.0.3",
|
|
66
|
-
"typescript-eslint": "^8.0.0"
|
|
66
|
+
"typescript-eslint": "^8.0.0",
|
|
67
|
+
"verdaccio": "^7.1.2"
|
|
67
68
|
},
|
|
68
69
|
"overrides": {
|
|
69
70
|
"qs": "6.17.1",
|
|
70
|
-
"@cypress/request": "4.0.1"
|
|
71
|
+
"@cypress/request": "4.0.1",
|
|
72
|
+
"minimatch": "11.0.9"
|
|
71
73
|
},
|
|
72
74
|
"author": {
|
|
73
75
|
"name": "Vitaliy Ponomarenko",
|