Skip to content

Only trust cf-connecting-ip when behind Cloudflare (fixes #510) - #511

Open
carfeii wants to merge 1 commit into
schlagmichdoch:masterfrom
carfeii:fix/cf-connecting-ip-trust-gate
Open

carfeii wants to merge 1 commit into
schlagmichdoch:masterfrom
carfeii:fix/cf-connecting-ip-trust-gate

Conversation

@carfeii

@carfeii carfeii commented Sep 11, 2026

Copy link
Copy Markdown

Fixes #510.

Problem

Peer._setIP (server/peer.js) checks cf-connecting-ip first and trusts it unconditionally. On any instance not behind Cloudflare that header is a plain client-supplied value, so a remote client can send cf-connecting-ip: <victim public IP> and be placed in that victim's IP auto-discovery room (_joinIpRoom -> _joinRoom(peer, 'ip', peer.ip)), crossing the intended same-network boundary.

The documented nginx reverse proxy overwrites only X-Forwarded-For (proxy_set_header X-Forwarded-for $remote_addr;), so it does not neutralize cf-connecting-ip, and _setIP checks that header first.

Change

Gate cf-connecting-ip behind a new CF_CONNECTING_IP option (default off):

  • server/index.js: conf.cfConnectingIp = process.env.CF_CONNECTING_IP === "true";
  • server/peer.js: only read cf-connecting-ip when this.conf.cfConnectingIp is set; otherwise fall back to x-forwarded-for (proxy-overwritten in the documented setup) or the socket address.

Operators genuinely behind Cloudflare set CF_CONNECTING_IP=true and keep the current behavior; all other deployments stop honoring the spoofable header.

Scope is limited to the cf-connecting-ip gap, since the documented $remote_addr overwrite already covers X-Forwarded-For.

Peer._setIP checked cf-connecting-ip first and trusted it
unconditionally. On any instance not behind Cloudflare that header is a
plain client-supplied value, so a remote client could send
cf-connecting-ip: <victim public IP> to join an arbitrary peer's IP
auto-discovery room. The documented nginx reverse proxy overwrites only
X-Forwarded-For, so it does not neutralize this header.

Gate cf-connecting-ip behind a new CF_CONNECTING_IP option (default
off). Operators behind Cloudflare set CF_CONNECTING_IP=true; everyone
else falls back to the proxy-overwritten X-Forwarded-For or the socket
address.
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.

cf-connecting-ip is trusted unconditionally, allowing cross-network IP-room join via a spoofed header

1 participant