Skip to content

SAST Security Scan #145

SAST Security Scan

SAST Security Scan #145

Workflow file for this run

name: SAST Security Scan
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
schedule:
# Run at 2 AM UTC every day
- cron: '0 2 * * *'
permissions:
contents: read
security-events: write
actions: read
jobs:
semgrep:
name: Semgrep Scan
runs-on: ubuntu-latest
container:
image: semgrep/semgrep
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Run Semgrep
run: |
semgrep --config=auto \
--json \
--output=semgrep-results.json \
--error \
--severity=ERROR \
--severity=WARNING \
--severity=INFO \
--exclude=dist \
--exclude=node_modules \
--exclude=coverage \
.
continue-on-error: true
- name: Run Semgrep Searif
run: |
semgrep --config=auto \
--sarif \
--output=semgrep.sarif \
--error \
--severity=ERROR \
--severity=WARNING \
--severity=INFO \
--exclude=dist \
--exclude=node_modules \
--exclude=coverage \
.
continue-on-error: true
- name: Upload Semgrep results
if: always()
uses: actions/upload-artifact@v4
with:
name: semgrep-results
path: semgrep-results.json
retention-days: 14
- name: Upload SARIF file for GitHub Advanced Security Dashboard
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: semgrep.sarif
if: always()
snyk:
name: Snyk Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=medium --json-file-output=snyk-results.json --sarif-file-output=snyk.sarif
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarif
- name: Upload Snyk results
if: always()
uses: actions/upload-artifact@v4
with:
name: snyk-results
path: snyk-results.json
retention-days: 14
- name: Monitor dependencies with Snyk
if: github.ref == 'refs/heads/main'
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
trivy:
name: Trivy Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH,MEDIUM'
- name: Upload Trivy results to GitHub Security
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
- name: Run Trivy for summary
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'table'
severity: 'CRITICAL,HIGH,MEDIUM'
secrets-scan:
name: Secret Detection
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: TruffleHog OSS
if: github.event_name == 'pull_request'
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.repository.default_branch }}
head: HEAD
extra_args: --debug --only-verified
- name: Gitleaks
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
security-summary:
name: Security Summary
runs-on: ubuntu-latest
needs: [semgrep, snyk, trivy, secrets-scan]
if: always()
steps:
- name: Generate Security Summary
run: |
echo "## 🔒 Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Scanner | Status |" >> $GITHUB_STEP_SUMMARY
echo "|---------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Semgrep | ${{ needs.semgrep.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Snyk | ${{ needs.snyk.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Trivy | ${{ needs.trivy.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Secret Detection | ${{ needs.secrets-scan.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "View detailed results in the Security tab and workflow artifacts." >> $GITHUB_STEP_SUMMARY