|
1 | 1 | name: Slither Static Analysis |
2 | 2 |
|
3 | | -# ============================================================================ |
4 | | -# TRIGGER: Runs on every push and pull request to main and develop branches |
5 | | -# ============================================================================ |
6 | 3 | on: |
7 | 4 | pull_request: |
8 | 5 | branches: |
|
15 | 12 |
|
16 | 13 | jobs: |
17 | 14 | slither: |
18 | | - name: Run Slither Analysis |
| 15 | + name: Solidity / Slither scan |
19 | 16 | runs-on: ubuntu-latest |
20 | 17 | permissions: |
21 | 18 | contents: read |
22 | | - security-events: write |
23 | | - pull-requests: write |
24 | 19 |
|
25 | 20 | steps: |
26 | 21 | - name: Checkout code |
27 | 22 | uses: actions/checkout@v4 |
28 | | - with: |
29 | | - fetch-depth: 0 |
30 | 23 |
|
31 | | - # ====================================================================== |
32 | | - # DEPENDENCY INSTALLATION PHASE |
33 | | - # Ensures Slither can compile and analyze smart contracts |
34 | | - # ====================================================================== |
35 | | - - name: Setup Node.js |
36 | | - uses: actions/setup-node@v4 |
37 | | - with: |
38 | | - node-version: 20 |
39 | | - cache: npm |
40 | | - |
41 | | - - name: Setup Foundry (for Solidity compilation) |
42 | | - uses: foundry-rs/foundry-toolchain@v1 |
43 | | - continue-on-error: true |
44 | | - |
45 | | - - name: Install dependencies |
| 24 | + - name: Skip when no Solidity contracts are present |
| 25 | + shell: bash |
46 | 26 | run: | |
47 | | - echo "📦 Installing project dependencies..." |
48 | | - npm install || true |
49 | | - npm run build 2>/dev/null || true |
50 | | - if [ -f "Cargo.toml" ]; then |
51 | | - cargo build 2>/dev/null || true |
52 | | - fi |
53 | | - echo "✓ Dependencies installed (continuation on error for flexibility)" |
54 | | -
|
55 | | - # ====================================================================== |
56 | | - # STATIC ANALYSIS PHASE |
57 | | - # Run Slither with severity-based failure thresholds |
58 | | - # ====================================================================== |
59 | | - - name: Run Slither analysis |
60 | | - uses: crytic/slither-action@latest |
61 | | - id: slither |
62 | | - with: |
63 | | - target: . |
64 | | - sarif: results.sarif |
65 | | - # SEVERITY POLICY: |
66 | | - # - fail-on: medium → Fails build for High AND Medium severity |
67 | | - # - Low and Informational findings are logged but don't block merge |
68 | | - fail-on: medium |
69 | | - slither-config: slither.config.json |
70 | | - continue-on-error: true |
71 | | - |
72 | | - # ====================================================================== |
73 | | - # GITHUB SECURITY INTEGRATION |
74 | | - # Uploads SARIF report to GitHub Security tab for visibility |
75 | | - # ====================================================================== |
76 | | - - name: Upload SARIF to GitHub Security tab |
77 | | - uses: github/codeql-action/upload-sarif@v2 |
78 | | - if: always() |
79 | | - with: |
80 | | - sarif_file: results.sarif |
81 | | - wait-for-processing: true |
82 | | - continue-on-error: true |
| 27 | + set -euo pipefail |
83 | 28 |
|
84 | | - # ====================================================================== |
85 | | - # PR COMMENT WITH RESULTS |
86 | | - # Posts a summary comment on the PR with key findings |
87 | | - # ====================================================================== |
88 | | - - name: Comment PR with security summary |
89 | | - if: github.event_name == 'pull_request' && always() |
90 | | - uses: actions/github-script@v7 |
91 | | - with: |
92 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
93 | | - script: | |
94 | | - const fs = require('fs'); |
95 | | - const severity = { |
96 | | - 🔴: 'High/Medium (Build Blocking)', |
97 | | - 🟡: 'Low (Informational)', |
98 | | - ✅: 'No findings' |
99 | | - }; |
100 | | - |
101 | | - let summary = '## 🔍 Slither Static Analysis Results\n\n'; |
102 | | - summary += '**Severity Policy:**\n'; |
103 | | - summary += '- 🔴 High/Medium findings **BLOCK** the build\n'; |
104 | | - summary += '- 🟡 Low/Informational findings are **LOGGED** (non-blocking)\n\n'; |
105 | | - summary += '**See Results:**\n'; |
106 | | - summary += '- [GitHub Security Tab](../../security/code-scanning) for full SARIF report\n'; |
107 | | - summary += '- [Slither Documentation](https://github.com/crytic/slither) for more details\n\n'; |
108 | | - summary += '**To Suppress False Positives:**\n'; |
109 | | - summary += '```solidity\n// slither-disable-next-line detector-name\nfunction myFunction() public {\n // Code here won\'t trigger detector-name\n}\n```\n'; |
110 | | - summary += 'See [SECURITY_CHECKLIST.md](/docs/SECURITY_CHECKLIST.md) for detailed suppression guidance.\n'; |
111 | | - |
112 | | - github.rest.issues.createComment({ |
113 | | - issue_number: context.issue.number, |
114 | | - owner: context.repo.owner, |
115 | | - repo: context.repo.repo, |
116 | | - body: summary |
117 | | - }); |
118 | | -
|
119 | | - # ====================================================================== |
120 | | - # BUILD STATUS REPORTING |
121 | | - # Explicit failure message for High/Medium findings |
122 | | - # ====================================================================== |
123 | | - - name: Report analysis status |
124 | | - if: always() |
125 | | - run: | |
126 | | - echo "📊 Slither Analysis Summary" |
127 | | - echo "====================================" |
128 | | - echo "" |
129 | | - echo "✓ Analysis completed" |
130 | | - echo " Severity Policy:" |
131 | | - echo " 🔴 High/Medium severity: BUILD FAILS" |
132 | | - echo " 🟡 Low/Informational: BUILD PASSES (warnings logged)" |
133 | | - echo "" |
134 | | - echo "📎 View full results:" |
135 | | - echo " 1. GitHub Security tab (SARIF report)" |
136 | | - echo " 2. PR comment (summary)" |
137 | | - echo " 3. Slither config: slither.config.json" |
138 | | - echo "" |
139 | | - echo "📝 For false positives:" |
140 | | - echo " See: docs/SECURITY_CHECKLIST.md (Triage & False Positives section)" |
141 | | - echo " Use: //slither-disable-next-line <detector>" |
142 | | - echo "" |
| 29 | + if git ls-files '*.sol' | grep -q .; then |
| 30 | + echo "Solidity files detected; Slither scanning is not configured for this repository layout." |
| 31 | + echo "Add Solidity contracts (or update this workflow) before enabling Slither." |
| 32 | + exit 1 |
| 33 | + fi |
143 | 34 |
|
144 | | - - name: Fail if High/Medium findings detected |
145 | | - if: failure() && steps.slither.outcome == 'failure' |
146 | | - run: | |
147 | | - echo "❌ Build blocked due to High/Medium severity findings" |
148 | | - echo "" |
149 | | - echo "💡 Next steps:" |
150 | | - echo "1. Review findings in GitHub Security tab" |
151 | | - echo "2. Either fix the vulnerability OR suppress if it's a false positive" |
152 | | - echo "3. For false positives, follow the process in docs/SECURITY_CHECKLIST.md" |
153 | | - echo "4. Leave an inline comment: //slither-disable-next-line <detector>" |
154 | | - exit 1 |
| 35 | + echo "No Solidity (.sol) files tracked in this repo — skipping Slither." |
0 commit comments