|
| 1 | +name: Security Scan |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +jobs: |
| 8 | + contract-audit: |
| 9 | + name: Rust / Soroban Audit |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + issues: write # Required to comment on issues |
| 13 | + pull-requests: write |
| 14 | + defaults: |
| 15 | + run: |
| 16 | + working-directory: contracts |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - uses: dtolnay/rust-toolchain@stable |
| 22 | + with: |
| 23 | + components: clippy |
| 24 | + |
| 25 | + - uses: Swatinem/rust-cache@v2 |
| 26 | + with: |
| 27 | + workspaces: contracts |
| 28 | + |
| 29 | + - name: clippy |
| 30 | + run: cargo clippy --all-targets -- -D warnings |
| 31 | + |
| 32 | + - name: cargo audit |
| 33 | + run: | |
| 34 | + cargo install cargo-audit --locked --quiet |
| 35 | + cargo audit 2>&1 | tee /tmp/audit-output.txt |
| 36 | + exit ${PIPESTATUS[0]} |
| 37 | +
|
| 38 | + - name: Soroban pattern check |
| 39 | + run: node ../scripts/soroban-security-check.mjs 2>&1 | tee /tmp/soroban-output.txt |
| 40 | + |
| 41 | + - name: Post contract audit summary |
| 42 | + if: always() |
| 43 | + uses: actions/github-script@v7 |
| 44 | + with: |
| 45 | + script: | |
| 46 | + const fs = require('fs') |
| 47 | + const audit = fs.existsSync('/tmp/audit-output.txt') |
| 48 | + ? fs.readFileSync('/tmp/audit-output.txt', 'utf8').trim() |
| 49 | + : '(no output)' |
| 50 | + const soroban = fs.existsSync('/tmp/soroban-output.txt') |
| 51 | + ? fs.readFileSync('/tmp/soroban-output.txt', 'utf8').trim() |
| 52 | + : '(no output)' |
| 53 | + const body = [ |
| 54 | + '## 🔐 Contract Security Scan', |
| 55 | + '', |
| 56 | + '<details><summary>cargo audit</summary>', |
| 57 | + '', |
| 58 | + '```', |
| 59 | + audit, |
| 60 | + '```', |
| 61 | + '', |
| 62 | + '</details>', |
| 63 | + '', |
| 64 | + '<details><summary>Soroban pattern check</summary>', |
| 65 | + '', |
| 66 | + '```', |
| 67 | + soroban, |
| 68 | + '```', |
| 69 | + '', |
| 70 | + '</details>', |
| 71 | + ].join('\n') |
| 72 | + await github.rest.issues.createComment({ |
| 73 | + owner: context.repo.owner, |
| 74 | + repo: context.repo.repo, |
| 75 | + issue_number: context.issue.number, |
| 76 | + body, |
| 77 | + }) |
| 78 | +
|
| 79 | + frontend-audit: |
| 80 | + name: Frontend Audit |
| 81 | + runs-on: ubuntu-latest |
| 82 | + |
| 83 | + steps: |
| 84 | + - uses: actions/checkout@v4 |
| 85 | + |
| 86 | + - uses: actions/setup-node@v4 |
| 87 | + with: |
| 88 | + node-version: 22 |
| 89 | + cache: npm |
| 90 | + |
| 91 | + - run: npm ci |
| 92 | + |
| 93 | + - name: npm audit |
| 94 | + run: npm audit --audit-level=high 2>&1 | tee /tmp/npm-audit.txt; exit ${PIPESTATUS[0]} |
| 95 | + |
| 96 | + - name: ESLint security |
| 97 | + run: npm run lint 2>&1 | tee /tmp/eslint-output.txt; exit ${PIPESTATUS[0]} |
| 98 | + |
| 99 | + - name: Check for hardcoded secrets |
| 100 | + run: | |
| 101 | + node scripts/check-secrets.mjs 2>&1 | tee /tmp/secrets-output.txt |
| 102 | + exit ${PIPESTATUS[0]} |
| 103 | +
|
| 104 | + - name: Post frontend audit summary |
| 105 | + if: always() |
| 106 | + uses: actions/github-script@v7 |
| 107 | + with: |
| 108 | + script: | |
| 109 | + const fs = require('fs') |
| 110 | + const read = (p) => fs.existsSync(p) ? fs.readFileSync(p, 'utf8').trim() : '(no output)' |
| 111 | + const body = [ |
| 112 | + '## 🛡️ Frontend Security Scan', |
| 113 | + '', |
| 114 | + '<details><summary>npm audit</summary>', |
| 115 | + '', |
| 116 | + '```', |
| 117 | + read('/tmp/npm-audit.txt'), |
| 118 | + '```', |
| 119 | + '', |
| 120 | + '</details>', |
| 121 | + '', |
| 122 | + '<details><summary>ESLint</summary>', |
| 123 | + '', |
| 124 | + '```', |
| 125 | + read('/tmp/eslint-output.txt'), |
| 126 | + '```', |
| 127 | + '', |
| 128 | + '</details>', |
| 129 | + '', |
| 130 | + '<details><summary>Hardcoded secrets check</summary>', |
| 131 | + '', |
| 132 | + '```', |
| 133 | + read('/tmp/secrets-output.txt'), |
| 134 | + '```', |
| 135 | + '', |
| 136 | + '</details>', |
| 137 | + ].join('\n') |
| 138 | + await github.rest.issues.createComment({ |
| 139 | + owner: context.repo.owner, |
| 140 | + repo: context.repo.repo, |
| 141 | + issue_number: context.issue.number, |
| 142 | + body, |
| 143 | + }) |
0 commit comments