-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (76 loc) · 2.73 KB
/
Copy pathsecurity-scan.yml
File metadata and controls
90 lines (76 loc) · 2.73 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
name: Security Scan
on:
push:
branches: [ master, main, develop ]
pull_request:
branches: [ '**' ]
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
permissions:
contents: read
security-events: write
jobs:
security-scan:
name: Security Scanning
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0 # Full history for secrets scanning
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10.12.1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
# Secrets Scanning
- name: Run Gitleaks (Secret Detection)
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
# Dependency Security Audit
- name: Run npm audit
run: |
echo "Running npm audit..."
pnpm audit --production --audit-level=moderate || true
echo "Audit completed"
continue-on-error: true
# Check for known vulnerabilities
# Note: Snyk scan is optional - add SNYK_TOKEN to repository secrets to enable
- name: Run Snyk Security Scan
if: ${{ github.event_name != 'pull_request' && secrets.SNYK_TOKEN != '' }}
uses: snyk/actions/node@master
continue-on-error: true
with:
args: --severity-threshold=high
snyk-token: ${{ secrets.SNYK_TOKEN }}
# Dependency Review (for PRs)
- name: Dependency Review
uses: actions/dependency-review-action@v4
if: github.event_name == 'pull_request'
continue-on-error: true
# Check for hardcoded secrets in code
- name: Check for hardcoded secrets
run: |
echo "Checking for potential hardcoded secrets..."
# Check for common secret patterns
if grep -rE "(password|secret|token|api[_-]?key|apikey)\s*=\s*['\"][^'\"]+['\"]" --include="*.ts" --include="*.js" --exclude-dir=node_modules --exclude-dir=dist .; then
echo "⚠️ Warning: Potential hardcoded secrets found"
exit 1
fi
continue-on-error: true
# Security Summary
- name: Security Summary
run: |
echo "## Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Secrets scanning completed" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Dependency audit completed" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Code security checks completed" >> $GITHUB_STEP_SUMMARY