@theoptimalpartner/npm-security-kit 1.0.2 → 2.0.0-beta.1

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.
@@ -1,118 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Check for Malicious Packages Script
4
- # Verifica si hay paquetes maliciosos instalados contra la blacklist conocida
5
-
6
- set -e
7
-
8
- # Colors
9
- RED='\033[0;31m'
10
- GREEN='\033[0;32m'
11
- YELLOW='\033[1;33m'
12
- NC='\033[0m' # No Color
13
-
14
- BLACKLIST_FILE=".security/malicious-packages-blacklist.json"
15
-
16
- echo "========================================"
17
- echo "Malicious Package Detection"
18
- echo "========================================"
19
- echo ""
20
-
21
- # Check if blacklist file exists
22
- if [ ! -f "$BLACKLIST_FILE" ]; then
23
- echo -e "${RED}✗ Blacklist file not found: $BLACKLIST_FILE${NC}"
24
- exit 1
25
- fi
26
-
27
- echo "Loading blacklist..."
28
- BLACKLIST_COUNT=$(jq -r '.blacklistedPackages | length' "$BLACKLIST_FILE")
29
- LAST_UPDATED=$(jq -r '.lastUpdated' "$BLACKLIST_FILE")
30
- SOURCE=$(jq -r '.source' "$BLACKLIST_FILE")
31
-
32
- echo -e "${GREEN}✓ Loaded $BLACKLIST_COUNT malicious packages${NC}"
33
- echo " Source: $SOURCE"
34
- echo " Last Updated: $LAST_UPDATED"
35
- echo ""
36
-
37
- # Get installed packages
38
- echo "Analyzing installed packages..."
39
- INSTALLED_PACKAGES=$(npm list --json 2>/dev/null | jq -r '.. | .dependencies? // {} | keys[]' 2>/dev/null || echo "")
40
-
41
- if [ -z "$INSTALLED_PACKAGES" ]; then
42
- echo -e "${YELLOW}⚠ Could not retrieve installed packages${NC}"
43
- exit 1
44
- fi
45
-
46
- TOTAL_INSTALLED=$(echo "$INSTALLED_PACKAGES" | wc -l)
47
- echo " Total installed packages: $TOTAL_INSTALLED"
48
- echo ""
49
-
50
- # Check against blacklist
51
- echo "Checking against blacklist..."
52
- FOUND_MALICIOUS=0
53
- MALICIOUS_FOUND=""
54
-
55
- while IFS= read -r package; do
56
- if jq -e ".blacklistedPackages | index(\"$package\")" "$BLACKLIST_FILE" > /dev/null 2>&1; then
57
- echo -e "${RED}✗ MALICIOUS PACKAGE DETECTED: $package${NC}"
58
- FOUND_MALICIOUS=$((FOUND_MALICIOUS + 1))
59
- MALICIOUS_FOUND="$MALICIOUS_FOUND\n - $package"
60
- fi
61
- done <<< "$INSTALLED_PACKAGES"
62
-
63
- # Check against patterns
64
- echo ""
65
- echo "Checking against malicious patterns..."
66
- PATTERN_MATCHES=0
67
-
68
- PATTERNS=$(jq -r '.patterns[].pattern' "$BLACKLIST_FILE")
69
- while IFS= read -r pattern; do
70
- while IFS= read -r package; do
71
- if echo "$package" | grep -qE "$pattern"; then
72
- PATTERN_DESC=$(jq -r ".patterns[] | select(.pattern == \"$pattern\") | .description" "$BLACKLIST_FILE")
73
- echo -e "${RED}✗ PATTERN MATCH: $package${NC}"
74
- echo " Pattern: $pattern"
75
- echo " Description: $PATTERN_DESC"
76
- PATTERN_MATCHES=$((PATTERN_MATCHES + 1))
77
- MALICIOUS_FOUND="$MALICIOUS_FOUND\n - $package (pattern match)"
78
- fi
79
- done <<< "$INSTALLED_PACKAGES"
80
- done <<< "$PATTERNS"
81
-
82
- echo ""
83
- echo "========================================"
84
- echo "Results"
85
- echo "========================================"
86
-
87
- if [ $FOUND_MALICIOUS -eq 0 ] && [ $PATTERN_MATCHES -eq 0 ]; then
88
- echo -e "${GREEN}✓ No malicious packages detected${NC}"
89
- echo ""
90
- echo "Summary:"
91
- echo " - Checked: $TOTAL_INSTALLED packages"
92
- echo " - Against: $BLACKLIST_COUNT known malicious packages"
93
- echo " - Found: 0 threats"
94
- exit 0
95
- else
96
- echo -e "${RED}✗ MALICIOUS PACKAGES FOUND!${NC}"
97
- echo ""
98
- echo "Summary:"
99
- echo " - Direct matches: $FOUND_MALICIOUS"
100
- echo " - Pattern matches: $PATTERN_MATCHES"
101
- echo " - Total threats: $((FOUND_MALICIOUS + PATTERN_MATCHES))"
102
- echo ""
103
- echo "Malicious packages found:"
104
- echo -e "$MALICIOUS_FOUND"
105
- echo ""
106
- echo "IMMEDIATE ACTIONS REQUIRED:"
107
- echo "1. DO NOT use this application"
108
- echo "2. Uninstall malicious packages immediately"
109
- echo "3. Review application logs for suspicious activity"
110
- echo "4. Check for data exfiltration"
111
- echo "5. Report to security team"
112
- echo "6. Review package-lock.json for when it was added"
113
- echo ""
114
- echo "To remove:"
115
- echo " npm uninstall <package-name>"
116
- echo ""
117
- exit 1
118
- fi
@@ -1,166 +0,0 @@
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