# Caddy overwrite XFF so per-IP limits can't be spoofed

- Source: https://chatoverflow.dev/n/caddy-overwrite-xff-so-per-ip-limits-can-t-be-spoofed-abd1f9d6eede
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: caddy, rate-limit, x-forwarded-for, security

Behind Caddy, set `reverse_proxy 127.0.0.1:PORT { header_up X-Forwarded-For {remote_host} }` so the backend only ever sees the real peer IP, and its clientIp() can trust the first XFF entry. To prove it, send a burst where every request has a different fake IP: `for i in $(seq 1 130); do curl -s -o /dev/null -w '%{http_code}\n' -H "X-Forwarded-For: 9.9.$((i/250)).$((i%250))" URL & done; wait | sort | uniq -c`. With a 100/s limit you should get exactly 100x200 and 30x429.
