Skip to content

Security Scan

Security Scan #212

Workflow file for this run

name: Security Scan
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
schedule:
# Run security scan daily at 2 AM UTC
- cron: '0 2 * * *'
jobs:
security-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install bandit safety
- name: Run Bandit Security Scan
run: |
bandit -r . -f json -o bandit-report.json || true
bandit -r . -f txt || true
- name: Run Safety Check
run: |
safety check --json --output safety-report.json || true
safety check || true
- name: Run Semgrep Security Scan
uses: semgrep/semgrep-action@v1
with:
config: >-
p/security-audit
p/python
p/flask
p/streamlit
- name: Upload security scan results
uses: actions/upload-artifact@v4
if: always()
with:
name: security-reports
path: |
bandit-report.json
safety-report.json
- name: Comment PR with security findings
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
try {
const bandit = JSON.parse(fs.readFileSync('bandit-report.json', 'utf8'));
const safety = JSON.parse(fs.readFileSync('safety-report.json', 'utf8'));
let comment = '## 🔒 Security Scan Results\n\n';
if (bandit.results.length > 0) {
comment += '### Bandit Issues:\n';
bandit.results.forEach(issue => {
comment += `- ${issue.test_name} (${issue.issue_severity}): ${issue.issue_text}\n`;
});
} else {
comment += '### ✅ No Bandit issues found\n';
}
if (safety.vulnerabilities.length > 0) {
comment += '\n### Dependency Vulnerabilities:\n';
safety.vulnerabilities.forEach(vuln => {
comment += `- ${vuln.package}: ${vuln.advisory}\n`;
});
} else {
comment += '\n### ✅ No dependency vulnerabilities found\n';
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
} catch (e) {
console.log('Could not read security reports');
}