Self-hosted Web Application Firewall built in Rust
Rust • Async I/O • OWASP Top 10 • Prometheus • Grafana
WAF is an open-source Web Application Firewall designed for teams who want visibility and control over their traffic filtering logic. It runs as a self-hosted reverse proxy, intercepting requests before they reach your application.
What WAF provides:
- Protection against OWASP Top 10 attacks (SQL injection, XSS, CSRF, path traversal, command injection, etc.)
- Configurable rule engine with YAML-based rule definitions
- Multiple rate limiting algorithms with distributed state via Redis
- Bot detection with fingerprinting and challenge mechanisms
- Prometheus metrics and Grafana dashboards for observability
- Hot reload for rules without service interruption
What WAF is:
- A rule-based request filter that you operate and maintain
- A Rust application optimized for high-throughput, low-latency filtering
- A solution for teams with the expertise to deploy and manage infrastructure
What WAF is not:
- A turnkey security solution requiring no operational expertise
- A replacement for comprehensive application security practices
- A service with SLA guarantees or vendor support
| Feature | Description |
|---|---|
| OWASP Top 10 Protection | Detection rules for SQL injection, XSS, CSRF, path traversal, command injection, XXE, LFI, RFI, LDAP injection |
| Bot Detection | Client fingerprinting, IP reputation, JavaScript challenges, CAPTCHA integration |
| Rate Limiting | Token bucket, sliding window, leaky bucket algorithms; Redis-backed for distributed deployments |
| Bypass Prevention | Encoding detection, case normalization, null byte handling |
| Feature | Description |
|---|---|
| Rust Runtime | Memory-safe, zero-cost abstractions |
| Async I/O | Non-blocking request handling via Tokio |
| Connection Pooling | Keep-alive connections to upstream servers |
| Hot Reload | Rule updates without dropping active connections |
| Feature | Description |
|---|---|
| Prometheus Metrics | Request counts, latency histograms, attack detection rates |
| Grafana Dashboards | Pre-built dashboards for real-time monitoring |
| Structured Logging | JSON-formatted logs for ELK/Splunk integration |
| Admin API | RESTful interface for rule management and statistics |
┌─────────────────────────────────────────────────────────────────┐
│ Client Request │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ waf-core (Proxy) │
│ ┌─────────────┐ ┌──────────────┐ ┌────────────────────────┐ │
│ │ TLS Handler │→ │ Bot Detector │→ │ Rate Limiter │ │
│ └─────────────┘ └──────────────┘ └────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┤
│ │ waf-engine (Detection) │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ SQLi │ │ XSS │ │ CSRF │ │ More │ ... │ │
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
│ └─────────────────────────────────────────────────────────────┤
│ │ │
│ ▼ │
│ Allow or Block │
└─────────────────────────────────────────────────────────────────┘
│
▼ (if allowed)
┌─────────────────────────────────────────────────────────────────┐
│ Upstream Server │
└─────────────────────────────────────────────────────────────────┘
| Crate | Purpose |
|---|---|
waf-common |
Shared types, configuration structures, error handling |
waf-engine |
Rule matching engine and attack detectors |
waf-rate-limiter |
Rate limiting algorithms (token bucket, sliding window, leaky bucket) |
waf-bot-detector |
Client fingerprinting, reputation database, challenge system |
waf-core |
HTTP proxy server with TLS termination |
waf-admin |
REST API for management operations |
waf-dashboard |
React-based admin dashboard |
git clone https://github.com/kuro-toji/waf.git
cd waf
# Start WAF with Prometheus, Grafana, and Redis
docker-compose up -d
# Verify services are running
docker-compose ps
# View WAF logs
docker-compose logs -f waf-core
# Access Grafana dashboard
open http://localhost:3000# Install Rust 1.75+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Build release binaries
cargo build --release
# Run with configuration file
./target/release/waf-core --config config/waf.yamlRules are defined in YAML with conditions and actions:
rules:
- id: sqli-001
name: "SQL Injection Detection"
severity: critical
match:
type: regex
patterns:
- "(?i)(union.*select|select.*from|insert.*into|delete.*from|drop.*table)"
- "(?i)(or\\s+1\\s*=\\s*1|and\\s+1\\s*=\\s*1|'\\s*or\\s*')"
- "--|\\/\\*|\\*\\/"
action: block
reason: "SQL injection attempt detected"server:
host: "0.0.0.0"
port: 8080
upstream_url: "http://localhost:3000"
rules:
path: "./rules"
severity_threshold: medium
rate_limiter:
enabled: true
algorithm: token_bucket
requests_per_second: 100
burst: 200
redis:
enabled: true
url: "redis://localhost:6379"| Method | Endpoint | Description |
|---|---|---|
GET |
/api/rules |
List all rules |
POST |
/api/rules |
Create a new rule |
GET |
/api/rules/{id} |
Get rule by ID |
PUT |
/api/rules/{id} |
Update rule |
DELETE |
/api/rules/{id} |
Delete rule |
GET |
/api/stats |
Get statistics summary |
GET |
/api/stats/attacks |
Get attack type breakdown |
GET |
/api/logs |
Get attack logs (paginated) |
GET |
/api/config |
Get current configuration |
PUT |
/api/config |
Update configuration |
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Health check |
GET |
/ready |
Readiness probe with stats |
GET |
/metrics |
Prometheus metrics |
GET |
/_waf_challenge |
Bot challenge page |
WAF exposes Prometheus metrics at GET /metrics:
# Request counters
waf_requests_total{status="allowed"} 12345
waf_requests_total{status="blocked"} 67
# Latency histogram
waf_latency_seconds_bucket{le="0.01"} 10000
waf_latency_seconds_bucket{le="0.1"} 12000
waf_latency_seconds_bucket{le="1"} 12500
waf_latency_seconds_bucket{le="+Inf"} 12567
# Attack detection counter
waf_attacks_total{type="sqli"} 23
waf_attacks_total{type="xss"} 15
waf_attacks_total{type="path_traversal"} 8
# Rate limiter metrics
waf_rate_limit_exceeded_total{algorithm="token_bucket"} 42
# Build all workspace crates
cargo build --release
# Run tests
cargo test --workspace
# Run linter
cargo clippy --workspace -- -D warnings
# Format code
cargo fmt --all
# Run integration tests
cargo test --test integration_tests
# Development run with debug logging
RUST_LOG=debug ./target/release/waf-core --config config/waf.yamlhelm install waf ./helm/waf -n waf-system --create-namespacecd terraform/aws
terraform init
terraform plan
terraform applycd terraform/gcp
terraform init
terraform plan
terraform applyBefore deploying WAF in production, evaluate:
- Rule Tuning: Default rules may require adjustment for your application's traffic patterns
- Performance Testing: Benchmark against your actual request volume and latency requirements
- High Availability: Multiple WAF instances behind a load balancer with shared Redis state
- Monitoring: Set up alerts for attack spikes and rate limit occurrences
- Logging: Configure log rotation and storage capacity for attack logs
See docs/PRODUCTION_CHECKLIST.md for deployment guidance.
| Document | Content |
|---|---|
| ARCHITECTURE.md | System design and component interactions |
| ARCHITECTURE_DECISIONS.md | Design decisions and tradeoffs |
| RULES.md | Rule syntax and available match types |
| DEPLOYMENT.md | Deployment options and configuration |
| API.md | API endpoint reference |
| TROUBLESHOOTING.md | Common issues and solutions |
Contributions are welcome. Please review CONTRIBUTING.md for guidelines on code style, testing, and pull request process.
MIT License. See LICENSE for full license text.