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 +24 -2
- package/build/index.d.ts +2 -0
- package/build/index.js +17 -3
- package/build/lib/popular-packages.d.ts +2 -0
- package/build/lib/popular-packages.js +1006 -0
- package/build/lib/typosquat-checker.d.ts +28 -0
- package/build/lib/typosquat-checker.js +85 -0
- package/build/types.d.ts +9 -0
- package/package.json +10 -8
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TyposquatConfig } from '../types';
|
|
2
|
+
export interface TyposquatResult {
|
|
3
|
+
allowed: boolean;
|
|
4
|
+
reason?: string;
|
|
5
|
+
target?: string;
|
|
6
|
+
distance?: number;
|
|
7
|
+
warnOnly?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class TyposquatChecker {
|
|
10
|
+
private readonly enabled;
|
|
11
|
+
private readonly maxDistance;
|
|
12
|
+
private readonly minLength;
|
|
13
|
+
private readonly warnOnly;
|
|
14
|
+
private readonly targets;
|
|
15
|
+
private readonly skip;
|
|
16
|
+
private readonly ignore;
|
|
17
|
+
private readonly matches;
|
|
18
|
+
constructor(config?: TyposquatConfig, popular?: readonly string[], known?: readonly string[]);
|
|
19
|
+
check(packageName: string): TyposquatResult;
|
|
20
|
+
private findTarget;
|
|
21
|
+
getSummary(): {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
maxDistance: number;
|
|
24
|
+
minLength: number;
|
|
25
|
+
targets: number;
|
|
26
|
+
warnOnly: boolean;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TyposquatChecker = void 0;
|
|
4
|
+
const popular_packages_1 = require("./popular-packages");
|
|
5
|
+
const lru_cache_1 = require("./lru-cache");
|
|
6
|
+
class TyposquatChecker {
|
|
7
|
+
constructor(config, popular = popular_packages_1.POPULAR_PACKAGES, known = popular_packages_1.KNOWN_PACKAGES) {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
this.matches = new lru_cache_1.LRUCache(5000);
|
|
10
|
+
this.enabled = (_a = config === null || config === void 0 ? void 0 : config.enabled) !== null && _a !== void 0 ? _a : false;
|
|
11
|
+
this.maxDistance = (_b = config === null || config === void 0 ? void 0 : config.maxDistance) !== null && _b !== void 0 ? _b : 1;
|
|
12
|
+
this.minLength = (_c = config === null || config === void 0 ? void 0 : config.minLength) !== null && _c !== void 0 ? _c : 5;
|
|
13
|
+
this.warnOnly = (_d = config === null || config === void 0 ? void 0 : config.warnOnly) !== null && _d !== void 0 ? _d : false;
|
|
14
|
+
const lower = (names = []) => names.map(n => n.toLowerCase());
|
|
15
|
+
this.targets = [...new Set([...lower(popular), ...lower(config === null || config === void 0 ? void 0 : config.protectedNames)])];
|
|
16
|
+
this.skip = new Set([...this.targets, ...lower(known)]);
|
|
17
|
+
this.ignore = new Set(lower(config === null || config === void 0 ? void 0 : config.ignore));
|
|
18
|
+
}
|
|
19
|
+
check(packageName) {
|
|
20
|
+
const name = packageName.toLowerCase();
|
|
21
|
+
if (!this.enabled || name.length < this.minLength || this.ignore.has(name) || this.skip.has(name)) {
|
|
22
|
+
return { allowed: true };
|
|
23
|
+
}
|
|
24
|
+
let match = this.matches.get(name);
|
|
25
|
+
if (match === undefined) {
|
|
26
|
+
match = this.findTarget(name);
|
|
27
|
+
this.matches.set(name, match);
|
|
28
|
+
}
|
|
29
|
+
if (!match) {
|
|
30
|
+
return { allowed: true };
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
allowed: this.warnOnly,
|
|
34
|
+
reason: `Possible typosquat of "${match.target}" (distance ${match.distance})`,
|
|
35
|
+
target: match.target,
|
|
36
|
+
distance: match.distance,
|
|
37
|
+
warnOnly: this.warnOnly,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
findTarget(name) {
|
|
41
|
+
for (const target of this.targets) {
|
|
42
|
+
if (Math.abs(target.length - name.length) > this.maxDistance) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const distance = osaDistance(name, target, this.maxDistance);
|
|
46
|
+
if (distance <= this.maxDistance) {
|
|
47
|
+
return { target, distance };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
getSummary() {
|
|
53
|
+
return {
|
|
54
|
+
enabled: this.enabled,
|
|
55
|
+
maxDistance: this.maxDistance,
|
|
56
|
+
minLength: this.minLength,
|
|
57
|
+
targets: this.targets.length,
|
|
58
|
+
warnOnly: this.warnOnly,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.TyposquatChecker = TyposquatChecker;
|
|
63
|
+
function osaDistance(a, b, max) {
|
|
64
|
+
let prev2 = [];
|
|
65
|
+
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
66
|
+
for (let i = 1; i <= a.length; i++) {
|
|
67
|
+
const row = [i];
|
|
68
|
+
let rowMin = i;
|
|
69
|
+
for (let j = 1; j <= b.length; j++) {
|
|
70
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
71
|
+
let d = Math.min(prev[j] + 1, row[j - 1] + 1, prev[j - 1] + cost);
|
|
72
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
73
|
+
d = Math.min(d, prev2[j - 2] + 1);
|
|
74
|
+
}
|
|
75
|
+
row.push(d);
|
|
76
|
+
rowMin = Math.min(rowMin, d);
|
|
77
|
+
}
|
|
78
|
+
if (rowMin > max) {
|
|
79
|
+
return max + 1;
|
|
80
|
+
}
|
|
81
|
+
prev2 = prev;
|
|
82
|
+
prev = row;
|
|
83
|
+
}
|
|
84
|
+
return prev[b.length];
|
|
85
|
+
}
|
package/build/types.d.ts
CHANGED
|
@@ -48,6 +48,14 @@ export interface PackageAgeConfig {
|
|
|
48
48
|
minVersionAgeDays?: number;
|
|
49
49
|
warnOnly?: boolean;
|
|
50
50
|
}
|
|
51
|
+
export interface TyposquatConfig {
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
maxDistance?: number;
|
|
54
|
+
minLength?: number;
|
|
55
|
+
protectedNames?: string[];
|
|
56
|
+
ignore?: string[];
|
|
57
|
+
warnOnly?: boolean;
|
|
58
|
+
}
|
|
51
59
|
export interface AuthorFilterConfig {
|
|
52
60
|
enabled: boolean;
|
|
53
61
|
blockedAuthors?: string[];
|
|
@@ -75,6 +83,7 @@ export interface SecurityConfig extends Config {
|
|
|
75
83
|
webhook?: WebhookConfig;
|
|
76
84
|
packageAge?: PackageAgeConfig;
|
|
77
85
|
authorFilter?: AuthorFilterConfig;
|
|
86
|
+
typosquatting?: TyposquatConfig;
|
|
78
87
|
errorHandling?: {
|
|
79
88
|
onFilterError?: 'fail-open' | 'fail-closed';
|
|
80
89
|
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.6.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",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"test": "jest",
|
|
38
38
|
"test:watch": "jest --watch",
|
|
39
39
|
"test:coverage": "jest --coverage",
|
|
40
|
+
"update:popular": "node scripts/update-popular-packages.mjs",
|
|
40
41
|
"test:e2e": "npm run build && jest --testMatch \"**/*.e2e.ts\" --coverage=false",
|
|
41
42
|
"debug:verdaccio": "node --inspect-brk $(which verdaccio)",
|
|
42
43
|
"debug:build": "npm run build && npm link",
|
|
@@ -51,16 +52,17 @@
|
|
|
51
52
|
"semver": "^7.7.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@eslint/js": "^
|
|
55
|
+
"@eslint/js": "^10.0.1",
|
|
55
56
|
"@types/express": "^5.0.6",
|
|
56
|
-
"@types/jest": "^
|
|
57
|
-
"@types/node": "^22.
|
|
57
|
+
"@types/jest": "^30.0.0",
|
|
58
|
+
"@types/node": "^22.20.5",
|
|
58
59
|
"@types/semver": "^7.0.0",
|
|
59
|
-
"@verdaccio/types": "^10.
|
|
60
|
-
"eslint": "^
|
|
61
|
-
"jest": "^
|
|
60
|
+
"@verdaccio/types": "^10.8.0",
|
|
61
|
+
"eslint": "^10.15.0",
|
|
62
|
+
"jest": "^30.5.2",
|
|
63
|
+
"npm-high-impact": "^1.13.0",
|
|
62
64
|
"ts-jest": "^29.2.5",
|
|
63
|
-
"typescript": "^
|
|
65
|
+
"typescript": "^6.0.3",
|
|
64
66
|
"typescript-eslint": "^8.0.0"
|
|
65
67
|
},
|
|
66
68
|
"overrides": {
|