π‘οΈ WiseGate
"You shall not pass!" - A wise guardian for your network gates.
An efficient, secure reverse proxy written in Rust with built-in rate limiting and IP filtering capabilities.
β¨ Features
- π Efficient & Compact: ~2.5MB binary, statically compiled
- π Rate Limiting: Per-IP sliding window algorithm
- π« IP Filtering: Block malicious IPs, validate proxy headers
- βοΈ HTTP Method Filtering: Block specific methods (PUT, DELETE, etc.)
- π‘οΈ URL Pattern Blocking: Block requests matching patterns (.php, .yaml, etc.)
- π Basic Authentication: RFC 7617 HTTP Basic Auth with multiple hash formats
- π« Bearer Token: RFC 6750 Bearer Token authentication
- π Real IP Extraction: RFC 7239 compliant header parsing
- π Structured Logging: Human-readable or JSON format
- π Graceful Shutdown: Drain connections on SIGINT/SIGTERM
- π Connection Limiting: Prevent resource exhaustion
π Quick Start
# Install
# Run (permissive mode)
# Run (strict mode with proxy validation)
βοΈ CLI Options
| Option | Short | Default | Description |
|---|---|---|---|
--listen |
-l |
8080 |
Port to listen on |
--forward |
-f |
9000 |
Port to forward to |
--bind |
-b |
0.0.0.0 |
Bind address |
--verbose |
-v |
Debug logging | |
--quiet |
-q |
Errors only | |
--json-logs |
JSON log format |
π§ Configuration
All configuration via environment variables:
| Variable | Default | Description |
|---|---|---|
CC_REVERSE_PROXY_IPS |
- | Trusted proxy IPs (enables strict mode) |
TRUSTED_PROXY_IPS_VAR |
- | Alternative variable name for proxy IPs (whitelisted: TRUSTED_PROXY_IPS, REVERSE_PROXY_IPS, PROXY_ALLOWLIST, ALLOWED_PROXY_IPS, PROXY_IPS) |
BLOCKED_IPS |
- | Blocked client IPs |
BLOCKED_METHODS |
- | Blocked HTTP methods (returns 405) |
BLOCKED_PATTERNS |
- | Blocked URL patterns (returns 404) |
RATE_LIMIT_REQUESTS |
100 |
Max requests per window |
RATE_LIMIT_WINDOW_SECS |
60 |
Window duration in seconds |
RATE_LIMIT_CLEANUP_THRESHOLD |
10000 |
Entries before auto-cleanup (0 = disabled) |
RATE_LIMIT_CLEANUP_INTERVAL_SECS |
60 |
Min interval between cleanups in seconds |
PROXY_TIMEOUT_SECS |
30 |
Upstream request timeout |
MAX_BODY_SIZE_MB |
100 |
Max body size (0 = unlimited) |
MAX_CONNECTIONS |
10000 |
Max concurrent connections (0 = unlimited) |
CC_HTTP_BASIC_AUTH |
- | Basic auth credentials (username:password) |
CC_HTTP_BASIC_AUTH_N |
- | Additional credentials (_1, _2, etc.) |
CC_HTTP_BASIC_AUTH_REALM |
WiseGate |
Authentication realm |
CC_BEARER_TOKEN |
- | Bearer token for API authentication |
π Example Configuration
π Security Modes
Strict Mode (CC_REVERSE_PROXY_IPS set)
- β
Validates
x-forwarded-forandforwardedheaders - β Authenticates proxy IPs against allowlist
- β Full IP filtering and rate limiting
- β
Injects
X-Real-IPheader
Permissive Mode (no proxy IPs)
- β Best-effort IP extraction from headers
- β Method and pattern filtering still active
- β Rate limiting when IP is available
β οΈ Permissive mode trusts client-supplied
X-Forwarded-For/Forwardedheaders verbatim. An attacker who can reach WiseGate directly can spoof their apparent IP by forging them. Use permissive mode only when WiseGate sits behind another reverse proxy that strips or normalises these headers, or when IP attribution is not a security boundary.
π Authentication
WiseGate supports two authentication methods that can be used independently or together.
Basic Authentication (RFC 7617)
# Plain text (not recommended for production)
# bcrypt (recommended)
# APR1 MD5 (htpasswd -m)
# SHA1 (htpasswd -s)
# Multiple users
# Custom realm
Generate password hashes with htpasswd:
Bearer Token (RFC 6750)
# Set bearer token
# Use with curl
Combined Authentication
When both Basic Auth and Bearer Token are configured, either method will be accepted:
# Configure both methods
# Both of these will work:
π Request Flow
Client β Load Balancer β π§ββοΈ WiseGate β Your Service
β
ββ π Check connection limit
ββ π Validate proxy headers + Extract client IP
ββ π« Check IP blocklist
ββ πΊοΈ Check URL patterns
ββ βοΈ Check HTTP method
ββ π Verify Authentication (if enabled)
ββ β±οΈ Apply rate limiting
ββ π Forward with X-Real-IP
π Logging
# Human-readable (default)
# JSON format (for log aggregation)
# Debug level
# Via RUST_LOG
RUST_LOG=debug
π¦ Using as a Library
WiseGate's core functionality is available as a separate crate wisegate-core for integration into your own projects:
[]
= "0.12"
The fastest path is DefaultConfig β it implements every configuration trait and exposes plain public fields you can tweak:
use Arc;
use Duration;
use ;
let mut config = default;
config.rate_limit.max_requests = 200;
config.rate_limit.window_duration = from_secs;
config.blocked_methods = vec!;
let limiter = new;
let config = new;
// Helpers used inside the pipeline are also available directly
let _blocked = is_ip_blocked;
let _allowed = check_rate_limit.await;
When you need finer control, implement the composable traits yourself (RateLimitingProvider, ProxyProvider, FilteringProvider, ConnectionProvider, AuthenticationProvider). The blanket impl turns any type that implements all five into a ConfigProvider β see the wisegate_core::types rustdoc for a worked example.
To proxy real HTTP traffic, call request_handler::handle_request from inside a Tokio runtime with a shared reqwest::Client:
use Arc;
use ;
async
π οΈ Development
π License
Apache License 2.0 - see LICENSE.
Made with β€οΈ and ancient wisdom β‘ for the Open Source Community
"All we have to decide is what to do with the traffic that is given to us."