AiPBX

Spec 003: Reverse Proxy Architecture, Network Firewall Matrix & Cloudflare DNS-01 Validation


1. Problem & Goal (What & Why)

1.1 Problem Statement

Deploying AiPBX in modern enterprise infrastructure often requires running behind a front-facing reverse proxy (e.g. Nginx, Caddy, Traefik, HAProxy, or Apache) for TLS termination, shared public IP routing, or cloud edge security. However:

  1. VoIP vs Web Multiplexing Confusion: Administrators frequently attempt to proxy all traffic (including SIP and RTP) through HTTP reverse proxies, causing broken call signaling, one-way audio, and failed WebRTC calls.
  2. IP Spoofing & Brute-Force Vulnerability: Reading X-Forwarded-For without verifying whether the direct peer connection is a trusted reverse proxy allows external attackers to spoof client IPs and bypass rate limiters or trigger denial-of-service lockouts against arbitrary IPs.
  3. Internal Server SSL/TLS Barrier: Let’s Encrypt HTTP-01 validation requires public port 80 exposure. PBXs deployed on private LANs, behind restrictive firewalls, or without public DNS A records could not automatically obtain valid certificates, breaking remote WebRTC and TURNS.
  4. WebSocket & SSO Callback Breaks: Edge TLS termination (HTTP between proxy and AiPBX, HTTPS between client and proxy) failed to set secure cookies and broke OIDC/SAML OAuth redirect URIs.

1.2 Proposed Solution


2. User Stories & Acceptance Criteria (DoD)

User Stories

Acceptance Criteria (Definition of Done)


3. Technical Design (How)

3.1 Settings & Storage

Settings stored in sys_settings:

3.2 Spoof-Proof IP Resolution Algorithm

1. Get remote peer IP from $_SERVER['REMOTE_ADDR']
2. If proxy_enabled is false -> return remote peer IP
3. If remote peer IP is NOT in trusted_proxies -> return remote peer IP (prevent spoofing)
4. Parse X-Forwarded-For header from right to left:
   - For each candidate IP:
     - If candidate is untrusted -> return candidate (first untrusted client)
5. If all hops trusted -> fallback to X-Real-IP if valid, else remote peer IP

3.3 Network Ports Matrix & Firewall Architecture


4. Verification & Status