|
| 1 | +name: Security |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + pull_request: |
| 9 | + schedule: |
| 10 | + - cron: "0 3 * * 1" |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + security-events: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + dependency-review: |
| 18 | + if: github.event_name == 'pull_request' && vars.ENABLE_DEPENDENCY_REVIEW == 'true' |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + pull-requests: write |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Dependency review |
| 28 | + uses: actions/dependency-review-action@v4 |
| 29 | + |
| 30 | + npm-audit: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: Checkout |
| 34 | + uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Setup Node |
| 37 | + uses: actions/setup-node@v4 |
| 38 | + with: |
| 39 | + node-version: 20 |
| 40 | + cache: npm |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + run: npm ci |
| 44 | + |
| 45 | + - name: Audit production dependencies (with temporary lodash exception) |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + npm audit --omit=dev --json > audit-prod.json || true |
| 50 | +
|
| 51 | + node - <<'NODE' |
| 52 | + const fs = require("fs"); |
| 53 | +
|
| 54 | + const report = JSON.parse(fs.readFileSync("audit-prod.json", "utf8")); |
| 55 | + const vulnerabilities = report.vulnerabilities || {}; |
| 56 | + const ignoreAdvisories = new Set([ |
| 57 | + "GHSA-xxjr-mmjv-4gpg", |
| 58 | + "GHSA-r5fr-rjxr-66jc", |
| 59 | + "GHSA-f23m-r3pf-42rh", |
| 60 | + ]); |
| 61 | +
|
| 62 | + const failing = []; |
| 63 | +
|
| 64 | + for (const [pkg, details] of Object.entries(vulnerabilities)) { |
| 65 | + const via = Array.isArray(details.via) ? details.via : []; |
| 66 | + const nonIgnoredVia = via.filter((entry) => { |
| 67 | + if (typeof entry === "string") { |
| 68 | + return true; |
| 69 | + } |
| 70 | + const sev = (entry.severity || "").toLowerCase(); |
| 71 | + if (sev !== "high" && sev !== "critical") { |
| 72 | + return false; |
| 73 | + } |
| 74 | + const url = entry.url || ""; |
| 75 | + const ghsa = url.split("/").pop() || ""; |
| 76 | + return !ignoreAdvisories.has(ghsa); |
| 77 | + }); |
| 78 | +
|
| 79 | + if (nonIgnoredVia.length > 0) { |
| 80 | + failing.push({ pkg, severity: details.severity, via: nonIgnoredVia }); |
| 81 | + } |
| 82 | + } |
| 83 | +
|
| 84 | + if (failing.length > 0) { |
| 85 | + console.error("High/Critical vulnerabilities found (excluding temporary lodash exception):"); |
| 86 | + for (const item of failing) { |
| 87 | + console.error(`- ${item.pkg} (${item.severity})`); |
| 88 | + } |
| 89 | + process.exit(1); |
| 90 | + } |
| 91 | +
|
| 92 | + console.log("No blocking high/critical production vulnerabilities found."); |
| 93 | + NODE |
| 94 | +
|
| 95 | + - name: Audit full dependency tree (informational) |
| 96 | + continue-on-error: true |
| 97 | + shell: bash |
| 98 | + run: | |
| 99 | + set -euo pipefail |
| 100 | + npm audit --json > audit-full.json || true |
| 101 | +
|
| 102 | + node - <<'NODE' |
| 103 | + const fs = require("fs"); |
| 104 | +
|
| 105 | + const report = JSON.parse(fs.readFileSync("audit-full.json", "utf8")); |
| 106 | + const vulnerabilities = report.vulnerabilities || {}; |
| 107 | + const ignoreAdvisories = new Set([ |
| 108 | + "GHSA-xxjr-mmjv-4gpg", |
| 109 | + "GHSA-r5fr-rjxr-66jc", |
| 110 | + "GHSA-f23m-r3pf-42rh", |
| 111 | + ]); |
| 112 | +
|
| 113 | + const failing = []; |
| 114 | +
|
| 115 | + for (const [pkg, details] of Object.entries(vulnerabilities)) { |
| 116 | + const via = Array.isArray(details.via) ? details.via : []; |
| 117 | + const nonIgnoredVia = via.filter((entry) => { |
| 118 | + if (typeof entry === "string") { |
| 119 | + return true; |
| 120 | + } |
| 121 | + const sev = (entry.severity || "").toLowerCase(); |
| 122 | + if (sev !== "high" && sev !== "critical") { |
| 123 | + return false; |
| 124 | + } |
| 125 | + const url = entry.url || ""; |
| 126 | + const ghsa = url.split("/").pop() || ""; |
| 127 | + return !ignoreAdvisories.has(ghsa); |
| 128 | + }); |
| 129 | +
|
| 130 | + if (nonIgnoredVia.length > 0) { |
| 131 | + failing.push({ pkg, severity: details.severity, via: nonIgnoredVia }); |
| 132 | + } |
| 133 | + } |
| 134 | +
|
| 135 | + if (failing.length > 0) { |
| 136 | + console.error("High/Critical vulnerabilities found in full tree (excluding temporary lodash exception):"); |
| 137 | + for (const item of failing) { |
| 138 | + console.error(`- ${item.pkg} (${item.severity})`); |
| 139 | + } |
| 140 | + process.exit(1); |
| 141 | + } |
| 142 | +
|
| 143 | + console.log("No blocking high/critical vulnerabilities found in full tree."); |
| 144 | + NODE |
| 145 | +
|
| 146 | + codeql: |
| 147 | + runs-on: ubuntu-latest |
| 148 | + steps: |
| 149 | + - name: Checkout |
| 150 | + uses: actions/checkout@v4 |
| 151 | + |
| 152 | + - name: Initialize CodeQL |
| 153 | + uses: github/codeql-action/init@v3 |
| 154 | + with: |
| 155 | + languages: javascript-typescript |
| 156 | + |
| 157 | + - name: Autobuild |
| 158 | + uses: github/codeql-action/autobuild@v3 |
| 159 | + |
| 160 | + - name: Perform CodeQL Analysis |
| 161 | + uses: github/codeql-action/analyze@v3 |
| 162 | + |
| 163 | + trivy-filesystem: |
| 164 | + runs-on: ubuntu-latest |
| 165 | + steps: |
| 166 | + - name: Checkout |
| 167 | + uses: actions/checkout@v4 |
| 168 | + |
| 169 | + - name: Trivy filesystem scan |
| 170 | + uses: aquasecurity/trivy-action@v0.24.0 |
| 171 | + with: |
| 172 | + scan-type: fs |
| 173 | + scan-ref: . |
| 174 | + format: sarif |
| 175 | + output: trivy-fs.sarif |
| 176 | + severity: HIGH,CRITICAL |
| 177 | + ignore-unfixed: true |
| 178 | + |
| 179 | + - name: Upload Trivy scan results |
| 180 | + uses: github/codeql-action/upload-sarif@v3 |
| 181 | + with: |
| 182 | + sarif_file: trivy-fs.sarif |
0 commit comments