Skip to content

Security Scanning

Security Scanning #799

Workflow file for this run

# Scans for security vulnerabilities: dependency scanning (safety), code analysis
# (bandit), secrets detection (trufflehog), and Docker image scanning (trivy).
# Runs on PRs, main pushes, and daily at 02:00 UTC. Advisory only, does not block merges.
name: Security Scanning
on:
schedule:
# Run security scans daily at 2 AM UTC
- cron: '0 2 * * *'
pull_request:
branches: [ main, develop ]
push:
branches: [ main ]
permissions:
contents: read
jobs:
# =============================================================================
# DEPENDENCY SCAN
# =============================================================================
dependency-scan:
name: Dependency Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.13.7"
- name: Scan dependencies
run: |
pip install safety
safety check --file requirements.txt || echo "Vulnerabilities found - review required"
# =============================================================================
# CODE SECURITY SCAN
# =============================================================================
code-security:
name: Code Security
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.13.7"
- name: Run security analysis
run: |
pip install bandit
bandit -r src/ || echo "Security issues found - review required"
# =============================================================================
# SECRETS SCAN
# =============================================================================
secrets-scan:
name: Secrets Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
# Fetch more history for proper commit comparison
fetch-depth: 0
- name: Determine scan range
id: scan-range
run: |
if [ "${{ github.event_name }}" = "push" ]; then
# For push events, scan from the previous commit to current commit
if [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
echo "base=${{ github.event.before }}" >> $GITHUB_OUTPUT
echo "head=${{ github.sha }}" >> $GITHUB_OUTPUT
else
# New branch or initial commit - scan just the current commit
echo "base=HEAD~1" >> $GITHUB_OUTPUT
echo "head=HEAD" >> $GITHUB_OUTPUT
fi
elif [ "${{ github.event_name }}" = "pull_request" ]; then
# For PRs, scan from base branch to PR head
echo "base=${{ github.event.pull_request.base.sha }}" >> $GITHUB_OUTPUT
echo "head=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
else
# For scheduled runs, scan the last commit only
echo "base=HEAD~1" >> $GITHUB_OUTPUT
echo "head=HEAD" >> $GITHUB_OUTPUT
fi
- name: Scan for secrets
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ steps.scan-range.outputs.base }}
head: ${{ steps.scan-range.outputs.head }}
extra_args: --only-verified
# =============================================================================
# DOCKER SECURITY
# =============================================================================
docker-security:
name: Docker Security
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Build and scan image
run: docker build -t rewards-eligibility-oracle:security-scan .
- name: Run vulnerability scan
uses: aquasecurity/trivy-action@master
with:
image-ref: 'rewards-eligibility-oracle:security-scan'
format: 'table'