Overview
The Firewall API allows you to manage an IP allowlist for restricting access to proxy endpoints. When the allowlist is active (contains at least one IP), only requests from listed IPs can access the proxy routes.Dashboard endpoints (
/api/*) are never restricted by the firewall. Only proxy endpoints are affected.Protected Endpoints
The firewall protects these proxy-facing paths:/v1/*- OpenAI-compatible API endpoints/backend-api/codex/*- Codex-specific endpoints/backend-api/transcribe- Audio transcription endpoint
List Firewall IPs
Retrieve the current firewall mode and all allowed IP addresses.
Response
Current firewall mode:
allow_all: Allowlist is empty, all IPs are permittedallowlist_active: Allowlist is active, only listed IPs are permitted
Array of allowed IP addresses
Example Request
Example Response - Allow All Mode
Example Response - Allowlist Active
Add IP to Allowlist
Add an IP address to the allowlist. The firewall automatically activates when the first IP is added.
Request Body
IP address to allow (IPv4 or IPv6 format)
Response
Returns the created firewall entry.The normalized IP address
Timestamp when the IP was added
Example Request - IPv4
Example Request - IPv6
Example Response
Error Responses
invalid_ip: The provided IP address format is invalid
ip_exists: This IP address is already in the allowlist
Remove IP from Allowlist
Remove an IP address from the allowlist. When the last IP is removed, the firewall returns to
allow_all mode.Path Parameters
The IP address to remove (URL-encoded if necessary)
Response
Always returns “deleted” on success
Example Request
Example Request - IPv6 (URL-encoded)
Example Response
Error Responses
invalid_ip: The provided IP address format is invalid
ip_not_found: The specified IP address is not in the allowlist
Firewall Behavior
Allow All Mode (Default)
When the allowlist is empty:mode: "allow_all"- All client IPs can access proxy endpoints
- Dashboard endpoints remain accessible
- No IP validation is performed
Allowlist Active Mode
When one or more IPs are in the allowlist:mode: "allowlist_active"- Only listed IPs can access proxy endpoints
- Unlisted IPs receive 403 Forbidden
- Dashboard endpoints remain accessible from any IP
Blocked Request Response
When a request from an unlisted IP is blocked:Trusted Proxy Configuration
If Codex-LB is behind a reverse proxy (nginx, Cloudflare, etc.), configure trusted proxy headers to ensure correct IP resolution.
Environment Variables
Header Resolution Logic
WhenFIREWALL_TRUST_PROXY_HEADERS=true:
- Check if request source IP matches a trusted CIDR
- If trusted, extract client IP from
X-Forwarded-Forheader (first valid IP) - If untrusted or header missing, use source socket IP
Example Scenarios
- Direct Connection
- Trusted Proxy
- Untrusted Proxy
Use Cases
Corporate Network
Restrict proxy access to your company’s public IP ranges.
CI/CD Pipeline
Allow only your build servers to access the API for automated testing.
Development
Permit specific developer IPs during initial deployment.
Partner Access
Grant proxy access to trusted partner organizations’ IP ranges.
Best Practices
1. Start with Dashboard-Only Access
During initial setup:- Add your admin IP to the allowlist
- Test dashboard access (should always work)
- Test proxy access from your IP (should work)
- Test proxy access from another IP (should be blocked)
2. Use CIDR Notation
For IP ranges, you can add individual IPs or configure your reverse proxy to handle CIDR ranges upstream.3. Monitor Blocked Requests
Check request logs forip_forbidden errors to identify legitimate users being blocked:
4. Coordinate with Network Team
Before enabling the firewall in production:- Document all allowed IP ranges
- Get confirmation from network team on static IPs
- Plan for IP changes (ISP reassignments, office moves)
5. Emergency Access
If you lock yourself out:- SSH into the server
- Access the database directly
- Clear the
firewall_ipstable:DELETE FROM firewall_ips; - The firewall returns to
allow_allmode
Authentication
All firewall management endpoints require dashboard authentication via session cookie. The firewall enforcement itself is separate from authentication - it operates at the network layer.Common Error Codes
| Code | Description |
|---|---|
invalid_ip | IP address format validation failed |
ip_exists | Attempted to add a duplicate IP |
ip_not_found | Attempted to remove an IP that isn’t in the allowlist |
ip_forbidden | Client IP not in allowlist (returned to blocked proxy requests) |