/v1/* and /backend-api/codex/*).
How It Works
The firewall operates in two modes:Allow All
Default mode. No restrictions—any IP can access the API.Active when the firewall allowlist is empty.
Allowlist Active
Restricted mode. Only IPs in the allowlist can access protected endpoints.Activated automatically when you add at least one IP to the allowlist.
Protected Endpoints
The firewall only protects API proxy endpoints:/v1and/v1/*(OpenAI-compatible API)/backend-api/codexand/backend-api/codex/*(Codex CLI API)
/api/*(dashboard API)/auth/*(OAuth callbacks)/(dashboard frontend)
Configuration
Environment Variables
Trust
X-Forwarded-For headers for client IP detection.When to enable:- Codex-LB is behind nginx/Caddy/HAProxy/Traefik
- Codex-LB is behind Cloudflare or another CDN
- You need to see real client IPs in logs and firewall checks
- Codex-LB is directly exposed to the internet
- You don’t use a reverse proxy
Comma-separated list of CIDR ranges for trusted proxy sources.Only requests from these IPs will have their See Cloudflare IP Ranges for the full list.
X-Forwarded-For headers trusted. This prevents malicious clients from spoofing IPs.Examples:Managing the Allowlist
You can manage the IP allowlist through the dashboard or API.Dashboard
- Navigate to Settings → Firewall
- View current mode and allowed IPs
- Add or remove IPs as needed
API
List Allowed IPs
List Allowed IPs
Add an IP
Add an IP
IPs are automatically normalized. IPv6 addresses like
::ffff:127.0.0.1 are converted to 127.0.0.1.Remove an IP
Remove an IP
IP Detection Logic
Codex-LB resolves the client IP using the following logic:Without Proxy Headers Trust
With Proxy Headers Trust
X-Forwarded-For when the direct connection comes from a trusted proxy.
Deployment Examples
Direct Exposure (No Proxy)
Behind nginx (Local)
Behind Cloudflare
X-Forwarded-For header.
Docker Compose with nginx
Common Scenarios
Allow Only My Home IP
Allow Only My Home IP
203.0.113.42 can access the API.Allow My Office Network
Allow My Office Network
Allow Localhost Only
Allow Localhost Only
Temporarily Disable Firewall
Temporarily Disable Firewall
Error Messages
IP Forbidden
Invalid IP Address
203.0.113.42, IPv6: 2001:db8::1).
IP Already Exists
Security Best Practices
Use with API Keys
Combine firewall with API key authentication for defense in depth.
Limit Trusted Proxies
Only add CIDRs you control to
FIREWALL_TRUSTED_PROXY_CIDRS.Regular Audits
Periodically review the allowlist and remove stale IPs.
Monitor Logs
Watch for
ip_forbidden errors to detect unauthorized access attempts.Firewall vs Dashboard Auth
| Feature | Firewall | Dashboard Auth |
|---|---|---|
| Protects | API endpoints (/v1, /backend-api) | Dashboard UI (/, /api) |
| Method | IP allowlist | Password + TOTP |
| Granularity | Per IP | Per user |
| Overhead | Minimal | Session cookies |
Troubleshooting
Dashboard Accessible, API Blocked
Expected behavior. The dashboard (/api/*) is not protected by the firewall.
Add your IP to access API endpoints:
Real IP Not Detected Behind Proxy
Verify:FIREWALL_TRUST_PROXY_HEADERS=true- Proxy IP is in
FIREWALL_TRUSTED_PROXY_CIDRS - Proxy is sending
X-Forwarded-Forheader
Locked Out After Enabling Firewall
You can still access the dashboard athttp://localhost:2455 (firewall doesn’t protect dashboard routes).
- Go to Settings → Firewall
- Remove all IPs to disable allowlist mode
- Or add your current IP