@efraindrummer/ghostdeps 0.3.0 → 0.5.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/CHANGELOG.md +20 -0
- package/README.md +131 -5
- package/dist/analyzer.js +4 -1
- package/dist/cli.js +257 -9
- package/dist/clients/npm.js +48 -0
- package/dist/config.js +35 -1
- package/dist/diff/inspect.js +223 -0
- package/dist/fix/remediator.js +124 -0
- package/dist/hooks/githook.js +84 -0
- package/dist/notifications/webhook.js +98 -0
- package/dist/parser/lockfile.js +208 -16
- package/dist/render/html.js +562 -0
- package/dist/render/sarif.js +18 -0
- package/dist/scoring/scoring.js +22 -0
- package/dist/scoring/signals.js +11 -1
- package/dist/security/licenses.js +58 -0
- package/dist/security/typosquatting.js +181 -0
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Módulo de auditoría y compliance legal de licencias de software.
|
|
3
|
+
* Clasifica licencias permisivas vs copyleft (GPL/AGPL) y evalúa
|
|
4
|
+
* reglas de inclusión/exclusión del proyecto.
|
|
5
|
+
*/
|
|
6
|
+
const COPYLEFT_REGEX = /\b(gpl|agpl|lgpl|sspl|eupl|osl)\b/i;
|
|
7
|
+
/**
|
|
8
|
+
* Normaliza nombres de licencias (ej. "Apache 2.0" -> "Apache-2.0").
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeLicense(lic) {
|
|
11
|
+
if (!lic || !lic.trim())
|
|
12
|
+
return 'UNKNOWN';
|
|
13
|
+
const clean = lic.trim();
|
|
14
|
+
if (/^apache\s*2(\.0)?$/i.test(clean))
|
|
15
|
+
return 'Apache-2.0';
|
|
16
|
+
if (/^bsd\s*3[\s-]*clause$/i.test(clean))
|
|
17
|
+
return 'BSD-3-Clause';
|
|
18
|
+
if (/^bsd\s*2[\s-]*clause$/i.test(clean))
|
|
19
|
+
return 'BSD-2-Clause';
|
|
20
|
+
if (/^mit$/i.test(clean))
|
|
21
|
+
return 'MIT';
|
|
22
|
+
if (/^isc$/i.test(clean))
|
|
23
|
+
return 'ISC';
|
|
24
|
+
return clean;
|
|
25
|
+
}
|
|
26
|
+
export function checkLicenseCompliance(rawLicense, options = {}) {
|
|
27
|
+
const license = normalizeLicense(rawLicense);
|
|
28
|
+
const isUnlicensed = license === 'UNKNOWN' ||
|
|
29
|
+
/^unlicensed$/i.test(license) ||
|
|
30
|
+
/^see license in/i.test(license);
|
|
31
|
+
const isCopyleft = COPYLEFT_REGEX.test(license);
|
|
32
|
+
const allowed = options.allowedLicenses?.map((l) => l.trim().toLowerCase());
|
|
33
|
+
const denied = options.deniedLicenses?.map((l) => l.trim().toLowerCase());
|
|
34
|
+
let isDenied = false;
|
|
35
|
+
let reason;
|
|
36
|
+
const licLower = license.toLowerCase();
|
|
37
|
+
if (denied && denied.some((d) => licLower === d || licLower.includes(d))) {
|
|
38
|
+
isDenied = true;
|
|
39
|
+
reason = `Licencia "${license}" denegada explícitamente por política del proyecto`;
|
|
40
|
+
}
|
|
41
|
+
else if (allowed && allowed.length > 0 && !allowed.some((a) => licLower === a || licLower.includes(a))) {
|
|
42
|
+
isDenied = true;
|
|
43
|
+
reason = `Licencia "${license}" no forma parte de las licencias permitidas`;
|
|
44
|
+
}
|
|
45
|
+
else if (isUnlicensed) {
|
|
46
|
+
reason = 'Dependencia sin licencia formal declarada (riesgo de propiedad intelectual)';
|
|
47
|
+
}
|
|
48
|
+
else if (isCopyleft) {
|
|
49
|
+
reason = `Licencia con cláusula Copyleft (${license}) que puede comprometer código privativo`;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
license,
|
|
53
|
+
isCopyleft,
|
|
54
|
+
isDenied,
|
|
55
|
+
isUnlicensed,
|
|
56
|
+
reason,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Módulo de detección de Typosquatting y confusión de dependencias.
|
|
3
|
+
* Compara las dependencias analizadas contra un registro de paquetes populares de npm
|
|
4
|
+
* calculando distancia de Levenshtein y normalización de separadores.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Top 120 paquetes más populares y atacados del ecosistema npm.
|
|
8
|
+
*/
|
|
9
|
+
export const TOP_NPM_PACKAGES = Object.freeze([
|
|
10
|
+
'express',
|
|
11
|
+
'react',
|
|
12
|
+
'react-dom',
|
|
13
|
+
'vue',
|
|
14
|
+
'angular',
|
|
15
|
+
'lodash',
|
|
16
|
+
'axios',
|
|
17
|
+
'chalk',
|
|
18
|
+
'commander',
|
|
19
|
+
'debug',
|
|
20
|
+
'dotenv',
|
|
21
|
+
'moment',
|
|
22
|
+
'request',
|
|
23
|
+
'uuid',
|
|
24
|
+
'winston',
|
|
25
|
+
'typescript',
|
|
26
|
+
'tslib',
|
|
27
|
+
'glob',
|
|
28
|
+
'semver',
|
|
29
|
+
'rxjs',
|
|
30
|
+
'webpack',
|
|
31
|
+
'esbuild',
|
|
32
|
+
'vite',
|
|
33
|
+
'cross-env',
|
|
34
|
+
'core-js',
|
|
35
|
+
'body-parser',
|
|
36
|
+
'cookie-parser',
|
|
37
|
+
'cors',
|
|
38
|
+
'fs-extra',
|
|
39
|
+
'async',
|
|
40
|
+
'yargs',
|
|
41
|
+
'prettier',
|
|
42
|
+
'eslint',
|
|
43
|
+
'postcss',
|
|
44
|
+
'rimraf',
|
|
45
|
+
'mkdirp',
|
|
46
|
+
'minimist',
|
|
47
|
+
'inquirer',
|
|
48
|
+
'nodemon',
|
|
49
|
+
'superagent',
|
|
50
|
+
'mongoose',
|
|
51
|
+
'sequelize',
|
|
52
|
+
'prisma',
|
|
53
|
+
'next',
|
|
54
|
+
'jest',
|
|
55
|
+
'vitest',
|
|
56
|
+
'mocha',
|
|
57
|
+
'chai',
|
|
58
|
+
'bcrypt',
|
|
59
|
+
'jsonwebtoken',
|
|
60
|
+
'passport',
|
|
61
|
+
'socket.io',
|
|
62
|
+
'cheerio',
|
|
63
|
+
'sharp',
|
|
64
|
+
'puppeteer',
|
|
65
|
+
'playwright',
|
|
66
|
+
'babel-core',
|
|
67
|
+
'webpack-cli',
|
|
68
|
+
'ts-node',
|
|
69
|
+
'colors',
|
|
70
|
+
'chokidar',
|
|
71
|
+
'nanoid',
|
|
72
|
+
'ora',
|
|
73
|
+
'nodemailer',
|
|
74
|
+
'ioredis',
|
|
75
|
+
'redis',
|
|
76
|
+
'pg',
|
|
77
|
+
'mysql2',
|
|
78
|
+
'ws',
|
|
79
|
+
'fastify',
|
|
80
|
+
'got',
|
|
81
|
+
'node-fetch',
|
|
82
|
+
'undici',
|
|
83
|
+
'dayjs',
|
|
84
|
+
'date-fns',
|
|
85
|
+
'zod',
|
|
86
|
+
'yup',
|
|
87
|
+
'joi',
|
|
88
|
+
'dotenv-expand',
|
|
89
|
+
'dotenv-safe',
|
|
90
|
+
'commander',
|
|
91
|
+
'minimatch',
|
|
92
|
+
'source-map',
|
|
93
|
+
'path-to-regexp',
|
|
94
|
+
'tar',
|
|
95
|
+
'archiver',
|
|
96
|
+
'adm-zip',
|
|
97
|
+
'yaml',
|
|
98
|
+
'multer',
|
|
99
|
+
'helmet',
|
|
100
|
+
'morgan',
|
|
101
|
+
'node-sass',
|
|
102
|
+
'sass',
|
|
103
|
+
'less',
|
|
104
|
+
'pnpm',
|
|
105
|
+
'yarn',
|
|
106
|
+
'npm',
|
|
107
|
+
]);
|
|
108
|
+
/**
|
|
109
|
+
* Distancia de Levenshtein (número mínimo de inserciones, borrados o sustituciones).
|
|
110
|
+
*/
|
|
111
|
+
export function levenshtein(a, b) {
|
|
112
|
+
if (a === b)
|
|
113
|
+
return 0;
|
|
114
|
+
if (!a.length)
|
|
115
|
+
return b.length;
|
|
116
|
+
if (!b.length)
|
|
117
|
+
return a.length;
|
|
118
|
+
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
119
|
+
for (let i = 1; i <= a.length; i++) {
|
|
120
|
+
let prev = i;
|
|
121
|
+
for (let j = 1; j <= b.length; j++) {
|
|
122
|
+
const val = a[i - 1] === b[j - 1] ? row[j - 1] : Math.min(row[j - 1], row[j], prev) + 1;
|
|
123
|
+
row[j - 1] = prev;
|
|
124
|
+
prev = val;
|
|
125
|
+
}
|
|
126
|
+
row[b.length] = prev;
|
|
127
|
+
}
|
|
128
|
+
return row[b.length];
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Inspecciona un nombre de paquete para determinar si es un intento de typosquatting.
|
|
132
|
+
*/
|
|
133
|
+
export function detectTyposquatting(packageName, topPackages = TOP_NPM_PACKAGES) {
|
|
134
|
+
const normalizedSuspect = packageName.toLowerCase().trim();
|
|
135
|
+
// Extraer el nombre base si tiene scope (@scope/pkg -> pkg)
|
|
136
|
+
const baseSuspect = normalizedSuspect.startsWith('@')
|
|
137
|
+
? (normalizedSuspect.split('/')[1] ?? normalizedSuspect)
|
|
138
|
+
: normalizedSuspect;
|
|
139
|
+
// Si es exactamente el paquete legítimo, no es typosquatting
|
|
140
|
+
if (topPackages.includes(baseSuspect)) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
const strippedSuspect = baseSuspect.replace(/[-_.]/g, '');
|
|
144
|
+
for (const target of topPackages) {
|
|
145
|
+
const strippedTarget = target.replace(/[-_.]/g, '');
|
|
146
|
+
// 1. Caso separadores omitidos o cambiados: e.g. "crossenv" vs "cross-env", "fsextra" vs "fs-extra"
|
|
147
|
+
if (strippedSuspect === strippedTarget && baseSuspect !== target) {
|
|
148
|
+
return {
|
|
149
|
+
suspectName: packageName,
|
|
150
|
+
targetPackage: target,
|
|
151
|
+
similarityReason: `Nombre idéntico omitiendo o alterando separadores respecto al popular "${target}"`,
|
|
152
|
+
distance: 1,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
// 2. Distancia de Levenshtein = 1 (e.g. "loadsh" -> "lodash", "cha1k" -> "chalk")
|
|
156
|
+
if (Math.abs(baseSuspect.length - target.length) <= 1 && target.length >= 4) {
|
|
157
|
+
const dist = levenshtein(baseSuspect, target);
|
|
158
|
+
if (dist === 1) {
|
|
159
|
+
return {
|
|
160
|
+
suspectName: packageName,
|
|
161
|
+
targetPackage: target,
|
|
162
|
+
similarityReason: `Difiere por solo 1 carácter del paquete popular "${target}" (posible engaño visual)`,
|
|
163
|
+
distance: 1,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// 3. Distancia de Levenshtein = 2 para paquetes largos (>= 8 caracteres)
|
|
168
|
+
if (Math.abs(baseSuspect.length - target.length) <= 2 && target.length >= 8) {
|
|
169
|
+
const dist = levenshtein(baseSuspect, target);
|
|
170
|
+
if (dist === 2) {
|
|
171
|
+
return {
|
|
172
|
+
suspectName: packageName,
|
|
173
|
+
targetPackage: target,
|
|
174
|
+
similarityReason: `Difiere por 2 caracteres del paquete popular "${target}"`,
|
|
175
|
+
distance: 2,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@efraindrummer/ghostdeps",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Detecta dependencias fantasma (abandonadas, bus factor bajo o con señales de secuestro) evaluando la salud social y de mantenimiento del repositorio origen.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"supply-chain",
|