Skip to content

Use the visitor's address behind a trusted reverse proxy - #63

Merged
rangoDJ merged 1 commit into
mainfrom
fix/client-ip-behind-proxy
Oct 10, 2026
Merged

rangoDJ merged 1 commit into
mainfrom
fix/client-ip-behind-proxy

Conversation

@rangoDJ

@rangoDJ rangoDJ commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Fixes #55

What changed

  • New TRUSTED_PROXIES setting (IPs/CIDRs, empty by default = unchanged behaviour).
  • client_ip(): when the peer nginx saw (X-Real-IP) is a trusted proxy, the visitor is the nearest X-Forwarded-For entry, read from the right, that isn't a trusted proxy. A visitor's forged entries sit to the left of what the proxy appends, so they're ignored. Used by the login/sign-up/password rate limiter and log messages.
  • peer_ip() (the old behaviour) is what the forward-auth check uses, so TRUSTED_PROXIES can never let a forwarded address pass as the forward-auth proxy.
  • README ("Behind a reverse proxy or tunnel") and docker-compose.yml document the setting.

Testing

  • pytest: 255 passed, 8 skipped. New tests: no trusted proxy → peer; behind a trusted tunnel → visitor, both with nginx's appended entry and as auth_request passes the header unchanged; a forged left-hand entry is ignored; a direct visitor can't claim another address; a chain of trusted proxies is skipped; a trusted proxy that forwards nothing → the proxy; forward auth rejects a request whose forwarded address, but not peer, is the forward-auth proxy.
  • Matches the live install behind cloudflared: all API requests arrive from 172.21.0.4, and cloudflared's X-Forwarded-For carries the visitor (uvicorn's own access log shows it for /auth/verify).
  • Not tested in a running container.

🤖 Generated with Claude Code

Behind a reverse proxy or tunnel every request reached ConnectHub from the
proxy's address, so all visitors shared one login rate limit (anyone's ten
wrong passwords locked everyone out) and logs showed the proxy. With the
proxy listed in the new TRUSTED_PROXIES setting, client_ip() takes the
nearest X-Forwarded-For entry that isn't a trusted proxy. The forward-auth
check keeps using the connecting peer.

Fixes #55

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rangoDJ
rangoDJ merged commit 87859fe into main Oct 10, 2026
4 checks passed
@rangoDJ
rangoDJ deleted the fix/client-ip-behind-proxy branch October 10, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behind a reverse proxy every visitor shares one login rate limit

1 participant