Sharkord
HTTPS Setup

Behind a Proxy

Trusted proxies, real client IPs, CDNs and what the proxy must pass through.

Sharkord uses the client IP for pre-login rate limits, upload limits, and the IP shown to admins. Behind a proxy, if the forwarded headers are not trusted, every user shares the proxy's IP and one rate limit bucket.

Trusted Proxies

server.trustedProxies lists who may set forwarded headers. Default: loopback and all private ranges.

[server]
trustedProxies[]=127.0.0.1
trustedProxies[]=::1
trustedProxies[]=10.0.0.0/8
trustedProxies[]=172.16.0.0/12
trustedProxies[]=192.168.0.0/16
trustedProxies[]=fc00::/7

So a proxy on the same host, in another container or on your LAN needs no config. A proxy reaching you from a public IP (a CDN) does. Setting the option replaces the list, so keep the private ranges you need.

Shared networks

Anything trusted can pick any client IP. If machines you do not control can reach Sharkord's port (shared provider network, campus LAN, multi-tenant Kubernetes), narrow the list to your proxy.

Running in Docker with no proxy at all? Some setups (Docker's userland proxy, IPv6) make every outside client arrive from the bridge gateway, such as 172.17.0.1, which falls in a trusted range, so any of them can pick its own IP. Set the list to 127.0.0.1 and ::1 to stop that. Those clients then share the gateway's IP and one rate limit bucket, so the real fix is to put a proxy in front.

How the IP Is Picked

  1. Connection not from a trusted proxy: use the socket IP, ignore headers.
  2. Otherwise read X-Forwarded-For, then Forwarded (max 20 entries).
  3. Take the right-most entry that is not a trusted proxy.
  4. All entries trusted: take the left-most. Nothing usable: socket IP.

CF-Connecting-IP and X-Real-IP are ignored on purpose. They carry no hop info, so a spoofed value looks the same as a real one.

Setups

Proxy on the same host, in Docker, or on the LAN. Nothing to do. Nginx must send X-Forwarded-For itself (the Nginx guide does). Caddy and Apache send it by default.

Proxy on another host over a public IP. Add that IP, and firewall Sharkord's port to that host only.

Cloudflare in front of your proxy. The header becomes visitor, cloudflare-edge. Cloudflare's edge is public, so add its IPv4 and IPv6 ranges:

[server]
trustedProxies[]=127.0.0.1
trustedProxies[]=::1
trustedProxies[]=172.16.0.0/12
trustedProxies[]=173.245.48.0/20
trustedProxies[]=103.21.244.0/22
# ...the rest of the published list

Or let Nginx resolve it and pass one clean IP:

# repeat for every cloudflare range
set_real_ip_from 173.245.48.0/20;
real_ip_header CF-Connecting-IP;

proxy_set_header X-Forwarded-For $remote_addr;

Coolify with Cloudflare. Traefik drops Cloudflare's header unless it trusts the edge. In Servers → your server → Proxy → Configuration, add to the Traefik command list:

      - '--entrypoints.http.forwardedHeaders.trustedIPs=127.0.0.1/32,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/13,104.24.0.0/14,172.64.0.0/13,131.0.72.0/22,2400:cb00::/32,2606:4700::/32,2803:f800::/32,2405:b500::/32,2405:8100::/32,2a06:98c0::/29,2c0f:f248::/32'
      - '--entrypoints.https.forwardedHeaders.trustedIPs=127.0.0.1/32,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,173.245.48.0/20,103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,141.101.64.0/18,108.162.192.0/18,190.93.240.0/20,188.114.96.0/20,197.234.240.0/22,198.41.128.0/17,162.158.0.0/15,104.16.0.0/13,104.24.0.0/14,172.64.0.0/13,131.0.72.0/22,2400:cb00::/32,2606:4700::/32,2803:f800::/32,2405:b500::/32,2405:8100::/32,2a06:98c0::/29,2c0f:f248::/32'

Both entrypoints, since http still serves the redirect. Restart the proxy. If users still show a Cloudflare IP, also add the Cloudflare ranges to Sharkord's trustedProxies.

Cloudflare Tunnel. Nothing to do. cloudflared connects from loopback.

Kubernetes ingress. Usually nothing. Check the controller sends X-Forwarded-For, and narrow the list on shared clusters.

Media never goes through the proxy or CDN

Port 40000 must be reachable directly, and webRtc.announcedAddress must point at the real server: the raw IP or a DNS-only (grey cloud) record. Point it at a proxied record and nobody hears anything.

Is It Working?

If headers arrive from an untrusted address, the server logs it once, with the IP to add:

Requests are arriving from 172.18.0.4 with forwarded headers, but that address is
not in server.trustedProxies, so the headers are ignored and every client is rate
limited as one.

Or open a user in the server settings (needs View user sensitive data) and check the IP is theirs.

What the Proxy Must Do

RequirementWhy
WebSocket upgradeSharkord runs on one WebSocket. Without it, nothing connects.
Long read timeoutThe socket idles. A 60s timeout drops users.
No body size limitUploads stream through.
X-Forwarded-ForReal client IPs.

Allowed Origins

server.allowedOrigins defaults to *. To lock it to your domain:

[server]
allowedOrigins[]=https://chat.example.com

This also applies to plugin HTTP routes.

On this page