-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (176 loc) · 6.69 KB
/
Copy pathsecurity-scan.yml
File metadata and controls
208 lines (176 loc) · 6.69 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
name: Security Scanning
on:
schedule:
# Run weekly on Monday at 9 AM UTC
- cron: '0 9 * * 1'
push:
branches: [main]
paths:
- 'website/**'
- 'package.json'
- 'package-lock.json'
pull_request:
branches: [main]
paths:
- 'website/**'
workflow_dispatch: # Allow manual triggering
env:
NODE_VERSION: '20'
jobs:
# Security vulnerability scanning
security-scan:
name: Security Vulnerability Scan
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./website
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: 'website/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Run npm audit
run: npm audit --audit-level=high
continue-on-error: true # Don't fail the workflow, just report
- name: Run Snyk security scan
uses: snyk/actions/node@master
with:
args: --severity-threshold=high
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
continue-on-error: true
- name: Check for leaked secrets
uses: gitleaks/gitleaks-action@v2
with:
config-path: .gitleaks.toml
continue-on-error: true
- name: Dependency review
uses: actions/dependency-review-action@v4
if: github.event_name == 'pull_request'
- name: Generate security report
run: |
echo "# Security Scan Report - $(date)" > security-report.md
echo "## Summary" >> security-report.md
echo "- Repository: ${{ github.repository }}" >> security-report.md
echo "- Branch: ${{ github.ref }}" >> security-report.md
echo "- Commit: ${{ github.sha }}" >> security-report.md
echo "- Scan Date: $(date)" >> security-report.md
echo "" >> security-report.md
echo "## Findings" >> security-report.md
echo "Security scans completed. Check logs for details." >> security-report.md
# Upload security report as artifact
mkdir -p reports
mv security-report.md reports/
- name: Upload security artifacts
uses: actions/upload-artifact@v4
with:
name: security-reports
path: |
website/reports/
retention-days: 30
- name: Notify on critical vulnerabilities
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🚨 Critical Security Vulnerabilities Detected',
body: `Critical security vulnerabilities were detected in the latest security scan.
**Repository:** ${context.repo.owner}/${context.repo.repo}
**Branch:** ${context.ref}
**Commit:** ${context.sha}
Please review the security scan results and address the vulnerabilities immediately.
Scan triggered by: ${context.actor}
Timestamp: ${new Date().toISOString()}`,
labels: ['security', 'critical']
})
# Code quality and security linting
code-quality:
name: Code Quality & Security Linting
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./website
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: 'website/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Run ESLint with security rules
run: npm run lint
continue-on-error: true
- name: Check for security anti-patterns
run: |
# Check for common security issues
echo "Checking for security anti-patterns..."
# Check for hardcoded secrets
if grep -r "password\|secret\|token\|key" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" --include="*.astro" src/ | grep -v "process.env" | grep -v "//" | grep -v "test"; then
echo "⚠️ Warning: Potential hardcoded secrets found"
grep -r "password\|secret\|token\|key" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" --include="*.astro" src/ | grep -v "process.env" | grep -v "//" | grep -v "test"
else
echo "✅ No hardcoded secrets found"
fi
# Check for eval() usage
if grep -r "eval(" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" --include="*.astro" src/; then
echo "❌ Critical: eval() usage detected - this is a security risk!"
grep -r "eval(" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" --include="*.astro" src/
exit 1
else
echo "✅ No eval() usage found"
fi
continue-on-error: true
- name: Generate code quality report
run: |
echo "# Code Quality Report - $(date)" > code-quality-report.md
echo "## Summary" >> code-quality-report.md
echo "- Repository: ${{ github.repository }}" >> code-quality-report.md
echo "- Branch: ${{ github.ref }}" >> code-quality-report.md
echo "- Commit: ${{ github.sha }}" >> code-quality-report.md
echo "- Scan Date: $(date)" >> code-quality-report.md
echo "" >> code-quality-report.md
echo "## Linting Results" >> code-quality-report.md
echo "ESLint checks completed. See logs for details." >> code-quality-report.md
mkdir -p reports
mv code-quality-report.md reports/
- name: Upload code quality artifacts
uses: actions/upload-artifact@v4
with:
name: code-quality-reports
path: |
website/reports/
retention-days: 30
# Container security scanning (if using Docker)
container-scan:
name: Container Security Scan
runs-on: ubuntu-latest
if: false # Disabled by default, enable if using Docker containers
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'