-
Notifications
You must be signed in to change notification settings - Fork 0
245 lines (196 loc) · 7.04 KB
/
Copy pathsecurity.yml
File metadata and controls
245 lines (196 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: 🔒 Security Audit
on:
schedule:
# Run security audit daily at 2 AM UTC
- cron: '0 2 * * *'
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
workflow_dispatch:
permissions:
contents: read
security-events: write
actions: read
jobs:
dependency-audit:
name: 🔍 Dependency Security Audit
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout Repository
uses: actions/checkout@v4
- name: 🟢 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: 📦 Install Dependencies
run: npm ci
- name: 🔒 NPM Security Audit
run: |
echo "🔒 Running comprehensive security audit..."
# Run audit and capture output
npm audit --audit-level=low --json > audit-report.json || true
# Display human-readable results
echo "📊 Security Audit Results:"
npm audit --audit-level=low || true
# Check for high/critical vulnerabilities
HIGH_VULNS=$(cat audit-report.json | jq -r '.metadata.vulnerabilities.high // 0')
CRITICAL_VULNS=$(cat audit-report.json | jq -r '.metadata.vulnerabilities.critical // 0')
echo "🔢 High vulnerabilities: $HIGH_VULNS"
echo "🔢 Critical vulnerabilities: $CRITICAL_VULNS"
if [ "$HIGH_VULNS" -gt 0 ] || [ "$CRITICAL_VULNS" -gt 0 ]; then
echo "❌ High or critical vulnerabilities found!"
exit 1
else
echo "✅ No high or critical vulnerabilities found"
fi
- name: 📋 Upload Audit Report
uses: actions/upload-artifact@v4
if: always()
with:
name: security-audit-report
path: audit-report.json
retention-days: 30
license-check:
name: 📜 License Compliance Check
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout Repository
uses: actions/checkout@v4
- name: 🟢 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: 📦 Install Dependencies
run: npm ci
- name: 📜 Check Licenses
run: |
echo "📜 Checking dependency licenses..."
# Install license checker
npm install -g license-checker
# Check licenses and generate report
license-checker --json --out licenses.json
echo "📊 License summary:"
license-checker --summary
# Check for problematic licenses
PROBLEMATIC_LICENSES="GPL-2.0,GPL-3.0,AGPL-1.0,AGPL-3.0,LGPL-2.0,LGPL-2.1,LGPL-3.0"
if license-checker --failOn "$PROBLEMATIC_LICENSES" --quiet; then
echo "✅ No problematic licenses found"
else
echo "⚠️ Potentially problematic licenses detected"
echo "Please review the license report"
fi
- name: 📋 Upload License Report
uses: actions/upload-artifact@v4
with:
name: license-report
path: licenses.json
retention-days: 30
code-scanning:
name: 🔎 Code Security Analysis
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout Repository
uses: actions/checkout@v4
- name: 🔍 Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript
- name: 📦 Install Dependencies
run: npm ci
- name: 🔍 Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:javascript"
secrets-scan:
name: 🕵️ Secrets Detection
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🕵️ Run TruffleHog
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: master
head: HEAD
extra_args: --debug --only-verified
malware-scan:
name: 🦠 Malware Detection
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout Repository
uses: actions/checkout@v4
- name: 🦠 Scan for Malware
run: |
echo "🦠 Scanning for potential malware patterns..."
# Check for suspicious patterns
echo "🔍 Checking for suspicious file patterns..."
# Look for potentially dangerous functions
if grep -r "eval\|Function\|setTimeout.*string\|setInterval.*string" . --exclude-dir=node_modules --exclude-dir=.git; then
echo "⚠️ Found potentially dangerous function usage"
echo "Please review the above findings"
else
echo "✅ No dangerous function patterns found"
fi
# Check for base64 encoded content that might be suspicious
if grep -r "base64\|btoa\|atob" . --exclude-dir=node_modules --exclude-dir=.git; then
echo "⚠️ Found base64 encoding usage"
echo "Please verify this is legitimate"
else
echo "✅ No suspicious encoding found"
fi
security-report:
name: 📊 Security Summary
runs-on: ubuntu-latest
needs: [dependency-audit, license-check, code-scanning, secrets-scan, malware-scan]
if: always()
steps:
- name: 📊 Generate Security Report
run: |
echo "# 🔒 Security Audit Summary" > security-summary.md
echo "" >> security-summary.md
echo "## 📅 Audit Date: $(date)" >> security-summary.md
echo "" >> security-summary.md
echo "## 🎯 Audit Results" >> security-summary.md
echo "" >> security-summary.md
# Check job results
if [ "${{ needs.dependency-audit.result }}" == "success" ]; then
echo "✅ **Dependency Audit**: PASSED" >> security-summary.md
else
echo "❌ **Dependency Audit**: FAILED" >> security-summary.md
fi
if [ "${{ needs.license-check.result }}" == "success" ]; then
echo "✅ **License Check**: PASSED" >> security-summary.md
else
echo "⚠️ **License Check**: REVIEW NEEDED" >> security-summary.md
fi
if [ "${{ needs.code-scanning.result }}" == "success" ]; then
echo "✅ **Code Scanning**: PASSED" >> security-summary.md
else
echo "❌ **Code Scanning**: ISSUES FOUND" >> security-summary.md
fi
if [ "${{ needs.secrets-scan.result }}" == "success" ]; then
echo "✅ **Secrets Scan**: CLEAN" >> security-summary.md
else
echo "❌ **Secrets Scan**: SECRETS DETECTED" >> security-summary.md
fi
if [ "${{ needs.malware-scan.result }}" == "success" ]; then
echo "✅ **Malware Scan**: CLEAN" >> security-summary.md
else
echo "⚠️ **Malware Scan**: REVIEW NEEDED" >> security-summary.md
fi
echo "" >> security-summary.md
echo "---" >> security-summary.md
echo "*Generated by GitHub Actions Security Audit*" >> security-summary.md
cat security-summary.md
- name: 📋 Upload Security Summary
uses: actions/upload-artifact@v4
with:
name: security-summary
path: security-summary.md
retention-days: 90