π Supply Chain Security with CodeQL Integration
This repository demonstrates a complete GitHub Actions workflow that creates cryptographically signed artifact attestations enriched with CodeQL security scan results. It provides a tamper-evident audit trail linking software artifacts to their source code, build process, and security analysis.
Creates artifact attestations that include:
- β Build Provenance - Who built it, when, and how
- β CodeQL Scan Results - Security vulnerabilities found
- β Pull Request Context - Which PR introduced changes
- β Complete Audit Trail - Immutable record of the entire process
The workflow (.github/workflows/attestation.yml) runs automatically on:
- Push to
mainordevelopbranches - Pull request merges to
main
βββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
β Build βββββΆβ CodeQL βββββΆβ Attestation β
β Package β β Scan β β Creation β
βββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
- Builds Python package from source
- Generates cryptographic hash (SHA256)
- Uploads artifacts for later stages
- Runs CodeQL analysis with
security-and-qualityqueries - Generates SARIF results with vulnerability details
- Uploads results to GitHub Security tab
- Saves scan data for attestation
- Combines build info + CodeQL results + PR metadata
- Creates custom attestation predicate
- Generates cryptographically signed attestation
- Links everything together immutably
The custom attestation includes:
{
"predicateType": "https://github.com/attestations/codeql-scan/v1",
"predicate": {
"artifact": {
"name": "poc_codeql_artifact_attestation-1.0.0.tar.gz",
"digest": "sha256:abc123...",
"buildTimestamp": "2025-09-10T14:30:00Z"
},
"pullRequest": {
"number": 42,
"author": "developer",
"mergeCommit": "def456...",
"mergedAt": "2025-09-10T14:35:00Z"
},
"codeqlScan": {
"resultCount": 15,
"sarif_results": [...],
"alertsSummary": {
"total": 20,
"open": 5,
"fixed": 3,
"by_severity": {"high": 2, "medium": 8, "low": 5}
}
}
}
}- GitHub repository with CodeQL enabled
- Python project with
pyproject.toml - Required workflow permissions (automatically configured)
- Copy the workflow from
.github/workflows/attestation.ymlto your repository - Ensure CodeQL is enabled in repository settings β Security β Code scanning
- Create a PR or push to
main/developto trigger the workflow - View results in the Actions tab and Security tab
Use GitHub CLI to verify attestations:
gh attestation verify artifact.tar.gz --repo owner/repositorypoc-codeql-artifact-attestation/
βββ .github/workflows/
β βββ attestation.yml # Main CodeQL attestation workflow
βββ scripts/
β βββ parse_sarif.py # SARIF parser utility
β βββ build_predicate.py # Attestation predicate builder
βββ app.py # Flask app with vulnerabilities
βββ database.py # SQL injection examples
βββ networking.py # SSRF vulnerabilities
βββ main.py # Demo script
βββ pyproject.toml # Package configuration
βββ requirements.txt # Vulnerable dependencies
βββ WORKFLOW_GUIDE.md # Detailed workflow documentation
β
Supply Chain Security - Links artifacts to exact source and scan results
β
Audit Trail - Complete record of what was scanned and when
β
Compliance - Meets software supply chain security requirements
β
Transparency - All security findings embedded in attestation
β
Tamper Evidence - Cryptographic signatures prevent modification
β
Automated - No manual intervention required
This repository contains intentional security vulnerabilities perfect for testing the CodeQL workflow:
- SQL Injection: Multiple functions in
database.py - Command Injection:
app.pyping endpoint - Code Injection:
eval()andexec()usage inutils.py - LDAP Injection: Simulated in
app.py
- Reflected XSS: Search endpoint in
app.py - Template Injection: Direct template rendering
- Debug Mode: Enabled in production
- Hardcoded Secrets: Throughout codebase
- Insecure Dependencies: Old versions with known CVEs
- Weak Passwords: MD5 hashing
- Predictable Tokens: Fixed seed random generation
- Session Fixation: No proper session management
- Information Disclosure: Debug endpoints
- Logging Sensitive Data: Passwords in logs
- Configuration Exposure: Secrets in config files
- Path Traversal: File reading without validation
- Insecure Direct Object References: User ID enumeration
- Open Redirect: Unvalidated redirects
- Internal Network Access: Unvalidated URL requests
- Protocol Smuggling: Support for various protocols
- Pickle Deserialization: Unsafe pickle.loads()
- YAML Unsafe Load: yaml.load() without safe loader
- Outdated Dependencies: Specific old versions with CVEs
- Vulnerable Libraries: Flask 1.0.2, PyYAML 3.13, etc.
- Sensitive Data in Logs: Passwords and tokens logged
- No Security Event Monitoring: Missing security alerts
-
Set up environment:
python -m pip install -r requirements.txt
-
Run the vulnerable web app:
python app.py
-
Run demo exploits:
python main.py
SQL Injection:
# In database.py - CodeQL will flag this
cursor.execute(f"SELECT * FROM users WHERE username = '{username}'")Command Injection:
# In app.py - CodeQL will detect this
os.system(f"ping -c 1 {host}")XSS Vulnerability:
# In app.py - CodeQL will identify this
return f"<h1>Search results for: {query}</h1>"- Make changes to the vulnerable code
- Create a pull request
- Watch the workflow run CodeQL analysis
- Review the attestation with embedded security findings
- See results in GitHub Security tab
This project works great with:
- CodeQL - Static analysis (primary focus)
- Bandit - Python security linter
- Safety - Dependency vulnerability scanner
- OWASP ZAP - Web application scanner
- Burp Suite - Manual security testing
When the workflow completes successfully, you'll see:
- CodeQL scan results with detailed findings
- Alert timeline and status tracking
- SARIF file uploads with vulnerability details
python-package- Built software artifactcodeql-sarif- Raw SARIF scan resultsattestation-data- Custom CodeQL predicate JSON
- Build Provenance - GitHub's native attestation
- Custom CodeQL Data - Embedded in workflow artifacts
- Cryptographic signatures linking everything together
π Artifact Attestation Created
Artifact: poc_codeql_artifact_attestation-1.0.0.tar.gz
Hash: sha256:abc123...
CodeQL Scan: β
Completed
Build Provenance: β
Generated and signed
Custom CodeQL Data: β
Saved to artifacts
This workflow pattern is valuable for:
- Enterprise Software - Compliance and audit requirements
- Open Source Projects - Transparency and trust building
- CI/CD Pipelines - Automated security verification
- Supply Chain Security - SLSA compliance
- Regulatory Requirements - SOX, GDPR, HIPAA compliance
- Security Research - Vulnerability analysis and tracking
This is a proof-of-concept project. Contributions welcome for:
- Additional vulnerability examples
- Workflow improvements
- Documentation enhancements
- Language-specific adaptations
- Detailed Workflow Guide: See
WORKFLOW_GUIDE.md - GitHub Attestations: Official Documentation
- CodeQL Documentation: Getting Started
- SLSA Framework: Supply Chain Security
π Ready to implement supply chain security with CodeQL integration!