security.ymlβ’6.45 kB
name: Security Checks
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
schedule:
# Run security checks weekly on Monday at 00:00 UTC
- cron: '0 0 * * 1'
workflow_dispatch: # Allow manual trigger
# Cancel in-progress runs when a new workflow with the same group name is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
dependency-scan:
name: Dependency Vulnerability Scan
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run pnpm audit
id: audit
run: |
echo "Running pnpm audit..."
pnpm audit --audit-level moderate --json > audit-results.json || true
# Check if there are any vulnerabilities
VULN_COUNT=$(cat audit-results.json | jq '.metadata.vulnerabilities | to_entries | map(select(.value > 0)) | length')
if [ "$VULN_COUNT" -gt 0 ]; then
echo "::warning::Found $VULN_COUNT vulnerability types in dependencies"
cat audit-results.json | jq '.metadata.vulnerabilities'
else
echo "No vulnerabilities found"
fi
continue-on-error: true
- name: Upload audit results
if: always()
uses: actions/upload-artifact@v4
with:
name: dependency-audit-results
path: audit-results.json
retention-days: 30
codeql-analysis:
name: CodeQL Security Scan
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ['javascript']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality
config: |
paths-ignore:
- node_modules
- dist
- build
- coverage
- '**/*.test.ts'
- '**/*.spec.ts'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build project
run: pnpm build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
upload: true
secret-scan:
name: Secret Detection Scan
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better secret detection
- name: TruffleHog Secret Scan
uses: trufflesecurity/trufflehog@main
with:
extra_args: --only-verified --json
path: ./
base: ${{ github.event.pull_request.base.sha || github.event.before || format('HEAD~{0}', '1') }}
head: ${{ github.event.pull_request.head.sha || github.event.after || 'HEAD' }}
license-check:
name: License Compliance Check
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.18.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check licenses
run: |
# Install license checker
pnpm add -g license-checker
# Run license check and output to file
license-checker --json --out license-report.json || true
# Check for problematic licenses
PROBLEMATIC_LICENSES="GPL-2.0,GPL-3.0,AGPL-1.0,AGPL-3.0"
echo "Checking for problematic licenses..."
if license-checker --failOn "$PROBLEMATIC_LICENSES" --summary; then
echo "β
No problematic licenses found"
else
echo "::warning::Found potentially problematic licenses. Review license-report.json"
fi
- name: Upload license report
if: always()
uses: actions/upload-artifact@v4
with:
name: license-compliance-report
path: license-report.json
retention-days: 30
security-summary:
name: Security Summary
runs-on: ubuntu-latest
needs: [dependency-scan, codeql-analysis, secret-scan, license-check]
if: always()
permissions:
contents: read
steps:
- name: Generate Security Summary
run: |
echo "# π Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Job Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Dependency Scan | ${{ needs.dependency-scan.result == 'success' && 'β
Passed' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| CodeQL Analysis | ${{ needs.codeql-analysis.result == 'success' && 'β
Passed' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Secret Detection | ${{ needs.secret-scan.result == 'success' && 'β
Passed' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| License Check | ${{ needs.license-check.result == 'success' && 'β
Passed' || 'β Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "View detailed results in the Security tab of this repository." >> $GITHUB_STEP_SUMMARY