Trusted Proxies

A reverse proxy connects to Atom on the browser's behalf. That connection can have a different IP address, scheme, or host from the original request. TrustedProxyMiddleware reads forwarding headers from a trusted proxy so the application can use the effective request values.

Registration

Add the middleware to the application's existing middlewares() hook. Register it before Trusted Hosts and other middleware that reads the effective client IP or HTTPS state.

app/Application.php (excerpt)
use Atom\Http\MiddlewareRegistry;
use Atom\Http\TrustedProxyMiddleware;

protected function middlewares(MiddlewareRegistry $middlewares): void
{
    $middlewares->add(TrustedProxyMiddleware::class);
}

Configuration

Set TRUSTED_PROXIES to the IP addresses or CIDR ranges of proxies that connect to Atom. For a reverse proxy running on the same machine over IPv4 loopback:

.env
TRUSTED_PROXIES=127.0.0.1

Use the address Atom sees for the proxy connection. List only proxy addresses or dedicated ranges you control. Configure those proxies to provide the forwarding headers. An empty list trusts no proxies.

Forwarded headers

Atom first checks the immediate network peer against TRUSTED_PROXIES. If the peer is trusted, Atom uses the values from Forwarded when present and falls back to the corresponding X-Forwarded-* header for each missing value. Requests from other peers keep their original connection values.

Value Forwarding headers Read it with
Client IP Forwarded: for or X-Forwarded-For $request->getClientIp()
Scheme Forwarded: proto or X-Forwarded-Proto $request->getScheme() or $request->isSecure()
Host Forwarded: host or X-Forwarded-Host $request->getHost()

Downstream middleware sees the normalized request. For example, after TLS terminates at the proxy, Atom can recognize the original HTTPS request when applying the session cookie policy or HSTS.