Internals: decision records
ADR-0022: Trusted proxies (X-Forwarded-For, PROXY protocol)
- Status: Accepted (2026-10-06)
Context
Behind a load balancer every connection comes from the balancer: per-source limits
(ADR-0013) would throttle all clients together, access logs and REMOTE_ADDR would show
the balancer. Client-supplied X-Forwarded-For must never be believed blindly.
Decision
server.trusted_proxies: CIDRs of peers allowed to report the client address. Reloadable.- Header mode (any listener): for requests whose TCP peer is trusted, the client is the
right-most
X-Forwarded-Forentry that is not itself a trusted proxy (entries further left may be forged by the client). The chain forwarded upstream is the received chain plus the peer. From untrusted peers the header is ignored and replaced. - PROXY protocol (
listener.proxy_protocol: true, requirestrusted_proxies): v1 and v2 headers, read before TLS/HTTP withinheader_read_timeout, never past the header. Peers outsidetrusted_proxiesare closed immediately (untrusted_proxy); missing or malformed headers close the connection (proxy_protocol). v1UNKNOWN, v2LOCALand non-TCP families keep the peer address. PROXY listeners admit connections per client after reading the header (the accept loop never waits). - The effective client address feeds the per-source request limiter, the access log,
RequestContext.remote_addr(PHPREMOTE_ADDR, Node/Python viaX-Forwarded-For) and diagnostics. Connections from trusted peers are exempt from the per-source connection limit (a balancer multiplexes many clients); their requests are limited per client. Forwarded(RFC 7239) is not parsed.
1.1: client_address
Status: Accepted (2026-11-14). Adds vendor presets and more headers; nothing above changes.
server.client_addresshasheader(x-forwarded-fordefault,forwarded,cf-connecting-ip,x-real-ip,true-client-ip),presets(cloudflarein 1.1),presets_dirandfile. The header follows the trusted group of the peer:trusted_proxiesuseheader, a preset uses its vendor’s header. A peer outside both is the client whatever it sends.- A peer in
trusted_proxiesand in a preset belongs totrusted_proxies(explicit wins). - Walking
X-Forwarded-FororForwarded: a hop intrusted_proxiesis skipped and the walk continues. The walk ends at an address trusted only through a preset (a vendor edge the operator’s hop appended): the client is the one address in the vendor’s single-value header (CF-Connecting-IP, ruling 3), else the edge itself, never an entry left of the edge (changed after audit run-7 N1; it was a one-step hop whose left entry was the client). A source inside the vendor’s ranges (a Cloudflare Worker) connecting to the load balancer directly writes those entries itself; the vendor header is read before the scrub removes it from the balancer’s request (ruling 7). - Single-value headers: absent means the peer is the client; exactly one line with one bare
address is that address; anything else is the unknown client
::. Forwardedis parsed (for=only, strict RFC 7239). Only the right-most element of the last line is read on its own, so a client cannot hide the element the proxy appended. At most 32 entries are examined. The proxy must quote and escape client-derived parameters or omit them;X-Forwarded-Foris the safer choice. Upstream, ScalWS sends onlyX-Forwarded-For, starting at the resolved client (::when unknown).- Single-value headers are removed from requests of peers not trusted for them; their
underscore spellings (
cf_connecting_ip) are removed from every peer, since CGI-style stacks behind a proxy route map them to the same variable (ScalWS’s own PHP runtime already drops underscored names). - PROXY protocol stays limited to
trusted_proxies. Preset peers and imported networks are exempt from per-source connection and handshake limits like trusted proxies; the cost is that a client coming through such a network (a Cloudflare Worker) has no per-source connection limit. - The preset list ships with the release.
scalwsctl client-address update(root, TLS, strict validation,--forceskips only the coverage check, a failed fetch keeps the old list) writespresets_dir, which must be root-owned, not a link and not group or other writable, as must the file; otherwise the shipped list is used with a warning. No refresh timer in 1.1. - Panel mode reads
mod_remoteip(cPanel, DirectAdmin) and nginxreal_ip(DirectAdmin) and writes/etc/scalws/panel/client-address.yaml, merged throughclient_address.file: lists are unioned, the file’s header applies only when the operator set neitherheadernortrusted_proxies, and the file is checked like a site file on every load.RemoteIPHeader CF-Connecting-IPwith Cloudflare networks becomes the preset; other proxies go totrusted_proxies; per-site settings,Include, host names, loopback and special-purpose ranges are not carried over.