๐ก๏ธ Solana Smart Contract Security Toolkit (solsec)
A comprehensive security analysis tool for Solana smart contracts that helps developers identify vulnerabilities before deployment through static analysis and fuzz testing.
โจ Features
- Static Analysis: Detect common vulnerabilities in Anchor and native Rust programs
- Fuzz Testing: Auto-generate fuzzing harnesses from IDL files
- Multiple Report Formats: JSON, HTML, Markdown, and CSV outputs
- Plugin System: Extensible architecture for custom security rules
- CI/CD Integration: GitHub Actions support with automated security checks
- Professional Reports: HTML reports with severity rankings and actionable recommendations
- Smart Error Handling: Clear, colored error messages with proper path validation
- Comprehensive Examples: 8 educational examples demonstrating vulnerabilities and secure patterns
๐ Quick Start
Installation
From Crates.io (Recommended)
From Source
Basic Usage
# Scan the current project and generates both JSON and HTML
# Scan a specific Solana program and set an output directory
# Generate only JSON
# Generate only HTML
# Generate multiple formats at once
# Don't open browser automatically
# Run fuzz testing
๐ Commands
solsec scan
Run static analysis on your Solana smart contracts. Generates both JSON and HTML by default. If no path is provided, it recursively scans the current directory for all .rs files, automatically ignoring target/ and .git/ folders.
HTML reports automatically open in the default browser when running interactively, but remain closed in CI/automation environments.
)
# Generate all available formats
# Scan with configuration file
solsec fuzz
Run fuzz testing on smart contracts.
solsec plugin
Manage security rule plugins.
๐ง Configuration
Create a solsec.toml configuration file:
# Enable/disable specific rules
= [
"integer_overflow",
"missing_signer_check",
"unchecked_account",
"reentrancy"
]
= []
# Rule-specific settings
[]
[]
= ["test_*", "mock_*"]
[]
= ["transfer", "withdraw"]
๐ Built-in Security Rules
| Rule | Severity | Description |
|---|---|---|
integer_overflow |
Medium | Detects potential integer overflow vulnerabilities |
missing_signer_check |
High | Identifies missing signer validation in instruction handlers |
unchecked_account |
Critical | Finds accounts used without proper validation |
reentrancy |
High | Detects potential reentrancy vulnerabilities |
๐ Plugin Development
Create custom security rules by implementing the Rule trait:
use ;
use Path;
use Result;
;
// Plugin interface
pub extern "C"
pub extern "C"
Build your plugin as a dynamic library:
๐ค CI/CD Integration
GitHub Actions
Add the following to your .github/workflows/security.yml:
name: Security Scan
on:
push:
branches:
pull_request:
branches:
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install solsec
run: |
curl -L https://github.com/hasip-timurtas/solsec/releases/latest/download/solsec-linux-x86_64.tar.gz | tar xz
sudo mv solsec /usr/local/bin/
- name: Run security scan
run: |
solsec scan ./programs --output ./security-results
- name: Upload security report
uses: actions/upload-artifact@v3
with:
name: security-report
path: ./security-results/
- name: Fail on critical issues
run: |
if [ -f ./security-results/*.json ]; then
critical_count=$(jq '[.[] | select(.severity == "critical")] | length' ./security-results/*.json)
if [ "$critical_count" -gt 0 ]; then
echo "โ Critical security issues found!"
exit 1
fi
fi
Pre-commit Hook
#!/bin/sh
# .git/hooks/pre-commit
if [; then
critical_count=
if [; then
fi
fi
Browser Opening Behavior
HTML reports automatically open in the default browser under the following conditions:
Opens automatically when:
- Running in an interactive terminal (not redirected)
- Generating HTML reports (
--html-onlyor default formats) - Not in CI/automation environments
Remains closed when:
- Running in CI environments (GitHub Actions, GitLab CI, etc.)
- Output is redirected or piped
- Using
--no-openflag - Only generating non-visual formats (JSON, CSV)
๐ Report Examples
HTML Report
Interactive HTML reports with:
- Executive summary with issue counts by severity
- Detailed findings with code snippets
- Actionable recommendations
- Responsive design for all devices
JSON Report
Machine-readable format for:
- CI/CD pipeline integration
- Custom tooling and analysis
- Data processing and metrics
Markdown Report
Developer-friendly format for:
- README documentation
- Pull request comments
- Documentation sites
๐ ๏ธ Development
Building from Source
Running Tests
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Examples
The examples/ directory contains comprehensive security vulnerability demonstrations:
๐จ Vulnerability Examples
Each category includes both vulnerable and secure implementations for educational purposes:
| Vulnerability Type | Severity | Vulnerable Examples | Secure Examples |
|---|---|---|---|
| Integer Overflow | Medium | examples/integer_overflow/vulnerable.rs |
examples/integer_overflow/secure.rs |
| Missing Signer Check | High | examples/missing_signer_check/vulnerable.rs |
examples/missing_signer_check/secure.rs |
| Unchecked Account | Critical | examples/unchecked_account/vulnerable.rs |
examples/unchecked_account/secure.rs |
| Reentrancy | High | examples/reentrancy/vulnerable.rs |
examples/reentrancy/secure.rs |
๐งช Testing the Examples
# Test vulnerable examples (should find many issues)
# Test secure examples (should find 0 issues)
# Comprehensive analysis
๐ Learning Resources
- Side-by-side Comparisons: See exactly how to fix each vulnerability
- Real-world Patterns: Actual Solana/Anchor code patterns
- Educational Comments: Clear explanations of security issues
- Test Suite: Validate that solsec detection works correctly
See the detailed examples/README.md for complete documentation.
๐ค Community
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Discord: Solana Security Community
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- The Solana Foundation for supporting security tooling
- The Rust security community for best practices
- Contributors and early adopters
โ ๏ธ Important: This tool helps identify potential security issues but does not guarantee complete security. Always conduct thorough testing and consider professional security audits for production applications.
Built with โค๏ธ by Hasip Timurtas