English summary: A complete guide to automating smart contract security scanning in GitHub Actions. Covers setting up Slither checks on every PR, blocking deployments on critical findings, generating scan reports as PR comments, and integrating ContractScan for unified multi-engine analysis.
"배포 전에 스캔하면 되지 않나?" — 그 생각이 문제입니다
보안 검사를 배포 직전에 한 번만 실행하면 이런 문제가 생깁니다:
- 개발 막판에 취약점 발견 → 수정 비용 폭증
- 코드 리뷰에서 보안 이슈를 사람이 잡아야 함
- "빠른 픽스"라는 이유로 보안 스캔 건너뜀
- 취약점이 메인 브랜치에 병합됨
CI/CD에 보안 스캔을 통합하면 모든 PR에서 자동으로 취약점을 탐지하고, 심각한 이슈가 있으면 머지를 차단합니다.
기본 설정: Slither를 모든 PR에 적용
폴더 구조 가정
my-defi-project/
├── contracts/
│ ├── Token.sol
│ └── Vault.sol
├── hardhat.config.js
└── .github/
└── workflows/
└── security.yml
기본 워크플로우
# .github/workflows/security.yml
name: Smart Contract Security Scan
on:
pull_request:
paths:
- 'contracts/**/*.sol' # Solidity 파일 변경 시만 실행
jobs:
slither:
name: Slither Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Slither
uses: crytic/slither-action@v0.4.0
id: slither
with:
target: contracts/
slither-args: '--filter-paths node_modules'
fail-on: high # high 이상 발견 시 CI 실패
- name: Upload SARIF
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
이 설정으로:
- contracts/ 폴더에 변경이 있는 모든 PR에서 자동 실행
- HIGH 이상 심각도의 취약점 발견 시 체크 실패 (머지 차단 가능)
- GitHub Security 탭에 결과 자동 업로드
고급 설정: 다중 엔진 + PR 코멘트
ContractScan GitHub Action 통합
# .github/workflows/security-full.yml
name: Full Security Scan
on:
pull_request:
paths:
- 'contracts/**'
jobs:
security-scan:
name: ContractScan Analysis
runs-on: ubuntu-latest
permissions:
pull-requests: write # PR 코멘트 작성 권한
steps:
- uses: actions/checkout@v4
- name: Run ContractScan
uses: contractscan/action@v1
id: scan
with:
path: contracts/
fail-on: high
comment-on-pr: true # PR에 결과 자동 코멘트
- name: Security Gate
if: steps.scan.outputs.critical-count > 0
run: |
echo "❌ Critical vulnerabilities found. Blocking merge."
exit 1
PR 코멘트 자동 생성 예시:
## ContractScan Security Report
🔴 **1 Critical** | 🟠 **2 High** | 🟡 **3 Medium**
### Critical Issues
**[SWC-107] Reentrancy in Vault.withdraw()**
- File: `contracts/Vault.sol:45`
- The contract state is changed after an external call.
- Fix: Apply Checks-Effects-Interactions pattern
---
Full report: [View on ContractScan](https://contract-scanner.raccoonworld.xyz/report/...)
브랜치 보호 규칙 설정
GitHub Settings → Branches → Branch protection rules에서:
main/master브랜치 선택- Require status checks to pass before merging 활성화
Slither Analysis또는ContractScan Analysis체크 추가- Require branches to be up to date 활성화
이제 보안 스캔이 통과하지 않으면 PR 머지가 차단됩니다.
실용적인 심각도 정책
모든 이슈에서 CI를 실패시키면 너무 많은 false positive로 개발이 막힙니다. 권장 정책:
# 환경별 다른 기준 적용
jobs:
security-scan:
strategy:
matrix:
include:
- branch: main
fail-on: high # main 브랜치: high 이상 차단
- branch: develop
fail-on: critical # develop: critical만 차단
또는 특정 이슈를 허용목록에 추가:
- name: Run Slither
uses: crytic/slither-action@v0.4.0
with:
slither-args: >
--exclude-informational
--exclude-low
--filter-paths "node_modules,test"
Hardhat / Foundry 프로젝트 통합
Hardhat 프로젝트
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- name: Compile contracts
run: npx hardhat compile
- name: Run Slither
uses: crytic/slither-action@v0.4.0
with:
node-version: '20'
hardhat: true
Foundry 프로젝트
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Build
run: forge build
- name: Run Slither
uses: crytic/slither-action@v0.4.0
with:
foundry: true
전체 DevSecOps 파이프라인
개발자 커밋
↓
[PR 오픈]
↓
GitHub Actions 트리거
├── Slither 정적 분석 (30초)
├── Semgrep 패턴 검사 (20초)
└── AI 취약점 분석 (60초)
↓
결과 PR 코멘트 자동 게시
↓
심각도 게이트 평가
CRITICAL/HIGH → ❌ 머지 차단
MEDIUM/LOW → ⚠️ 경고만
↓
[코드 리뷰 + 수정]
↓
보안 스캔 통과
↓
[배포 전 최종 검토]
↓
메인넷 배포
비용: 완전 무료로 시작
- GitHub Actions: 공개 레포 무료, 비공개 레포 월 2,000분 무료
- Slither: 오픈소스, 무료
- ContractScan 무료 티어: 세션당 3회 스캔, 가입 불필요
팀이 커지거나 스캔 횟수가 늘어나면 유료 플랜을 검토하면 됩니다. 지금 당장은 0원으로 전체 파이프라인을 구축할 수 있습니다.
마치며: 보안은 자동화가 답이다
이 시리즈에서 다룬 내용을 정리합니다:
- 입문: 스마트 컨트랙트 보안의 왜 — 불변성, 직접 자산 제어
- Reentrancy: The DAO부터 Euler Finance까지, CEI 패턴과 ReentrancyGuard
- TOP 5 취약점: 접근 제어, 오버플로우, 오라클 조작, 플래시론, 프론트러닝
- 도구 비교: Slither vs Mythril vs Semgrep — 언제 무엇을 쓸까
- CI/CD 자동화: 이 편 — GitHub Actions로 보안을 파이프라인에
코드 한 줄 배포 전에 contract-scanner.raccoonworld.xyz에서 무료 스캔을 실행해보세요. 5분이 수억 원을 지킬 수 있습니다.