@theoptimalpartner/npm-security-kit 1.0.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 ADDED
@@ -0,0 +1,495 @@
1
+ # NPM Security Kit 🛡️
2
+
3
+ **Protección instant contra paquetes maliciosos y vulnerabilidades**
4
+
5
+ Kit portable y reutilizable para proteger cualquier proyecto Node.js/npm contra:
6
+ - ✅ 175+ paquetes maliciosos conocidos (campaña de phishing Oct 2025)
7
+ - ✅ Vulnerabilidades en dependencias
8
+ - ✅ Supply chain attacks
9
+ - ✅ Typosquatting
10
+ - ✅ Malware en dependencias transitivas
11
+
12
+ ---
13
+
14
+ ## 🚀 Instalación Rápida (2 minutos)
15
+
16
+ ### Opción 1: Instalación Automática (Recomendado)
17
+
18
+ ```bash
19
+ # Desde la raíz de tu proyecto
20
+ curl -sSL https://raw.githubusercontent.com/tu-org/npm-security-kit/main/install.sh | bash
21
+ ```
22
+
23
+ O si tienes el kit localmente:
24
+
25
+ ```bash
26
+ # Desde la raíz de tu proyecto
27
+ bash /ruta/a/npm-security-kit/install.sh
28
+ ```
29
+
30
+ ### Opción 2: Instalación Manual (3 pasos)
31
+
32
+ ```bash
33
+ # 1. Copiar archivos de seguridad
34
+ cp -r /ruta/a/npm-security-kit/template/.security .
35
+ cp -r /ruta/a/npm-security-kit/template/scripts .
36
+ cp -r /ruta/a/npm-security-kit/template/.github .
37
+
38
+ # 2. Hacer scripts ejecutables
39
+ chmod +x scripts/*.sh
40
+
41
+ # 3. Agregar scripts a package.json
42
+ # Ver sección "Scripts NPM" más abajo
43
+ ```
44
+
45
+ ---
46
+
47
+ ## 📦 ¿Qué Incluye?
48
+
49
+ ### Archivos Instalados
50
+
51
+ ```
52
+ tu-proyecto/
53
+ ├── .github/
54
+ │ ├── workflows/
55
+ │ │ └── security-audit.yml # GitHub Actions automático
56
+ │ └── dependabot.yml # Actualizaciones automáticas
57
+ ├── .security/
58
+ │ ├── malicious-packages-blacklist.json # 175+ paquetes maliciosos
59
+ │ └── config.json # Configuración personalizable
60
+ ├── scripts/
61
+ │ ├── check-malicious-packages.sh # Verificar paquetes maliciosos
62
+ │ └── security-check.sh # Auditoría completa
63
+ └── SECURITY.md # Documentación
64
+ ```
65
+
66
+ ### Scripts NPM Agregados
67
+
68
+ ```json
69
+ {
70
+ "scripts": {
71
+ "security:check": "./scripts/security-check.sh",
72
+ "security:check-malicious": "./scripts/check-malicious-packages.sh",
73
+ "security:audit": "npm audit --audit-level=moderate",
74
+ "security:audit:fix": "npm audit fix",
75
+ "security:outdated": "npm outdated",
76
+ "security:licenses": "npm list --json | jq -r '.dependencies | to_entries[] | \"\\(.key): \\(.value.license)\"'",
77
+ "security:full": "npm run security:audit && npm run security:check"
78
+ }
79
+ }
80
+ ```
81
+
82
+ ---
83
+
84
+ ## 🎯 Uso Diario
85
+
86
+ ### Antes de Instalar un Paquete
87
+
88
+ ```bash
89
+ # Verificar si un paquete es seguro
90
+ npm run security:check-malicious
91
+
92
+ # Ver info del paquete
93
+ npm info paquete-nombre
94
+ ```
95
+
96
+ ### Después de Instalar Dependencias
97
+
98
+ ```bash
99
+ # Verificación rápida
100
+ npm run security:audit
101
+
102
+ # Verificación completa (recomendado)
103
+ npm run security:full
104
+ ```
105
+
106
+ ### Antes de Deploy
107
+
108
+ ```bash
109
+ # Auditoría completa
110
+ npm run security:full
111
+
112
+ # Si hay problemas, auto-fix
113
+ npm run security:audit:fix
114
+ ```
115
+
116
+ ---
117
+
118
+ ## ⚙️ Configuración
119
+
120
+ ### Personalizar para tu Proyecto
121
+
122
+ Edita `.security/config.json`:
123
+
124
+ ```json
125
+ {
126
+ "projectName": "mi-proyecto",
127
+ "projectType": "node",
128
+ "excludeDirs": ["node_modules", "dist", "build"],
129
+ "strictMode": true,
130
+ "notifications": {
131
+ "email": "security@tuempresa.com",
132
+ "slack": "https://hooks.slack.com/..."
133
+ }
134
+ }
135
+ ```
136
+
137
+ ### Tipos de Proyecto Soportados
138
+
139
+ - `node` - Proyectos Node.js backend
140
+ - `react` - Aplicaciones React
141
+ - `nextjs` - Aplicaciones Next.js
142
+ - `vue` - Aplicaciones Vue.js
143
+ - `express` - APIs Express
144
+ - `serverless` - Funciones serverless
145
+ - `library` - Librerías npm
146
+
147
+ ---
148
+
149
+ ## 🔒 Características
150
+
151
+ ### 1. Verificación de Paquetes Maliciosos
152
+
153
+ **Blacklist de 175+ paquetes conocidos**:
154
+ - Campaña de phishing Oct 2025
155
+ - Patrones maliciosos (`redirect-*`)
156
+ - Dominios de phishing
157
+ - Cuentas npm comprometidas
158
+
159
+ ```bash
160
+ npm run security:check-malicious
161
+ ```
162
+
163
+ ### 2. Auditoría Automática
164
+
165
+ **npm audit mejorado**:
166
+ - Verifica vulnerabilidades conocidas
167
+ - Auto-fix cuando es posible
168
+ - Reportes detallados
169
+
170
+ ```bash
171
+ npm run security:audit
172
+ ```
173
+
174
+ ### 3. GitHub Actions
175
+
176
+ **Verificación en cada PR/Push**:
177
+ - ✅ npm audit
178
+ - ✅ Paquetes maliciosos
179
+ - ✅ Dependency review
180
+ - ✅ License compliance
181
+ - ✅ Secrets detection
182
+
183
+ **Ejecución semanal automática** (Lunes 9am UTC)
184
+
185
+ ### 4. Dependabot
186
+
187
+ **Actualizaciones automáticas**:
188
+ - Security patches prioritarios
189
+ - Agrupación inteligente
190
+ - PRs con contexto
191
+
192
+ ### 5. Pre-commit Hooks (Opcional)
193
+
194
+ Instalar con Husky:
195
+
196
+ ```bash
197
+ npm install --save-dev husky
198
+ npx husky init
199
+ echo "npm run security:check-malicious" > .husky/pre-commit
200
+ ```
201
+
202
+ ---
203
+
204
+ ## 📊 Ejemplos de Salida
205
+
206
+ ### ✅ Proyecto Limpio
207
+
208
+ ```
209
+ ========================================
210
+ Malicious Package Detection
211
+ ========================================
212
+
213
+ Loading blacklist...
214
+ ✓ Loaded 175 malicious packages
215
+ Source: Socket.dev - 175 Malicious npm Packages...
216
+ Last Updated: 2025-10-20
217
+
218
+ Analyzing installed packages...
219
+ Total installed packages: 342
220
+
221
+ Checking against blacklist...
222
+
223
+ Checking against malicious patterns...
224
+
225
+ ========================================
226
+ Results
227
+ ========================================
228
+ ✓ No malicious packages detected
229
+
230
+ Summary:
231
+ - Checked: 342 packages
232
+ - Against: 175 known malicious packages
233
+ - Found: 0 threats
234
+ ```
235
+
236
+ ### ❌ Amenaza Detectada
237
+
238
+ ```
239
+ ========================================
240
+ Results
241
+ ========================================
242
+ ✗ MALICIOUS PACKAGES FOUND!
243
+
244
+ Summary:
245
+ - Direct matches: 1
246
+ - Pattern matches: 0
247
+ - Total threats: 1
248
+
249
+ Malicious packages found:
250
+ - redirect-abc123 (direct match)
251
+
252
+ IMMEDIATE ACTIONS REQUIRED:
253
+ 1. DO NOT use this application
254
+ 2. Uninstall malicious packages immediately
255
+ 3. Review application logs for suspicious activity
256
+ 4. Check for data exfiltration
257
+ 5. Report to security team
258
+ ```
259
+
260
+ ---
261
+
262
+ ## 🔄 Actualización
263
+
264
+ ### Actualizar Blacklist
265
+
266
+ ```bash
267
+ # Descargar última blacklist
268
+ curl -o .security/malicious-packages-blacklist.json \
269
+ https://raw.githubusercontent.com/tu-org/npm-security-kit/main/blacklist.json
270
+
271
+ # Verificar
272
+ npm run security:check-malicious
273
+ ```
274
+
275
+ ### Actualizar Scripts
276
+
277
+ ```bash
278
+ # Re-ejecutar instalación (preserva config)
279
+ bash /ruta/a/npm-security-kit/install.sh --update
280
+ ```
281
+
282
+ ---
283
+
284
+ ## 🎓 Mejores Prácticas
285
+
286
+ ### 1. Verificar Antes de Instalar
287
+
288
+ ```bash
289
+ # ❌ NO HACER
290
+ npm install paquete-random
291
+
292
+ # ✅ HACER
293
+ npm info paquete-random
294
+ npm view paquete-random repository
295
+ npm view paquete-random license
296
+ npm install paquete-random
297
+ npm run security:check-malicious
298
+ ```
299
+
300
+ ### 2. Mantener Dependencias Actualizadas
301
+
302
+ ```bash
303
+ # Ver paquetes desactualizados
304
+ npm run security:outdated
305
+
306
+ # Actualizar con cuidado
307
+ npm update
308
+ npm run security:full
309
+ ```
310
+
311
+ ### 3. Revisar Dependabot PRs
312
+
313
+ - ✅ Priorizar PRs de seguridad
314
+ - ✅ Leer changelog antes de aprobar
315
+ - ✅ Probar en staging primero
316
+
317
+ ### 4. Auditorías Regulares
318
+
319
+ | Frecuencia | Acción | Comando |
320
+ |------------|--------|---------|
321
+ | **Diario** | Revisar Dependabot PRs | GitHub UI |
322
+ | **Semanal** | GitHub Actions (automático) | - |
323
+ | **Mensual** | Auditoría manual completa | `npm run security:full` |
324
+ | **Trimestral** | Actualizar blacklist | Ver sección Actualización |
325
+
326
+ ---
327
+
328
+ ## 🚨 Respuesta a Incidentes
329
+
330
+ ### Si se Detecta un Paquete Malicioso
331
+
332
+ 1. **DETENER** - No desplegar ni ejecutar
333
+ 2. **AISLAR** - Marcar entorno como comprometido
334
+ 3. **ANALIZAR**:
335
+ ```bash
336
+ npm run security:check-malicious
337
+ npm list | grep nombre-paquete
338
+ git log package-lock.json
339
+ ```
340
+ 4. **REMOVER**:
341
+ ```bash
342
+ npm uninstall nombre-paquete
343
+ npm audit
344
+ npm run security:full
345
+ ```
346
+ 5. **INVESTIGAR**:
347
+ - Revisar logs de aplicación
348
+ - Verificar conexiones de red
349
+ - Buscar data exfiltration
350
+ 6. **REPORTAR**:
351
+ - Equipo de seguridad interno
352
+ - npm security (security@npmjs.com)
353
+ - Socket.dev (https://socket.dev/report)
354
+
355
+ ---
356
+
357
+ ## 🔧 Troubleshooting
358
+
359
+ ### Error: "jq command not found"
360
+
361
+ ```bash
362
+ # Ubuntu/Debian
363
+ sudo apt-get install jq
364
+
365
+ # macOS
366
+ brew install jq
367
+
368
+ # Windows (WSL)
369
+ sudo apt-get install jq
370
+ ```
371
+
372
+ ### Error: "Permission denied" en scripts
373
+
374
+ ```bash
375
+ chmod +x scripts/*.sh
376
+ ```
377
+
378
+ ### GitHub Actions no ejecuta
379
+
380
+ Verifica que `.github/workflows/security-audit.yml` esté commiteado:
381
+
382
+ ```bash
383
+ git add .github/workflows/security-audit.yml
384
+ git commit -m "chore: add security audit workflow"
385
+ git push
386
+ ```
387
+
388
+ ### Dependabot no abre PRs
389
+
390
+ Verifica en GitHub Settings > Security > Dependabot que esté habilitado.
391
+
392
+ ---
393
+
394
+ ## 📚 Recursos
395
+
396
+ ### Documentación Adicional
397
+
398
+ - **SECURITY_PROTOCOL.md** - Protocolo completo (en auth-service)
399
+ - **SECURITY_AUDIT_REPORT.md** - Ejemplo de informe
400
+ - **SECURITY_QUICK_GUIDE.md** - Guía rápida
401
+
402
+ ### Enlaces Útiles
403
+
404
+ - Socket.dev Blog: https://socket.dev/blog
405
+ - npm Security: https://docs.npmjs.com/security
406
+ - OWASP Dependency Check: https://owasp.org/www-community/Component_Analysis
407
+ - Snyk Advisor: https://snyk.io/advisor
408
+
409
+ ### Reportar Vulnerabilidades
410
+
411
+ - NPM Security: security@npmjs.com
412
+ - Socket.dev: https://socket.dev/report
413
+ - GitHub Security: https://github.com/security
414
+
415
+ ---
416
+
417
+ ## 🤝 Contribuir
418
+
419
+ ### Agregar Paquetes a la Blacklist
420
+
421
+ 1. Verificar en múltiples fuentes (Socket.dev, Snyk, GitHub)
422
+ 2. Editar `.security/malicious-packages-blacklist.json`
423
+ 3. Agregar evidencia y referencias
424
+ 4. Pull request con documentación
425
+
426
+ ### Mejorar Scripts
427
+
428
+ 1. Fork del repositorio
429
+ 2. Crear rama con feature
430
+ 3. Probar en múltiples proyectos
431
+ 4. PR con tests y documentación
432
+
433
+ ---
434
+
435
+ ## 📄 Licencia
436
+
437
+ MIT License - Úsalo libremente en proyectos comerciales y open source
438
+
439
+ ---
440
+
441
+ ## ⭐ Proyectos Usando Este Kit
442
+
443
+ - auth-service
444
+ - jwt-auth-package
445
+ - auth-react-client
446
+
447
+ ¿Usas este kit? Agrega tu proyecto aquí!
448
+
449
+ ---
450
+
451
+ ## 🎯 Roadmap
452
+
453
+ - [ ] npm package instalable (`npm install -D @tuorg/security-kit`)
454
+ - [ ] Integración con más CI/CD (GitLab, Bitbucket, CircleCI)
455
+ - [ ] Dashboard web de métricas
456
+ - [ ] Integración con Slack/Discord
457
+ - [ ] Soporte para Python/pip, Ruby/gems, etc.
458
+ - [ ] Machine learning para detectar patrones
459
+
460
+ ---
461
+
462
+ ## 📞 Soporte
463
+
464
+ - **Issues**: GitHub Issues
465
+ - **Discusiones**: GitHub Discussions
466
+ - **Email**: security@tuempresa.com
467
+ - **Slack**: #security channel
468
+
469
+ ---
470
+
471
+ **Versión**: 1.0.0
472
+ **Última actualización**: 2025-10-20
473
+ **Mantenedor**: Diego
474
+
475
+ ---
476
+
477
+ ## 🚀 Quick Start
478
+
479
+ ```bash
480
+ # 1. Clonar o descargar el kit
481
+ git clone https://github.com/tu-org/npm-security-kit
482
+
483
+ # 2. Ir a tu proyecto
484
+ cd mi-proyecto
485
+
486
+ # 3. Ejecutar instalación
487
+ bash /ruta/a/npm-security-kit/install.sh
488
+
489
+ # 4. Verificar
490
+ npm run security:check-malicious
491
+
492
+ # 5. ¡Listo! Tu proyecto está protegido
493
+ ```
494
+
495
+ **¿Preguntas?** Lee la documentación completa o abre un issue.
package/bin/check.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * NPM Security Kit - Quick Check Tool
5
+ * Runs malicious package check in current project
6
+ */
7
+
8
+ const { execSync } = require('child_process');
9
+ const path = require('path');
10
+ const fs = require('fs');
11
+
12
+ const targetDir = process.cwd();
13
+ const checkScript = path.join(targetDir, 'scripts', 'check-malicious-packages.sh');
14
+
15
+ // Check if scripts are installed
16
+ if (!fs.existsSync(checkScript)) {
17
+ console.error('Error: NPM Security Kit not installed in this project');
18
+ console.error('Run: npx @yourorg/npm-security-kit install');
19
+ process.exit(1);
20
+ }
21
+
22
+ try {
23
+ // Execute check script
24
+ execSync(`bash "${checkScript}"`, {
25
+ stdio: 'inherit',
26
+ cwd: targetDir
27
+ });
28
+ } catch (error) {
29
+ process.exit(error.status || 1);
30
+ }
package/bin/install.js ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * NPM Security Kit - CLI Installation Tool
5
+ * Installs security infrastructure in any Node.js project
6
+ */
7
+
8
+ const { execSync } = require('child_process');
9
+ const path = require('path');
10
+ const fs = require('fs');
11
+
12
+ const installScript = path.join(__dirname, 'install.sh');
13
+
14
+ // Check if install.sh exists
15
+ if (!fs.existsSync(installScript)) {
16
+ console.error('Error: install.sh not found');
17
+ process.exit(1);
18
+ }
19
+
20
+ // Get target directory from arguments or use current directory
21
+ const targetDir = process.argv[2] || process.cwd();
22
+
23
+ // Build command
24
+ const args = process.argv.slice(2).join(' ');
25
+ const command = `bash "${installScript}" ${args}`;
26
+
27
+ try {
28
+ // Execute install script
29
+ execSync(command, {
30
+ stdio: 'inherit',
31
+ cwd: targetDir
32
+ });
33
+ } catch (error) {
34
+ console.error('Installation failed:', error.message);
35
+ process.exit(1);
36
+ }