@theoptimalpartner/npm-security-kit 1.0.2 → 2.0.0-beta.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/QUICK_START.md DELETED
@@ -1,291 +0,0 @@
1
- # Quick Start Guide - NPM Security Kit
2
-
3
- ## 3 Minutos para Proteger tu Proyecto
4
-
5
- ---
6
-
7
- ## Para Proyectos Existentes
8
-
9
- ### Opción A: Instalación Automática (Más Fácil)
10
-
11
- ```bash
12
- # 1. Ir a tu proyecto
13
- cd /ruta/a/tu-proyecto
14
-
15
- # 2. Ejecutar instalación
16
- bash /home/diego/projects/npm-security-kit/install.sh
17
-
18
- # 3. Verificar
19
- npm run security:check-malicious
20
-
21
- # ¡Listo!
22
- ```
23
-
24
- ### Opción B: Instalación Manual
25
-
26
- ```bash
27
- # 1. Copiar archivos
28
- cp -r /home/diego/projects/npm-security-kit/template/.security tu-proyecto/
29
- cp -r /home/diego/projects/npm-security-kit/template/scripts tu-proyecto/
30
- cp -r /home/diego/projects/npm-security-kit/template/.github tu-proyecto/
31
-
32
- # 2. Hacer ejecutables
33
- cd tu-proyecto
34
- chmod +x scripts/*.sh
35
-
36
- # 3. Agregar a package.json (ver abajo)
37
- ```
38
-
39
- **Scripts para agregar a package.json**:
40
-
41
- ```json
42
- {
43
- "scripts": {
44
- "security:check": "./scripts/security-check.sh",
45
- "security:check-malicious": "./scripts/check-malicious-packages.sh",
46
- "security:audit": "npm audit --audit-level=moderate",
47
- "security:audit:fix": "npm audit fix",
48
- "security:outdated": "npm outdated",
49
- "security:licenses": "npm list --json | jq -r '.dependencies | to_entries[] | \"\\(.key): \\(.value.license)\"'",
50
- "security:full": "npm run security:audit && npm run security:check"
51
- }
52
- }
53
- ```
54
-
55
- ---
56
-
57
- ## Para Proyectos Nuevos
58
-
59
- ### Desde el Inicio
60
-
61
- ```bash
62
- # 1. Crear proyecto
63
- mkdir mi-nuevo-proyecto
64
- cd mi-nuevo-proyecto
65
- npm init -y
66
-
67
- # 2. Instalar security kit
68
- bash /home/diego/projects/npm-security-kit/install.sh
69
-
70
- # 3. Instalar dependencias
71
- npm install
72
-
73
- # 4. Verificar
74
- npm run security:check-malicious
75
-
76
- # Ahora tu proyecto nace protegido!
77
- ```
78
-
79
- ---
80
-
81
- ## Uso Diario
82
-
83
- ### Antes de Instalar un Paquete
84
-
85
- ```bash
86
- # Ver info del paquete
87
- npm info nombre-paquete
88
-
89
- # Instalar
90
- npm install nombre-paquete
91
-
92
- # Verificar inmediatamente
93
- npm run security:check-malicious
94
- ```
95
-
96
- ### Antes de Hacer Deploy
97
-
98
- ```bash
99
- npm run security:full
100
- ```
101
-
102
- ### Si Hay Problemas
103
-
104
- ```bash
105
- # Auto-fix
106
- npm run security:audit:fix
107
-
108
- # Verificar de nuevo
109
- npm run security:full
110
- ```
111
-
112
- ---
113
-
114
- ## Comandos Importantes
115
-
116
- | Comando | Cuándo Usarlo | Frecuencia |
117
- |---------|---------------|------------|
118
- | `npm run security:check-malicious` | Después de instalar paquetes | Cada instalación |
119
- | `npm run security:audit` | Verificar vulnerabilidades | Diario |
120
- | `npm run security:full` | Antes de deploy | Pre-deploy |
121
- | `npm run security:audit:fix` | Cuando hay vulnerabilidades | Según necesidad |
122
- | `npm run security:outdated` | Ver actualizaciones | Semanal |
123
-
124
- ---
125
-
126
- ## Configuración Rápida
127
-
128
- ### Editar `.security/config.json`
129
-
130
- ```json
131
- {
132
- "projectName": "mi-proyecto", // Nombre de tu proyecto
133
- "projectType": "react", // node, react, nextjs, etc.
134
- "strictMode": true // Bloquear en CI si hay amenazas
135
- }
136
- ```
137
-
138
- ### Tipos de Proyecto
139
-
140
- - `node` - Backend Node.js
141
- - `react` - React app
142
- - `nextjs` - Next.js
143
- - `vue` - Vue.js
144
- - `express` - Express API
145
- - `serverless` - Lambdas
146
- - `library` - npm package
147
-
148
- ---
149
-
150
- ## GitHub Actions (Automático)
151
-
152
- Una vez que hagas push, GitHub Actions ejecutará:
153
-
154
- - ✅ Verificación en cada PR
155
- - ✅ Verificación en cada push
156
- - ✅ Scan semanal automático (Lunes 9am)
157
-
158
- No necesitas hacer nada más!
159
-
160
- ---
161
-
162
- ## Dependabot (Automático)
163
-
164
- Dependabot abrirá PRs automáticos para:
165
-
166
- - ✅ Security patches
167
- - ✅ Actualizaciones de dependencias
168
- - ✅ Agrupadas por categoría
169
-
170
- Revisa y aprueba semanalmente.
171
-
172
- ---
173
-
174
- ## Verificar que Todo Funciona
175
-
176
- ```bash
177
- # 1. Verificar blacklist
178
- ls -la .security/malicious-packages-blacklist.json
179
-
180
- # 2. Verificar scripts
181
- ls -la scripts/*.sh
182
- ./scripts/check-malicious-packages.sh
183
-
184
- # 3. Verificar GitHub Actions
185
- ls -la .github/workflows/security-audit.yml
186
-
187
- # 4. Verificar scripts npm
188
- npm run security:check-malicious
189
-
190
- # Si todo sale ✓ estás listo!
191
- ```
192
-
193
- ---
194
-
195
- ## Problemas Comunes
196
-
197
- ### "jq: command not found"
198
-
199
- ```bash
200
- # Ubuntu/Debian
201
- sudo apt-get install jq
202
-
203
- # macOS
204
- brew install jq
205
- ```
206
-
207
- ### "Permission denied"
208
-
209
- ```bash
210
- chmod +x scripts/*.sh
211
- ```
212
-
213
- ### Scripts npm no funcionan
214
-
215
- Asegúrate de que package.json tenga los scripts. Verifica con:
216
-
217
- ```bash
218
- cat package.json | grep security
219
- ```
220
-
221
- ---
222
-
223
- ## Próximos Pasos
224
-
225
- 1. ✅ Instalar en proyecto actual
226
- 2. ✅ Ejecutar `npm run security:full`
227
- 3. ✅ Arreglar cualquier problema
228
- 4. ✅ Commit y push
229
- 5. ✅ Verificar GitHub Actions
230
- 6. ✅ Configurar Dependabot
231
- 7. ✅ Repetir en otros proyectos!
232
-
233
- ---
234
-
235
- ## ¿Necesitas Ayuda?
236
-
237
- - **Documentación completa**: `README.md`
238
- - **Configuración avanzada**: `.security/config.json`
239
- - **Issues**: GitHub Issues
240
- - **Email**: security@tuempresa.com
241
-
242
- ---
243
-
244
- ## Ejemplos Reales
245
-
246
- ### Proyecto Backend (Express)
247
-
248
- ```bash
249
- cd mi-api-express
250
- bash /home/diego/projects/npm-security-kit/install.sh
251
- npm run security:check-malicious
252
- # ✓ No malicious packages detected
253
- ```
254
-
255
- ### Proyecto Frontend (React)
256
-
257
- ```bash
258
- cd mi-app-react
259
- bash /home/diego/projects/npm-security-kit/install.sh
260
- npm run security:check-malicious
261
- # ✓ No malicious packages detected
262
- ```
263
-
264
- ### Librería npm
265
-
266
- ```bash
267
- cd mi-libreria
268
- bash /home/diego/projects/npm-security-kit/install.sh
269
- npm run security:check-malicious
270
- # ✓ No malicious packages detected
271
- ```
272
-
273
- ---
274
-
275
- ## Checklist de Instalación
276
-
277
- - [ ] Ejecutar `install.sh`
278
- - [ ] Verificar archivos creados (`.security`, `scripts`, `.github`)
279
- - [ ] Probar `npm run security:check-malicious`
280
- - [ ] Probar `npm run security:full`
281
- - [ ] Personalizar `.security/config.json`
282
- - [ ] Commit archivos a git
283
- - [ ] Push para activar GitHub Actions
284
- - [ ] Verificar que Dependabot esté activo
285
- - [ ] Documentar para el equipo
286
-
287
- ---
288
-
289
- **¡Tu proyecto está protegido!** 🛡️
290
-
291
- Repite este proceso en todos tus proyectos para mantener tu código seguro.
package/bin/check.js DELETED
@@ -1,30 +0,0 @@
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 DELETED
@@ -1,36 +0,0 @@
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
- }
package/bin/install.sh DELETED
@@ -1,318 +0,0 @@
1
- #!/bin/bash
2
-
3
- # NPM Security Kit - Installation Script
4
- # Installs security infrastructure in any Node.js project
5
-
6
- set -e
7
-
8
- # Colors
9
- RED='\033[0;31m'
10
- GREEN='\033[0;32m'
11
- YELLOW='\033[1;33m'
12
- BLUE='\033[0;34m'
13
- NC='\033[0m' # No Color
14
-
15
- # Configuration
16
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17
- TARGET_DIR="${1:-.}"
18
- UPDATE_MODE=false
19
-
20
- # Parse arguments
21
- for arg in "$@"; do
22
- case $arg in
23
- --update)
24
- UPDATE_MODE=true
25
- shift
26
- ;;
27
- --help)
28
- echo "Usage: $0 [target-directory] [--update]"
29
- echo ""
30
- echo "Options:"
31
- echo " target-directory Directory where to install (default: current directory)"
32
- echo " --update Update existing installation (preserves config)"
33
- echo " --help Show this help message"
34
- exit 0
35
- ;;
36
- esac
37
- done
38
-
39
- echo -e "${BLUE}========================================"
40
- echo "NPM Security Kit - Installation"
41
- echo -e "========================================${NC}"
42
- echo ""
43
-
44
- # Check if target directory exists
45
- if [ ! -d "$TARGET_DIR" ]; then
46
- echo -e "${RED}✗ Target directory does not exist: $TARGET_DIR${NC}"
47
- exit 1
48
- fi
49
-
50
- # Check if it's a Node.js project
51
- if [ ! -f "$TARGET_DIR/package.json" ]; then
52
- echo -e "${YELLOW}⚠ Warning: package.json not found in $TARGET_DIR${NC}"
53
- echo -e "${YELLOW} This might not be a Node.js project.${NC}"
54
- read -p "Continue anyway? (y/n) " -n 1 -r
55
- echo
56
- if [[ ! $REPLY =~ ^[Yy]$ ]]; then
57
- exit 1
58
- fi
59
- fi
60
-
61
- cd "$TARGET_DIR"
62
-
63
- echo -e "${GREEN}✓ Target directory: $(pwd)${NC}"
64
- echo ""
65
-
66
- # Check for required tools
67
- echo "Checking required tools..."
68
- MISSING_TOOLS=()
69
-
70
- if ! command -v jq &> /dev/null; then
71
- MISSING_TOOLS+=("jq")
72
- fi
73
-
74
- if ! command -v npm &> /dev/null; then
75
- MISSING_TOOLS+=("npm")
76
- fi
77
-
78
- if [ ${#MISSING_TOOLS[@]} -gt 0 ]; then
79
- echo -e "${RED}✗ Missing required tools: ${MISSING_TOOLS[*]}${NC}"
80
- echo ""
81
- echo "Install them with:"
82
- for tool in "${MISSING_TOOLS[@]}"; do
83
- case $tool in
84
- jq)
85
- echo " - Ubuntu/Debian: sudo apt-get install jq"
86
- echo " - macOS: brew install jq"
87
- ;;
88
- npm)
89
- echo " - Visit: https://nodejs.org/"
90
- ;;
91
- esac
92
- done
93
- exit 1
94
- fi
95
-
96
- echo -e "${GREEN}✓ All required tools available${NC}"
97
- echo ""
98
-
99
- # Create directories
100
- echo "Creating directory structure..."
101
- mkdir -p .security
102
- mkdir -p scripts
103
- mkdir -p .github/workflows
104
-
105
- echo -e "${GREEN}✓ Directories created${NC}"
106
- echo ""
107
-
108
- # Copy security files
109
- echo "Installing security files..."
110
-
111
- # Template directory
112
- TEMPLATE_DIR="$SCRIPT_DIR/../template"
113
-
114
- # 1. Blacklist
115
- if [ -f "$TEMPLATE_DIR/.security/malicious-packages-blacklist.json" ]; then
116
- cp "$TEMPLATE_DIR/.security/malicious-packages-blacklist.json" .security/
117
- echo -e "${GREEN} ✓ Blacklist installed${NC}"
118
- else
119
- echo -e "${RED} ✗ Error: Blacklist template not found${NC}"
120
- echo -e "${YELLOW} Expected: $TEMPLATE_DIR/.security/malicious-packages-blacklist.json${NC}"
121
- exit 1
122
- fi
123
-
124
- # 2. Config
125
- if [ "$UPDATE_MODE" = false ] || [ ! -f ".security/config.json" ]; then
126
- cat > .security/config.json <<'EOF'
127
- {
128
- "projectName": "my-project",
129
- "projectType": "node",
130
- "excludeDirs": ["node_modules", "dist", "build", ".next"],
131
- "strictMode": true,
132
- "notifications": {
133
- "enabled": false,
134
- "email": "",
135
- "slack": ""
136
- },
137
- "autofix": {
138
- "enabled": false,
139
- "level": "moderate"
140
- }
141
- }
142
- EOF
143
- echo -e "${GREEN} ✓ Config created${NC}"
144
- else
145
- echo -e "${BLUE} → Config preserved (update mode)${NC}"
146
- fi
147
-
148
- # 3. Scripts
149
- if [ -f "$TEMPLATE_DIR/scripts/check-malicious-packages.sh" ]; then
150
- cp "$TEMPLATE_DIR/scripts/check-malicious-packages.sh" scripts/
151
- chmod +x scripts/check-malicious-packages.sh
152
- else
153
- echo -e "${RED} ✗ Error: check-malicious-packages.sh not found${NC}"
154
- exit 1
155
- fi
156
-
157
- if [ -f "$TEMPLATE_DIR/scripts/security-check.sh" ]; then
158
- cp "$TEMPLATE_DIR/scripts/security-check.sh" scripts/
159
- chmod +x scripts/security-check.sh
160
- else
161
- echo -e "${RED} ✗ Error: security-check.sh not found${NC}"
162
- exit 1
163
- fi
164
-
165
- echo -e "${GREEN} ✓ Scripts installed${NC}"
166
-
167
- # 4. GitHub Actions
168
- if [ -f "$TEMPLATE_DIR/.github/workflows/security-audit.yml" ]; then
169
- cp "$TEMPLATE_DIR/.github/workflows/security-audit.yml" .github/workflows/
170
- else
171
- echo -e "${RED} ✗ Error: security-audit.yml not found${NC}"
172
- exit 1
173
- fi
174
-
175
- echo -e "${GREEN} ✓ GitHub Actions workflow installed${NC}"
176
-
177
- # 5. Dependabot
178
- if [ -f "$TEMPLATE_DIR/.github/dependabot.yml" ]; then
179
- cp "$TEMPLATE_DIR/.github/dependabot.yml" .github/
180
- else
181
- echo -e "${RED} ✗ Error: dependabot.yml not found${NC}"
182
- exit 1
183
- fi
184
-
185
- echo -e "${GREEN} ✓ Dependabot config installed${NC}"
186
-
187
- # 6. SECURITY.md
188
- if [ "$UPDATE_MODE" = false ] || [ ! -f "SECURITY.md" ]; then
189
- cat > SECURITY.md <<'EOF'
190
- # Security Documentation
191
-
192
- ## Quick Reference
193
-
194
- ### Security Commands
195
-
196
- ```bash
197
- # Check for malicious packages
198
- npm run security:check-malicious
199
-
200
- # Full security audit
201
- npm run security:full
202
-
203
- # npm audit only
204
- npm run security:audit
205
-
206
- # Auto-fix vulnerabilities
207
- npm run security:audit:fix
208
-
209
- # Check outdated packages
210
- npm run security:outdated
211
-
212
- # Verify licenses
213
- npm run security:licenses
214
- ```
215
-
216
- ## Current Security Status
217
-
218
- **Last Audit**: Run `npm run security:full` to check
219
-
220
- ## Automated Protection
221
-
222
- - ✅ Blacklist of 175+ known malicious packages
223
- - ✅ GitHub Actions (weekly scans)
224
- - ✅ Dependabot (automatic updates)
225
- - ✅ Pre-deployment checks
226
-
227
- ## Reporting Security Issues
228
-
229
- If you discover a security vulnerability, please report it to the security team.
230
-
231
- ## Resources
232
-
233
- - NPM Security Kit: https://github.com/tu-org/npm-security-kit
234
- - Socket.dev: https://socket.dev
235
- - npm Security: https://docs.npmjs.com/security
236
- EOF
237
- echo -e "${GREEN} ✓ SECURITY.md created${NC}"
238
- else
239
- echo -e "${BLUE} → SECURITY.md preserved (update mode)${NC}"
240
- fi
241
-
242
- echo ""
243
-
244
- # Add npm scripts
245
- echo "Adding npm scripts to package.json..."
246
-
247
- if [ -f "package.json" ]; then
248
- # Check if scripts already exist
249
- if grep -q '"security:check-malicious"' package.json; then
250
- echo -e "${BLUE} → Scripts already exist, skipping${NC}"
251
- else
252
- # Backup package.json
253
- cp package.json package.json.backup
254
-
255
- # Add scripts using jq
256
- jq '.scripts += {
257
- "security:check": "./scripts/security-check.sh",
258
- "security:check-malicious": "./scripts/check-malicious-packages.sh",
259
- "security:audit": "npm audit --audit-level=moderate",
260
- "security:audit:fix": "npm audit fix",
261
- "security:outdated": "npm outdated",
262
- "security:licenses": "npm list --json | jq -r '\''.dependencies | to_entries[] | \"\\(.key): \\(.value.license)\"'\''",
263
- "security:full": "npm run security:audit && npm run security:check"
264
- }' package.json > package.json.tmp
265
-
266
- mv package.json.tmp package.json
267
- echo -e "${GREEN} ✓ Scripts added to package.json${NC}"
268
- echo -e "${BLUE} → Backup saved as package.json.backup${NC}"
269
- fi
270
- else
271
- echo -e "${YELLOW} ⚠ package.json not found, skipping script installation${NC}"
272
- fi
273
-
274
- echo ""
275
-
276
- # Run initial check
277
- echo "Running initial security check..."
278
- if npm run security:check-malicious > /dev/null 2>&1; then
279
- echo -e "${GREEN}✓ Initial check passed - No malicious packages detected${NC}"
280
- else
281
- echo -e "${YELLOW}⚠ Check completed with warnings${NC}"
282
- fi
283
-
284
- echo ""
285
- echo -e "${BLUE}========================================"
286
- echo "Installation Complete!"
287
- echo -e "========================================${NC}"
288
- echo ""
289
- echo "Files installed:"
290
- echo " ✓ .security/malicious-packages-blacklist.json"
291
- echo " ✓ .security/config.json"
292
- echo " ✓ scripts/check-malicious-packages.sh"
293
- echo " ✓ scripts/security-check.sh"
294
- echo " ✓ .github/workflows/security-audit.yml"
295
- echo " ✓ .github/dependabot.yml"
296
- echo " ✓ SECURITY.md"
297
- echo " ✓ package.json (scripts added)"
298
- echo ""
299
- echo "Next steps:"
300
- echo ""
301
- echo " 1. Verify installation:"
302
- echo " npm run security:check-malicious"
303
- echo ""
304
- echo " 2. Run full audit:"
305
- echo " npm run security:full"
306
- echo ""
307
- echo " 3. Customize config:"
308
- echo " Edit .security/config.json"
309
- echo ""
310
- echo " 4. Commit files:"
311
- echo " git add .security scripts .github SECURITY.md package.json"
312
- echo " git commit -m \"security: add npm security kit\""
313
- echo ""
314
- echo " 5. Push to enable GitHub Actions:"
315
- echo " git push"
316
- echo ""
317
- echo -e "${GREEN}Your project is now protected!${NC} 🛡️"
318
- echo ""