Overview
Coraza Proxy supports geographic blocking and allowlisting using the MaxMind GeoIP2 Country database. You can either block specific countries or create an allowlist of permitted countries.Environment Variables
Enable or disable GeoIP-based filtering. Must be set to
true to activate geolocation features.Comma-separated list of country codes (ISO 3166-1 alpha-2) to block.Example:
CN,RU,KPComma-separated list of country codes to allow. When set, all other countries are blocked.Example:
US,CA,GB,FR,DEHow It Works
Database Loading
The GeoIP database is loaded at startup if enabled (frommain.go:370-376):
main.go:264-271):
Country Code Lookup
Country codes are determined from IP addresses (frommain.go:273-283):
Configuration Parsing
Country lists are parsed from environment variables (frommain.go:285-294):
main.go:417-420):
Filtering Logic
The geo filtering function implements the allowlist/blocklist logic (frommain.go:296-315):
Request Handling
GeoIP filtering is applied early in the request pipeline (frommain.go:432-439):
Filtering Modes
Mode 1: Block Specific Countries
Block a list of countries while allowing all others:- If country is in blocklist → Block (403)
- Otherwise → Allow
Mode 2: Allow Only Specific Countries
Allow only a specific list of countries:- If country is in allowlist → Allow
- Otherwise → Block (403)
Mode 3: Combined (Allow Takes Precedence)
You can combine both, but the allowlist takes precedence:- Check blocklist first → If matched, block
- Check allowlist (if configured) → If not matched, block
- Otherwise → Allow
Country Codes
Use ISO 3166-1 alpha-2 country codes. Common examples:| Code | Country |
|---|---|
| US | United States |
| CA | Canada |
| GB | United Kingdom |
| FR | France |
| DE | Germany |
| CN | China |
| RU | Russia |
| JP | Japan |
| AU | Australia |
| BR | Brazil |
| IN | India |
| KP | North Korea |
| IR | Iran |
Configuration Examples
Block High-Risk Countries
Allow Only North America
Allow Only Europe
Block Specific Regions
Docker Setup
The GeoIP database must be mounted into the container:Obtaining the GeoIP Database
MaxMind GeoLite2 (Free)
- Sign up for a free account at MaxMind
- Download the GeoLite2 Country database (MMDB format)
- Extract
GeoLite2-Country.mmdb - Mount it to
/app/GeoLite2-Country.mmdbin the container
Commercial Database
For more accurate data, use MaxMind’s commercial GeoIP2 database:- Purchase GeoIP2 Country database
- Download and extract
- Use the same mount path
Response Format
When a request is blocked by GeoIP policy:Logging
GeoIP blocks are logged with details:Error Handling
Missing Database File
If the database file is missing whenGEO_BLOCK_ENABLED=true:
Invalid IP Address
If the IP cannot be parsed, the request is blocked:IP Not in Database
If the IP is not found in the database (e.g., private IPs), the lookup fails and the request is blocked by default.Behind Proxies
The GeoIP lookup uses the real client IP extracted from headers (see Rate Limiting for IP detection details):CF-Connecting-IP(Cloudflare)X-Forwarded-For(standard)
Performance Considerations
- The GeoIP database is loaded into memory once at startup
- Lookups are extremely fast (microseconds)
- Negligible performance impact per request
- Database size: ~6 MB for GeoLite2-Country
Testing
Test GeoIP blocking with VPN or proxy services:Best Practices
- Use allowlist for critical apps: For sensitive applications, use
GEO_ALLOW_COUNTRIESto explicitly permit only trusted regions - Update database regularly: GeoLite2 should be updated monthly for accuracy
- Monitor logs: Review blocked requests to ensure legitimate users aren’t affected
- Combine with WAF: Use GeoIP as a first layer before WAF processing
- Test before production: Verify your country codes work as expected
- Consider false positives: VPNs and proxies can cause misidentification
- Document your policy: Maintain a clear list of why countries are blocked/allowed
Limitations
- GeoIP databases are not 100% accurate
- VPNs and proxies can bypass geographic restrictions
- Private IP addresses (10.x.x.x, 192.168.x.x) cannot be geolocated
- Database must be updated regularly for accuracy
- No built-in automatic database updates (implement separately)
