fix(gateway): don't let clients pick their IP behind TRUST_PROXY

TRUST_PROXY=1 trusted CF-Connecting-IP and the first X-Forwarded-For
entry, both of which a client can send itself when the proxy in front
isn't Cloudflare (nginx's $proxy_add_x_forwarded_for only appends), so
per-IP limits could be sidestepped. Now TRUST_PROXY=1 takes the last
X-Forwarded-For entry (the one the proxy appended), and the new
TRUST_PROXY=cloudflare takes only CF-Connecting-IP. The bundled compose
file (cloudflared) switches to cloudflare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-10-05 18:31:13 +00:00
1 parent bda908029b
commit bbb44b3eaa
3 files changed
+16 -14

No files matched your search

+3 -2
View File
@@ -9,8 +9,9 @@ services:
# This file publishes no port - the gateway is only reachable through
# the cloudflared tunnel below, so the client IP it forwards can be
# trusted (per-IP limits would otherwise see every user as the tunnel).
# Remove this if you publish a port directly instead.
- TRUST_PROXY=1
# Remove this if you publish a port directly instead; behind your own
# reverse proxy use TRUST_PROXY=1.
- TRUST_PROXY=cloudflare
# Nothing in here needs Linux capabilities (unprivileged port, plain
# TCP/UDP sockets), so drop them all.
cap_drop: [ALL]