|
| 1 | +name: Security Scan |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + |
| 7 | +jobs: |
| 8 | + security: |
| 9 | + name: Security & Secrets Scan |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 0 # IMPORTANT: scan full history |
| 17 | + |
| 18 | + # ----------------------------- |
| 19 | + # 1. GITLEAKS |
| 20 | + # ----------------------------- |
| 21 | + - name: Run Gitleaks |
| 22 | + uses: gitleaks/gitleaks-action@v2 |
| 23 | + with: |
| 24 | + args: detect --source . --no-git |
| 25 | + |
| 26 | + # ----------------------------- |
| 27 | + # 2. TRUFFLEHOG (deep secrets) |
| 28 | + # ----------------------------- |
| 29 | + - name: Run TruffleHog |
| 30 | + uses: trufflesecurity/trufflehog@v3 |
| 31 | + with: |
| 32 | + path: . |
| 33 | + # Search git history too |
| 34 | + base: origin/main |
| 35 | + |
| 36 | + # ----------------------------- |
| 37 | + # 3. detect-secrets |
| 38 | + # ----------------------------- |
| 39 | + - name: Install detect-secrets |
| 40 | + run: pip install detect-secrets |
| 41 | + |
| 42 | + - name: Run detect-secrets |
| 43 | + run: | |
| 44 | + detect-secrets scan > .secrets.baseline |
| 45 | + detect-secrets audit .secrets.baseline || exit 1 |
| 46 | +
|
| 47 | + # ----------------------------- |
| 48 | + # 4. NPM / Node dependency scan |
| 49 | + # ----------------------------- |
| 50 | + - name: Install Node (optional) |
| 51 | + uses: actions/setup-node@v4 |
| 52 | + with: |
| 53 | + node-version: 20 |
| 54 | + |
| 55 | + - name: Run npm audit |
| 56 | + run: | |
| 57 | + if [ -f package-lock.json ]; then |
| 58 | + npm ci |
| 59 | + npm audit --production --audit-level=high |
| 60 | + fi |
| 61 | +
|
| 62 | + # ----------------------------- |
| 63 | + # 5. Python dependency scan |
| 64 | + # ----------------------------- |
| 65 | + - name: Python dependency audit |
| 66 | + uses: pypa/gh-action-pip-audit@v1.0.8 |
| 67 | + if: hashFiles('requirements.txt') != '' |
| 68 | + |
| 69 | + # ----------------------------- |
| 70 | + # 6. CodeQL Analysis (vulnerabilities) |
| 71 | + # ----------------------------- |
| 72 | + codeql: |
| 73 | + name: CodeQL |
| 74 | + runs-on: ubuntu-latest |
| 75 | + permissions: |
| 76 | + security-events: write |
| 77 | + actions: read |
| 78 | + contents: read |
| 79 | + |
| 80 | + strategy: |
| 81 | + fail-fast: false |
| 82 | + matrix: |
| 83 | + language: [ 'javascript', 'typescript', 'python', 'go' ] # adjust |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: Checkout code |
| 87 | + uses: actions/checkout@v4 |
| 88 | + |
| 89 | + - name: Initialize CodeQL |
| 90 | + uses: github/codeql-action/init@v3 |
| 91 | + with: |
| 92 | + languages: ${{ matrix.language }} |
| 93 | + |
| 94 | + - name: Autobuild |
| 95 | + uses: github/codeql-action/autobuild@v3 |
| 96 | + |
| 97 | + - name: Analyze |
| 98 | + uses: github/codeql-action/analyze@v3 |
0 commit comments