Skip to content

feat(webui): opt-in CF-Connecting-IP for login limits behind a local cloudflared - #187

Open
gerarecipe wants to merge 1 commit into
jasonxu114514:mainfrom
gerarecipe:cloudflare-client-ip
Open

gerarecipe wants to merge 1 commit into
jasonxu114514:mainfrom
gerarecipe:cloudflare-client-ip

Conversation

@gerarecipe

Copy link
Copy Markdown

Problem

Behind a reverse proxy every visitor shares the proxy's address — the README says so. For the login limit (5 failures per 5 minutes per client) that makes the limit global: anyone who can reach the login page can keep the operator locked out with one wrong password a minute. A common way to expose the WebUI is a cloudflared tunnel on the same host, where every request arrives from 127.0.0.1.

Change

New opt-in flag -trust-cloudflare-client-ip (default false, current behavior unchanged):

  • The client address for the login and Playground limits and the auth audit logs is taken from CF-Connecting-IP, only when the direct peer is a loopback address. Cloudflare's edge overwrites that header, so a remote visitor cannot choose it; a remote peer is never trusted, whatever it sends.
  • Missing, repeated, comma-separated, zoned or malformed values fall back to the peer address (the shared bucket) — stricter, never looser.
  • IPv6 clients share one limit per /64, so rotating addresses inside one allocation does not reset the counter. Logs keep the full address.
  • X-Forwarded-For stays untrusted. The global concurrent password-check cap is unchanged.

clientIP becomes a Server method in a new internal/admin/client_ip.go; call sites are otherwise unchanged. READMEs and management guides (EN/中文/VI/IT) describe the flag and say not to enable it for other reverse proxies.

Verification

  • gofmt -l ., go vet ./..., Linux and Windows builds: clean.
  • Throwaway tests (not committed; the repository has no _test.go files) against the real handler on loopback with synthetic credentials: header parsing table (loopback v4/v6, mapped v4, spoofing from a remote peer, missing/garbage/list/repeated/zoned values), IPv6 /64 grouping, and the end-to-end case — without the flag, five failures from one visitor make the operator's correct login return 429; with the flag the attacker gets 429 and the operator 200. Happy to add the tests if wanted.

🤖 Generated with Claude Code

…cloudflared

Behind a reverse proxy every visitor shares the proxy's address, so the
per-client login limit (5 failures per 5 minutes) becomes global: anyone
on the internet can keep the operator locked out of the WebUI with one
wrong password a minute.

-trust-cloudflare-client-ip (off by default) takes the client address for
the login and Playground limits and the audit logs from CF-Connecting-IP,
but only when the direct peer is a loopback address (a cloudflared
connector on the same host). Cloudflare's edge overwrites that header, so
remote visitors cannot choose it; a remote peer is never trusted. Missing,
repeated, comma-separated, zoned or malformed values fall back to the peer
address, which is stricter, not looser. IPv6 clients share one limit per
/64 so rotating addresses inside one allocation does not reset it.
X-Forwarded-For stays untrusted. READMEs and management guides (all four
languages) describe the flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant