On this page
Why. Nine IP-keyed rate limiters (sign-in, webhooks, OAuth callback, DSAR, switch-org/brand…) key on the client IP.
App side — done, and hop-count-independent. Production runs
TRUSTED_PROXY_HOPS=0. The app resolves the connection peer from
X-Real-Ip, which Traefik always stamps with its immediate peer and which a
client cannot write; the leftmost X-Forwarded-For is used only where no proxy
stamped anything (dev / single-tier). A non-zero TRUSTED_PROXY_HOPS still means
what it always meant — read the Nth-from-the-right XFF entry — for a deployment
that declares its topology that way.
Cloudflare. The apex msocloud.net is fronted by Cloudflare; the wildcard
tenant hosts reach Traefik directly. On the apex the peer is a Cloudflare edge
address, so cf-connecting-ip is used instead — but only when the peer is
inside Cloudflare's published ranges, because a direct caller on a wildcard
host can set that header to anything. Ranges: a dated snapshot in
apps/web/src/server/middleware/cloudflare-ranges.ts; rotate without a deploy by
setting CLOUDFLARE_IP_RANGES (comma/whitespace-separated CIDRs) in .env.prod.
The Traefik side is belt-and-suspenders: Traefik overwrites inbound XFF so a spoofed
chain never reaches the app. Traefik lives in /opt/apps/balancer, shared
infrastructure serving other projects on this host, which is why this is a runbook
and not a change made from this repository.
1. Forwarded headers on the entrypoints#
The balancer configures Traefik with command flags in
/opt/apps/balancer/docker-compose.mso.yml (there is no traefik.yml). Neither
web nor websecure sets a forwardedHeaders flag, and Traefik's default is to trust
no inbound X-Forwarded-*, so it already replaces XFF with the real peer IP. Do not
add --entrypoints.<name>.forwardedheaders.trustedips: Cloudflare is not needed there,
because the app reads cf-connecting-ip only behind a verified Cloudflare peer, and
do not raise TRUSTED_PROXY_HOPS (a guessed value re-opens the forged-entry hole).
Verify: curl -H 'X-Forwarded-For: 1.2.3.4' https://<tenant-host>/api/health -sk -o /dev/null,
then check that the web container log's request IP is the real peer, not 1.2.3.4.
2. Rotate TRAEFIK_CONFIG_TOKEN#
The token authorizes Traefik's HTTP provider to read /api/edge/traefik-dynamic. The
balancer substitutes it from /opt/apps/balancer/.env.mso into the
--providers.http.headers.Authorization flag, so the expanded value is visible in the
container's args to anyone with docker socket access.
- Mint a new value:
openssl rand -base64 32. - Set it in this checkout's
.env.prod(TRAEFIK_CONFIG_TOKEN=...) and redeploy with./scripts/start-prod.sh; set the same value in/opt/apps/balancer/.env.mso. - Recreate Traefik:
docker compose -f /opt/apps/balancer/docker-compose.yml -f /opt/apps/balancer/docker-compose.mso.yml up -d traefik(affects every project behind it; do it in a quiet window). - Confirm the dynamic-config poll still returns 200: the Traefik log shows no
traefik-dynamicfetch errors and tenant hosts keep routing.
The old token dies when both sides restart; there is no dual-accept window, so do steps 2 and 3 back to back.
3. CSP#
Content-Security-Policy rollout, the violation sink and the edge check are in csp-nonce-rollout.md.