Skip to content

Security Scan

Security Scan #22

Workflow file for this run

name: Security Scan
on:
schedule:
# Run weekly on Monday at 9 AM UTC
- cron: '0 9 * * 1'
push:
branches: [main]
paths:
- 'pnpm-lock.yaml'
- '**/package.json'
workflow_dispatch:
permissions:
contents: read
security-events: write
jobs:
dependency-audit:
name: Dependency Audit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '22.x'
cache: 'pnpm'
cache-dependency-path: pnpm-lock.yaml
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run npm audit
run: |
echo "## Dependency Audit Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### High and Critical Vulnerabilities" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
pnpm audit --audit-level=high 2>&1 | tee audit-high.txt || true
cat audit-high.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# Fail if there are high or critical vulnerabilities
if grep -q "found [1-9]" audit-high.txt; then
echo "::warning::Security vulnerabilities found. Review the audit report."
fi
- name: Check for outdated packages
run: |
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Outdated Packages" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
pnpm outdated 2>&1 | head -50 >> $GITHUB_STEP_SUMMARY || true
echo '```' >> $GITHUB_STEP_SUMMARY
codeql:
name: CodeQL Analysis
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: javascript-typescript
queries: security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@v4
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:javascript-typescript"
docker-scan:
name: Docker Image Scan
runs-on: ubuntu-latest
strategy:
matrix:
service: [auth, api, app]
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image for scanning
uses: docker/build-push-action@v6
with:
context: .
file: apps/${{ matrix.service }}/Dockerfile
push: false
load: true
tags: core-exchange-${{ matrix.service }}:scan
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: 'core-exchange-${{ matrix.service }}:scan'
format: 'sarif'
output: 'trivy-results-${{ matrix.service }}.sarif'
severity: 'CRITICAL,HIGH'
env:
TRIVY_DB_REPOSITORY: 'ghcr.io/aquasecurity/trivy-db:2'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: 'trivy-results-${{ matrix.service }}.sarif'
- name: Trivy summary
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: 'core-exchange-${{ matrix.service }}:scan'
format: 'table'
severity: 'CRITICAL,HIGH,MEDIUM'
env:
TRIVY_DB_REPOSITORY: 'ghcr.io/aquasecurity/trivy-db:2'