-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (154 loc) · 5.48 KB
/
codeql.yml
File metadata and controls
176 lines (154 loc) · 5.48 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
name: CodeQL Security Analysis
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
schedule:
# Run weekly on Sundays at 2 AM UTC
- cron: '0 2 * * 0'
workflow_dispatch:
permissions:
contents: read
security-events: write
actions: read
deployments: read
env:
NODE_VERSION: '20'
jobs:
analyze:
name: CodeQL Analysis
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
language: ['javascript', 'typescript']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality
config-file: .github/codeql-config.yml
source-root: .
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
upload: true
upload-database: true
wait-for-processing: true
# Custom security checks for JavaScript/TypeScript
security-scan:
name: Additional Security Scans
runs-on: ubuntu-latest
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'
- name: Install dependencies
run: npm ci
- name: Run npm audit
run: |
echo "Running npm audit..."
npm audit --audit-level=moderate --json > npm-audit.json || true
npm audit --audit-level=moderate
continue-on-error: true
- name: Check for hardcoded secrets
run: |
echo "Scanning for hardcoded secrets..."
# Patterns to check for potential secrets
PATTERNS=(
"password\s*=\s*['\"][^'\"]+['\"]"
"api_key\s*=\s*['\"][^'\"]+['\"]"
"secret\s*=\s*['\"][^'\"]+['\"]"
"token\s*=\s*['\"][^'\"]+['\"]"
"private_key\s*=\s*['\"][^'\"]+['\"]"
"aws_access_key_id"
"aws_secret_access_key"
"[-0-9a-f]{32,}" # Potential API keys
)
FOUND=0
for pattern in "${PATTERNS[@]}"; do
if grep -riE "$pattern" packages/ src/ --include="*.ts" --include="*.js" --exclude-dir=node_modules --exclude-dir=dist; then
FOUND=1
fi
done
if [[ $FOUND -eq 1 ]]; then
echo "Warning: Potential hardcoded secrets found. Please review."
fi
continue-on-error: true
- name: Run Snyk security scan
if: env.SNYK_TOKEN != ''
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: |
npm install -g snyk
snyk test --severity-threshold=high || true
continue-on-error: true
- name: Check for dependency vulnerabilities
run: |
echo "Checking for known vulnerabilities..."
npm audit --production --audit-level=high
continue-on-error: true
# CodeQL database analysis
database-analysis:
name: Database Queries Analysis
runs-on: ubuntu-latest
needs: analyze
if: github.event_name == 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download CodeQL database
uses: github/codeql-action/database-upload@v3
with:
language: javascript
database: github/codeql
# Security summary
security-summary:
name: Security Summary
runs-on: ubuntu-latest
needs: [analyze, security-scan]
if: always()
steps:
- name: Generate security summary
run: |
echo "## Security Scan Summary 🔒" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| CodeQL Analysis | ${{ needs.analyze.result == 'success' && '✅ Passed' || '⚠️ Review Required' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Additional Scans | ${{ needs.security-scan.result == 'success' && '✅ Passed' || '⚠️ Review Required' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Recommendations:**" >> $GITHUB_STEP_SUMMARY
echo "- Review all security warnings in the Actions tab" >> $GITHUB_STEP_SUMMARY
echo "- Address high/critical severity issues promptly" >> $GITHUB_STEP_SUMMARY
echo "- Keep dependencies updated" >> $GITHUB_STEP_SUMMARY
- name: Comment on PR
if: github.event_name == 'pull_request' && (needs.analyze.result == 'failure' || needs.security-scan.result == 'failure')
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '⚠️ **Security Issues Detected**\n\nPlease review the security scan results in the Actions tab. High or critical severity issues must be addressed before merging.'
})