Skip to content

Commit 29dedd1

Browse files
committed
ci: add CodeQL SAST workflow
Static analysis for security vulnerabilities: - Python analysis with security-extended queries - Runs on push, PR, and weekly schedule - SARIF results uploaded to Security tab + artifacts
1 parent 5ac9f92 commit 29dedd1

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

.github/workflows/codeql.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# CodeQL Static Application Security Testing (SAST)
2+
# https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning-for-a-repository
3+
#
4+
# Analyzes Python and Rust code for:
5+
# - Security vulnerabilities (injection, XSS, SSRF, etc.)
6+
# - Code quality issues
7+
# - Supply chain risks
8+
# - Common programming errors
9+
#
10+
# Results appear in GitHub Security tab and as PR annotations.
11+
12+
name: CodeQL
13+
14+
on:
15+
push:
16+
branches: [main]
17+
pull_request:
18+
branches: [main]
19+
schedule:
20+
# Weekly deep scan on Sunday at 3am UTC
21+
- cron: "0 3 * * 0"
22+
workflow_dispatch:
23+
# Manual trigger for ad-hoc security analysis
24+
25+
permissions:
26+
contents: read
27+
security-events: write # Required for uploading SARIF results
28+
actions: read # Required for workflow status
29+
30+
concurrency:
31+
group: codeql-${{ github.workflow }}-${{ github.ref }}
32+
cancel-in-progress: true
33+
34+
jobs:
35+
analyze:
36+
name: Analyze (${{ matrix.language }})
37+
runs-on: ubuntu-latest
38+
timeout-minutes: 30
39+
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
language:
44+
- python
45+
# Note: Rust support is limited in CodeQL
46+
# We rely on cargo-audit, cargo-deny, and Miri for Rust security
47+
# CodeQL language config
48+
# https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#changing-the-languages-that-are-analyzed
49+
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
54+
# Python setup for accurate analysis
55+
- name: Set up Python
56+
if: matrix.language == 'python'
57+
uses: actions/setup-python@v5
58+
with:
59+
python-version: "3.12"
60+
61+
- name: Install Python dependencies
62+
if: matrix.language == 'python'
63+
run: |
64+
python -m pip install --upgrade pip
65+
# Install dependencies so CodeQL can analyze import resolution
66+
pip install -e ".[data]" || pip install -e .
67+
68+
# Initialize CodeQL
69+
- name: Initialize CodeQL
70+
uses: github/codeql-action/init@v3
71+
with:
72+
languages: ${{ matrix.language }}
73+
# Use security-extended for maximum coverage
74+
# Options: security-extended, security-and-quality
75+
queries: security-extended
76+
# Config file for custom queries (optional)
77+
# config-file: .github/codeql/codeql-config.yml
78+
79+
# Autobuild attempts to build any compiled code
80+
# For Python, this is largely a no-op but ensures imports resolve
81+
- name: Autobuild
82+
uses: github/codeql-action/autobuild@v3
83+
84+
# Run CodeQL analysis
85+
- name: Perform CodeQL Analysis
86+
uses: github/codeql-action/analyze@v3
87+
with:
88+
category: "/language:${{ matrix.language }}"
89+
# Upload SARIF to GitHub Security tab
90+
upload: true
91+
# Also output SARIF for artifact storage
92+
output: sarif-results
93+
94+
# Archive SARIF for audit trail
95+
- name: Upload SARIF artifact
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: codeql-sarif-${{ matrix.language }}
99+
path: sarif-results
100+
retention-days: 90

0 commit comments

Comments
 (0)