@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/EXAMPLES.md +528 -0
- package/LICENSE +21 -0
- package/QUICK_START.md +291 -0
- package/README.md +495 -0
- package/bin/check.js +30 -0
- package/bin/install.js +36 -0
- package/bin/install.sh +324 -0
- package/package.json +52 -0
- package/src/index.js +71 -0
- package/template/.github/dependabot.yml +63 -0
- package/template/.github/workflows/security-audit.yml +218 -0
- package/template/.security/config.json +94 -0
- package/template/.security/malicious-packages-blacklist.json +259 -0
- package/template/scripts/check-malicious-packages.sh +118 -0
- package/template/scripts/security-check.sh +166 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Security Check Script
|
|
4
|
+
# Ejecuta múltiples validaciones de seguridad en el proyecto
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
echo "========================================"
|
|
9
|
+
echo "Security Audit Script"
|
|
10
|
+
echo "========================================"
|
|
11
|
+
echo ""
|
|
12
|
+
|
|
13
|
+
# Colors for output
|
|
14
|
+
RED='\033[0;31m'
|
|
15
|
+
GREEN='\033[0;32m'
|
|
16
|
+
YELLOW='\033[1;33m'
|
|
17
|
+
NC='\033[0m' # No Color
|
|
18
|
+
|
|
19
|
+
ERRORS=0
|
|
20
|
+
WARNINGS=0
|
|
21
|
+
|
|
22
|
+
# Function to print colored output
|
|
23
|
+
print_success() {
|
|
24
|
+
echo -e "${GREEN}✓ $1${NC}"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
print_warning() {
|
|
28
|
+
echo -e "${YELLOW}⚠ $1${NC}"
|
|
29
|
+
((WARNINGS++))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
print_error() {
|
|
33
|
+
echo -e "${RED}✗ $1${NC}"
|
|
34
|
+
((ERRORS++))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# 1. Check for package-lock.json
|
|
38
|
+
echo "1. Checking package-lock.json..."
|
|
39
|
+
if [ -f "package-lock.json" ]; then
|
|
40
|
+
print_success "package-lock.json exists"
|
|
41
|
+
else
|
|
42
|
+
print_error "package-lock.json not found"
|
|
43
|
+
fi
|
|
44
|
+
echo ""
|
|
45
|
+
|
|
46
|
+
# 2. NPM Audit
|
|
47
|
+
echo "2. Running npm audit..."
|
|
48
|
+
if npm audit --audit-level=moderate > /dev/null 2>&1; then
|
|
49
|
+
print_success "No vulnerabilities found"
|
|
50
|
+
else
|
|
51
|
+
print_error "Vulnerabilities detected - run 'npm audit' for details"
|
|
52
|
+
npm audit --audit-level=moderate
|
|
53
|
+
fi
|
|
54
|
+
echo ""
|
|
55
|
+
|
|
56
|
+
# 3. Check for outdated packages
|
|
57
|
+
echo "3. Checking for outdated packages..."
|
|
58
|
+
OUTDATED=$(npm outdated --json 2>/dev/null || echo "{}")
|
|
59
|
+
if [ "$OUTDATED" = "{}" ]; then
|
|
60
|
+
print_success "All packages are up to date"
|
|
61
|
+
else
|
|
62
|
+
print_warning "Some packages are outdated"
|
|
63
|
+
npm outdated
|
|
64
|
+
fi
|
|
65
|
+
echo ""
|
|
66
|
+
|
|
67
|
+
# 4. Check for suspicious install scripts
|
|
68
|
+
echo "4. Checking for install scripts..."
|
|
69
|
+
INSTALL_SCRIPTS=$(grep -E '"(pre|post)?install"' package.json || true)
|
|
70
|
+
if [ -z "$INSTALL_SCRIPTS" ]; then
|
|
71
|
+
print_success "No install scripts found"
|
|
72
|
+
else
|
|
73
|
+
print_warning "Install scripts detected - review manually:"
|
|
74
|
+
echo "$INSTALL_SCRIPTS"
|
|
75
|
+
fi
|
|
76
|
+
echo ""
|
|
77
|
+
|
|
78
|
+
# 5. Check for hardcoded secrets
|
|
79
|
+
echo "5. Scanning for hardcoded secrets..."
|
|
80
|
+
SECRETS=$(grep -rE "(password|secret|api[_-]?key|token).*=.*['\"]" --include="*.ts" --include="*.js" src/ 2>/dev/null || true)
|
|
81
|
+
if [ -z "$SECRETS" ]; then
|
|
82
|
+
print_success "No hardcoded secrets detected"
|
|
83
|
+
else
|
|
84
|
+
print_error "Potential hardcoded secrets found:"
|
|
85
|
+
echo "$SECRETS"
|
|
86
|
+
fi
|
|
87
|
+
echo ""
|
|
88
|
+
|
|
89
|
+
# 6. Check for unprotected endpoints
|
|
90
|
+
echo "6. Checking for unprotected endpoints..."
|
|
91
|
+
UNPROTECTED=$(find src/handlers -name "*.ts" -not -path "*/__tests__/*" -exec grep -l "export.*handler" {} \; | xargs grep -L "withAuth\|validateToken\|withAdminApiKey\|withFlexibleAuth\|withClientApiKey" || true)
|
|
92
|
+
if [ -z "$UNPROTECTED" ]; then
|
|
93
|
+
print_success "All endpoints appear to be protected"
|
|
94
|
+
else
|
|
95
|
+
print_warning "Potentially unprotected endpoints found:"
|
|
96
|
+
echo "$UNPROTECTED"
|
|
97
|
+
fi
|
|
98
|
+
echo ""
|
|
99
|
+
|
|
100
|
+
# 7. Check for packages without licenses
|
|
101
|
+
echo "7. Checking package licenses..."
|
|
102
|
+
UNLICENSED=$(npm list --json | jq -r '.dependencies | to_entries[] | select(.value.license == null or .value.license == "") | .key' 2>/dev/null || true)
|
|
103
|
+
if [ -z "$UNLICENSED" ]; then
|
|
104
|
+
print_success "All packages have licenses"
|
|
105
|
+
else
|
|
106
|
+
print_warning "Packages without licenses found:"
|
|
107
|
+
echo "$UNLICENSED"
|
|
108
|
+
fi
|
|
109
|
+
echo ""
|
|
110
|
+
|
|
111
|
+
# 8. Check bundle size (if built)
|
|
112
|
+
echo "8. Checking bundle size..."
|
|
113
|
+
if [ -d "dist" ]; then
|
|
114
|
+
BUNDLE_SIZE=$(du -sh dist 2>/dev/null | cut -f1)
|
|
115
|
+
print_success "Bundle size: $BUNDLE_SIZE"
|
|
116
|
+
else
|
|
117
|
+
print_warning "dist folder not found - run 'npm run build' first"
|
|
118
|
+
fi
|
|
119
|
+
echo ""
|
|
120
|
+
|
|
121
|
+
# 9. Check for known malicious packages
|
|
122
|
+
echo "9. Checking for known malicious packages..."
|
|
123
|
+
if [ -f ".security/malicious-packages-blacklist.json" ]; then
|
|
124
|
+
MALICIOUS_CHECK=$(./scripts/check-malicious-packages.sh 2>&1)
|
|
125
|
+
if [ $? -eq 0 ]; then
|
|
126
|
+
print_success "No known malicious packages detected"
|
|
127
|
+
else
|
|
128
|
+
print_error "CRITICAL: Malicious packages detected!"
|
|
129
|
+
echo "$MALICIOUS_CHECK"
|
|
130
|
+
fi
|
|
131
|
+
else
|
|
132
|
+
print_warning "Malicious package blacklist not found"
|
|
133
|
+
fi
|
|
134
|
+
echo ""
|
|
135
|
+
|
|
136
|
+
# 10. Socket.dev check (if available)
|
|
137
|
+
echo "10. Checking Socket.dev..."
|
|
138
|
+
if command -v socket &> /dev/null; then
|
|
139
|
+
if socket npm audit > /dev/null 2>&1; then
|
|
140
|
+
print_success "Socket security check passed"
|
|
141
|
+
else
|
|
142
|
+
print_warning "Socket detected potential issues - review manually"
|
|
143
|
+
fi
|
|
144
|
+
else
|
|
145
|
+
print_warning "Socket CLI not installed - install with: npm install -g @socketsecurity/cli"
|
|
146
|
+
fi
|
|
147
|
+
echo ""
|
|
148
|
+
|
|
149
|
+
# Summary
|
|
150
|
+
echo "========================================"
|
|
151
|
+
echo "Summary"
|
|
152
|
+
echo "========================================"
|
|
153
|
+
echo -e "Errors: ${RED}$ERRORS${NC}"
|
|
154
|
+
echo -e "Warnings: ${YELLOW}$WARNINGS${NC}"
|
|
155
|
+
echo ""
|
|
156
|
+
|
|
157
|
+
if [ $ERRORS -gt 0 ]; then
|
|
158
|
+
echo -e "${RED}Security check FAILED${NC}"
|
|
159
|
+
exit 1
|
|
160
|
+
elif [ $WARNINGS -gt 0 ]; then
|
|
161
|
+
echo -e "${YELLOW}Security check PASSED with warnings${NC}"
|
|
162
|
+
exit 0
|
|
163
|
+
else
|
|
164
|
+
echo -e "${GREEN}Security check PASSED${NC}"
|
|
165
|
+
exit 0
|
|
166
|
+
fi
|