forked from augustina-jpg/scoopdope
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependency-vulnerability-scanning.yml
More file actions
303 lines (248 loc) · 9.17 KB
/
Copy pathdependency-vulnerability-scanning.yml
File metadata and controls
303 lines (248 loc) · 9.17 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
name: Dependency Vulnerability Scanning
on:
push:
branches: [main, develop]
paths:
- 'package.json'
- 'package-lock.json'
- 'apps/*/package.json'
- 'apps/*/package-lock.json'
- 'Cargo.toml'
- 'Cargo.lock'
- 'contracts/*/Cargo.toml'
pull_request:
branches: [main, develop]
schedule:
- cron: '0 3 * * *' # Daily at 3 AM UTC
jobs:
npm-audit:
name: NPM Audit - Frontend & Backend
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Run npm audit
id: npm-audit
run: |
echo "🔍 Running npm audit..."
# Run audit and capture output
npm audit --audit-level=moderate > npm-audit-report.txt 2>&1 || true
# Check for high/critical vulnerabilities
if npm audit --audit-level=high > /dev/null 2>&1; then
echo "audit_status=pass" >> $GITHUB_OUTPUT
echo "✅ No high/critical vulnerabilities found"
else
echo "audit_status=fail" >> $GITHUB_OUTPUT
echo "❌ High/critical vulnerabilities detected"
cat npm-audit-report.txt
exit 1
fi
- name: Generate npm audit JSON report
run: npm audit --json > npm-audit-report.json 2>&1 || true
- name: Upload npm audit report
uses: actions/upload-artifact@v4
with:
name: npm-audit-report
path: npm-audit-report.*
retention-days: 30
cargo-audit:
name: Cargo Deny - Rust Contracts
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Install cargo-deny
run: cargo install cargo-deny --locked
- name: Run cargo deny (advisories + licenses + bans)
id: cargo-audit
run: |
echo "🔍 Running cargo deny check..."
cargo deny check 2>&1 | tee cargo-deny-report.txt
if [ ${PIPESTATUS[0]} -ne 0 ]; then
echo "audit_status=fail" >> $GITHUB_OUTPUT
echo "❌ cargo deny found issues"
exit 1
else
echo "audit_status=pass" >> $GITHUB_OUTPUT
echo "✅ No issues found in Rust dependencies"
fi
- name: Upload cargo deny report
if: always()
uses: actions/upload-artifact@v4
with:
name: cargo-deny-report
path: cargo-deny-report.txt
retention-days: 30
snyk-scan:
name: Snyk Security Scan
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'schedule'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Snyk scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high --json-file-output=snyk-report.json
continue-on-error: true
- name: Upload Snyk report
uses: actions/upload-artifact@v4
with:
name: snyk-report
path: snyk-report.json
retention-days: 30
continue-on-error: true
dependabot-check:
name: Dependabot Status Check
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Check Dependabot PR
run: |
if [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
echo "✅ Dependabot PR detected"
echo "This PR updates dependencies automatically"
fi
create-security-report:
name: Create Security Report
runs-on: ubuntu-latest
needs: [npm-audit, cargo-audit]
if: always()
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download all reports
uses: actions/download-artifact@v4
with:
path: security-reports/
- name: Generate consolidated report
run: |
mkdir -p final-reports
cat > final-reports/security-summary.md << 'EOF'
# Security Vulnerability Report
Generated: $(date)
## Summary
| Tool | Status | Details |
|------|--------|---------|
| npm audit | ${{ needs.npm-audit.result }} | Frontend & Backend dependencies |
| cargo audit | ${{ needs.cargo-audit.result }} | Rust smart contracts |
| Snyk | Pending | Third-party vulnerability database |
## Recommendations
1. **High Priority**: Address all high and critical vulnerabilities immediately
2. **Medium Priority**: Plan updates for moderate vulnerabilities in next sprint
3. **Low Priority**: Monitor low-severity issues and update when convenient
## Next Steps
- Review detailed reports in artifacts
- Create issues for vulnerabilities that require code changes
- Update dependencies using `npm update` or `cargo update`
- Re-run scans after updates to verify fixes
EOF
cat final-reports/security-summary.md
- name: Upload final report
uses: actions/upload-artifact@v4
with:
name: security-report
path: final-reports/
retention-days: 90
fail-on-critical:
name: Fail Build on Critical Vulnerabilities
runs-on: ubuntu-latest
needs: [npm-audit, cargo-audit]
if: always()
steps:
- name: Check for critical vulnerabilities
run: |
if [ "${{ needs.npm-audit.result }}" = "failure" ] || [ "${{ needs.cargo-audit.result }}" = "failure" ]; then
echo "❌ Critical or high-severity vulnerabilities detected"
echo "Build failed due to security vulnerabilities"
exit 1
else
echo "✅ No critical vulnerabilities detected"
fi
auto-update-dependencies:
name: Auto-Update Dependencies (Scheduled)
runs-on: ubuntu-latest
if: github.event_name == 'schedule'
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Update npm dependencies
run: |
echo "📦 Updating npm dependencies..."
npm update --save
npm audit fix --audit-level=moderate || true
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Update Cargo dependencies
run: |
echo "📦 Updating Cargo dependencies..."
cargo update
- name: Create pull request
uses: peter-evans/create-pull-request@v5
with:
commit-message: 'chore(deps): automated dependency updates'
title: 'chore(deps): automated dependency updates'
body: |
## Automated Dependency Updates
This PR contains automated updates to dependencies.
### Changes
- Updated npm packages (frontend & backend)
- Updated Cargo packages (Rust contracts)
### Testing
- [ ] Run full test suite
- [ ] Verify no breaking changes
- [ ] Check performance impact
Please review and merge if all checks pass.
branch: 'chore/auto-update-dependencies'
delete-branch: true
labels: 'dependencies, automated'
continue-on-error: true
notify-vulnerabilities:
name: Notify on Vulnerabilities
runs-on: ubuntu-latest
needs: [npm-audit, cargo-audit]
if: failure()
steps:
- name: Create security issue
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🔒 Security: Vulnerabilities Detected in Dependencies',
body: `Dependency vulnerability scan detected security issues.\n\n- npm audit: ${{ needs.npm-audit.result }}\n- cargo audit: ${{ needs.cargo-audit.result }}\n\nRun: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}\n\nPlease review and address vulnerabilities immediately.`,
labels: ['security', 'dependencies', 'urgent']
});
- name: Comment on related PRs
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '⚠️ **Security Alert**: Dependency vulnerabilities detected. Please review the security scan results before merging.'
});