|
| 1 | +name: Security Scanning |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, master ] |
| 8 | + schedule: |
| 9 | + # Run security scan every Monday at 9am UTC |
| 10 | + - cron: '0 9 * * 1' |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +jobs: |
| 14 | + npm-audit: |
| 15 | + name: NPM Security Audit |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Setup Node.js |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: '20' |
| 26 | + cache: 'npm' |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: npm ci |
| 30 | + |
| 31 | + - name: Run npm audit |
| 32 | + run: | |
| 33 | + echo "## NPM Security Audit Results" >> $GITHUB_STEP_SUMMARY |
| 34 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 35 | +
|
| 36 | + # Run audit and capture output |
| 37 | + if npm audit --audit-level=moderate 2>&1 | tee audit.txt; then |
| 38 | + echo "✅ No vulnerabilities found!" >> $GITHUB_STEP_SUMMARY |
| 39 | + else |
| 40 | + echo "⚠️ Vulnerabilities detected - see details below" >> $GITHUB_STEP_SUMMARY |
| 41 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 42 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 43 | + cat audit.txt >> $GITHUB_STEP_SUMMARY |
| 44 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Check for outdated dependencies |
| 49 | + run: | |
| 50 | + echo "## Outdated Dependencies" >> $GITHUB_STEP_SUMMARY |
| 51 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 52 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 53 | + npm outdated >> $GITHUB_STEP_SUMMARY || true |
| 54 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 55 | + continue-on-error: true |
| 56 | + |
| 57 | + codeql: |
| 58 | + name: CodeQL Security Analysis |
| 59 | + runs-on: ubuntu-latest |
| 60 | + permissions: |
| 61 | + security-events: write |
| 62 | + actions: read |
| 63 | + contents: read |
| 64 | + |
| 65 | + strategy: |
| 66 | + fail-fast: false |
| 67 | + matrix: |
| 68 | + language: [ 'javascript' ] |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Checkout code |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: Initialize CodeQL |
| 75 | + uses: github/codeql-action/init@v3 |
| 76 | + with: |
| 77 | + languages: ${{ matrix.language }} |
| 78 | + # Optional: Add custom queries |
| 79 | + # queries: security-extended,security-and-quality |
| 80 | + |
| 81 | + - name: Autobuild |
| 82 | + uses: github/codeql-action/autobuild@v3 |
| 83 | + |
| 84 | + - name: Perform CodeQL Analysis |
| 85 | + uses: github/codeql-action/analyze@v3 |
| 86 | + with: |
| 87 | + category: "/language:${{matrix.language}}" |
| 88 | + |
| 89 | + dependency-review: |
| 90 | + name: Dependency Review |
| 91 | + runs-on: ubuntu-latest |
| 92 | + # Only run on pull requests |
| 93 | + if: github.event_name == 'pull_request' |
| 94 | + |
| 95 | + steps: |
| 96 | + - name: Checkout code |
| 97 | + uses: actions/checkout@v4 |
| 98 | + |
| 99 | + - name: Dependency Review |
| 100 | + uses: actions/dependency-review-action@v4 |
| 101 | + with: |
| 102 | + # Fail the build if vulnerabilities are found |
| 103 | + fail-on-severity: moderate |
| 104 | + # Add comment to PR with results |
| 105 | + comment-summary-in-pr: always |
0 commit comments