verdaccio-security-filter 1.5.1 → 1.6.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
@@ -6,6 +6,7 @@ Advanced security filter plugin for Verdaccio with **dual-layer protection archi
6
6
  [![npm version](https://img.shields.io/npm/v/verdaccio-security-filter.svg)](https://www.npmjs.com/package/verdaccio-security-filter)
7
7
  [![npm downloads](https://img.shields.io/npm/dm/verdaccio-security-filter.svg)](https://www.npmjs.com/package/verdaccio-security-filter)
8
8
  [![CI](https://github.com/ponomarenko/verdaccio-security-filter/actions/workflows/ci.yml/badge.svg)](https://github.com/ponomarenko/verdaccio-security-filter/actions/workflows/ci.yml)
9
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/ponomarenko/verdaccio-security-filter/badge)](https://scorecard.dev/viewer/?uri=github.com/ponomarenko/verdaccio-security-filter)
9
10
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue)]()
10
11
  [![Node](https://img.shields.io/badge/node-%3E%3D22-brightgreen)](./package.json)
11
12
  [![Verdaccio](https://img.shields.io/badge/Verdaccio-6.x%20%7C%207.x-orange)]()
@@ -70,6 +71,7 @@ This plugin implements **two independent security layers** for complete protecti
70
71
  - **Minimum Package Age** - Require packages to exist for a minimum number of days
71
72
  - **Minimum Version Age** - Require specific versions to exist for a minimum number of days
72
73
  - **Warn-Only Mode** - Log warnings without blocking
74
+ - **Typosquatting Detection** - Block names one typo away from a popular npm package or your own protected names (`lodahs`, `expres`)
73
75
  - **Author Filtering** - Block packages based on author information
74
76
  - **Block by Author Name** - Block specific author names or patterns
75
77
  - **Block by Email** - Block specific email addresses or patterns
@@ -101,7 +103,6 @@ This plugin implements **two independent security layers** for complete protecti
101
103
 
102
104
  #### Planned
103
105
  - [ ] **Package signature verification** - check npm registry signatures and provenance attestations
104
- - [ ] **Typosquatting detection** - flag names within a small edit distance of popular packages
105
106
 
106
107
  #### Under consideration
107
108
  These wait for a concrete request:
@@ -111,6 +112,7 @@ These wait for a concrete request:
111
112
 
112
113
  #### Done
113
114
  - [x] **Dry-run mode** - `dryRun: true`
115
+ - [x] **Typosquatting detection** - `typosquatting`: names within a small edit distance of popular packages
114
116
  - [x] **Webhook notifications** - `webhook`: block events as JSON or as a Slack message
115
117
 
116
118
  #### Not planned
@@ -573,6 +575,26 @@ The `slack` body:
573
575
 
574
576
  Every version is checked against the author rules: versions published by a blocked author are removed from the metadata, and the package is blocked as a whole only when no version is left.
575
577
 
578
+ ### Typosquatting Options
579
+
580
+ | Option | Type | Default | Description |
581
+ |--------|------|---------|-------------|
582
+ | `typosquatting.enabled` | `boolean` | `false` | Enable typosquatting detection |
583
+ | `typosquatting.maxDistance` | `number` | `1` | Edits allowed between a name and a target; swapping two adjacent letters counts as one |
584
+ | `typosquatting.minLength` | `number` | `5` | Names shorter than this are not checked |
585
+ | `typosquatting.protectedNames` | `string[]` | `[]` | Extra names to protect, e.g. your internal packages |
586
+ | `typosquatting.ignore` | `string[]` | `[]` | Names never flagged, for false positives |
587
+ | `typosquatting.warnOnly` | `boolean` | `false` | Only warn, don't block |
588
+
589
+ The targets are the top 1000 npm packages by downloads plus `protectedNames`. A name that is itself one of the ~17,000 established npm packages (such as `preact` next to `react`) is never flagged. The list ships with the plugin, so no request leaves the registry, and results are cached per name (last 5000); maintainers refresh it with `npm run update:popular`. In `mode: whitelist` the check is skipped: the whitelist already decides which names are allowed.
590
+
591
+ ```yaml
592
+ typosquatting:
593
+ enabled: true
594
+ protectedNames: ['@acme/core', 'acme-ui']
595
+ ignore: ['lodash-ext']
596
+ ```
597
+
576
598
  ### Error Handling Options
577
599
 
578
600
  | Option | Type | Default | Description |
@@ -808,7 +830,7 @@ authorFilter:
808
830
  5. **Enable Author Filtering** - Block packages from untrusted authors or regions
809
831
  6. **Enable Metrics** - Track security events for audit and compliance
810
832
  7. **Regular Updates** - Keep the plugin and CVE database cache updated
811
- 8. **Test Rules** - Use dry run mode (planned) before applying strict rules
833
+ 8. **Test Rules** - Use dry-run mode (`dryRun: true`) before applying strict rules
812
834
  9. **Monitor Logs** - Review security logs regularly for suspicious activity
813
835
 
814
836
  ## 🐛 Troubleshooting
package/build/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export default class SecurityFilterPlugin implements IPluginMiddleware<SecurityC
14
14
  private readonly licenseChecker;
15
15
  private readonly packageAgeChecker;
16
16
  private readonly authorChecker;
17
+ private readonly typosquatChecker;
17
18
  constructor(config: SecurityConfig, options: PluginOptions<SecurityConfig>);
18
19
  private _parseVersionRangeRules;
19
20
  private _logInitialization;
@@ -40,4 +41,5 @@ export { CVEChecker } from './lib/cve-checker';
40
41
  export { LicenseChecker } from './lib/license-checker';
41
42
  export { PackageAgeChecker } from './lib/package-age-checker';
42
43
  export { AuthorChecker } from './lib/author-checker';
44
+ export { TyposquatChecker } from './lib/typosquat-checker';
43
45
  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.AuthorChecker = exports.PackageAgeChecker = exports.LicenseChecker = exports.CVEChecker = exports.WhitelistChecker = exports.WebhookNotifier = exports.MetricsCollector = exports.SecurityLogger = void 0;
48
+ 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");
@@ -56,6 +56,7 @@ const cve_checker_1 = require("./lib/cve-checker");
56
56
  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
+ const typosquat_checker_1 = require("./lib/typosquat-checker");
59
60
  const lru_cache_1 = require("./lib/lru-cache");
60
61
  const webhook_1 = require("./lib/webhook");
61
62
  const PLUGIN_VERSION = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '..', 'package.json'), 'utf8')).version;
@@ -80,6 +81,7 @@ class SecurityFilterPlugin {
80
81
  this.licenseChecker = new license_checker_1.LicenseChecker(this.config.licenses);
81
82
  this.packageAgeChecker = new package_age_checker_1.PackageAgeChecker(this.config.packageAge);
82
83
  this.authorChecker = new author_checker_1.AuthorChecker(this.config.authorFilter);
84
+ this.typosquatChecker = new typosquat_checker_1.TyposquatChecker(this.config.typosquatting);
83
85
  this.securityRules = {
84
86
  blockedVersions: this.config.blockedVersions || [],
85
87
  blockedPatterns: this.config.blockedPatterns || [],
@@ -151,7 +153,7 @@ class SecurityFilterPlugin {
151
153
  }
152
154
  }
153
155
  _getEnabledFeatures() {
154
- var _a, _b, _c, _d;
156
+ var _a, _b, _c, _d, _e;
155
157
  const features = [];
156
158
  if (this.config.dryRun)
157
159
  features.push('dry-run');
@@ -169,6 +171,8 @@ class SecurityFilterPlugin {
169
171
  features.push('package-age-verification');
170
172
  if ((_d = this.config.authorFilter) === null || _d === void 0 ? void 0 : _d.enabled)
171
173
  features.push('author-filtering');
174
+ if ((_e = this.config.typosquatting) === null || _e === void 0 ? void 0 : _e.enabled)
175
+ features.push('typosquat-detection');
172
176
  if (this.securityRules.versionRangeRules.length > 0)
173
177
  features.push('version-range-rules');
174
178
  if (this.securityRules.blockedPatterns.length > 0)
@@ -503,7 +507,8 @@ class SecurityFilterPlugin {
503
507
  }
504
508
  _checkPackageBlock(packageName, version) {
505
509
  return __awaiter(this, void 0, void 0, function* () {
506
- if (this.config.mode === 'whitelist') {
510
+ const whitelistMode = this.config.mode === 'whitelist';
511
+ if (whitelistMode) {
507
512
  const whitelistCheck = this.whitelistChecker.isWhitelisted(packageName, version);
508
513
  if (!whitelistCheck.allowed) {
509
514
  return { blocked: true, reason: whitelistCheck.reason || 'Package is not in whitelist' };
@@ -515,6 +520,13 @@ class SecurityFilterPlugin {
515
520
  if (!this._isScopeAllowed(packageName)) {
516
521
  return { blocked: true, reason: 'Package scope not allowed' };
517
522
  }
523
+ const typosquat = whitelistMode ? { allowed: true } : this.typosquatChecker.check(packageName);
524
+ if (typosquat.warnOnly && typosquat.reason) {
525
+ this.logger.warn(`TYPOSQUAT WARNING: ${packageName} - ${typosquat.reason} (warn-only mode)`);
526
+ }
527
+ else if (!typosquat.allowed) {
528
+ return { blocked: true, reason: typosquat.reason };
529
+ }
518
530
  const versionReason = version ? this._versionBlockReason(packageName, version) : null;
519
531
  if (versionReason) {
520
532
  return { blocked: true, reason: versionReason };
@@ -581,4 +593,6 @@ var package_age_checker_2 = require("./lib/package-age-checker");
581
593
  Object.defineProperty(exports, "PackageAgeChecker", { enumerable: true, get: function () { return package_age_checker_2.PackageAgeChecker; } });
582
594
  var author_checker_2 = require("./lib/author-checker");
583
595
  Object.defineProperty(exports, "AuthorChecker", { enumerable: true, get: function () { return author_checker_2.AuthorChecker; } });
596
+ var typosquat_checker_2 = require("./lib/typosquat-checker");
597
+ Object.defineProperty(exports, "TyposquatChecker", { enumerable: true, get: function () { return typosquat_checker_2.TyposquatChecker; } });
584
598
  __exportStar(require("./types"), exports);
@@ -0,0 +1,2 @@
1
+ export declare const POPULAR_PACKAGES: readonly string[];
2
+ export declare const KNOWN_PACKAGES: readonly string[];