Skip to content

Reverse proxy and client IP

This page is for operators who put Adiutor behind a reverse proxy, a CDN or a load balancer. It covers keeping the app’s port private, telling Adiutor which header holds the client’s IP address, example setups for Caddy and nginx, and how to check it.

Adiutor uses the client’s IP address for its per-IP rate limits, the audit log, the list of signed-in devices and the security emails. If it reads the wrong address, everyone behind the proxy shares one rate limit (one person can then block password and email-link sign-in for the whole site), or someone can choose their own address and put a fake one in the audit log and in emails.

Whatever your setup, clients must not be able to reach the app without going through your proxy or platform. Anyone who can talk to the app directly can send any IP header and choose their own address, which gets around the per-IP limits.

On a server with Docker, published ports bypass firewalls such as ufw. So either:

  • publish the port on the loopback address only, 127.0.0.1:3000:3000 instead of 3000:3000, when the proxy runs on the host, or
  • don’t publish it at all, and put the proxy on the same Docker network as the app.

Two settings decide it:

  • CLIENT_IP_HEADERS names the headers to read, in order. The default is x-forwarded-for.
  • TRUSTED_PROXIES lists the addresses or CIDR ranges of your own proxies, separated by commas.

Without TRUSTED_PROXIES, a header only counts when it holds a single address. A chain like client, proxy is ignored, since anyone can put an address at its left end. With TRUSTED_PROXIES, a chain is read from the right, skipping those addresses: the first other address is the client.

The safest setup is a proxy that replaces one header with the address that connected to it, and CLIENT_IP_HEADERS set to that header, with TRUSTED_PROXIES empty. The two examples below do that with X-Real-IP.

Caddy gets a certificate for the address by itself and redirects HTTP to HTTPS. In the Caddyfile, replace X-Real-IP with the address that connected:

adiutor.dev {
reverse_proxy 127.0.0.1:3000 {
header_up X-Real-IP {remote_host}
}
}

That’s for Caddy on the host, with the app’s port published on the loopback address as in the Compose file. When Caddy runs in a container on the same Docker network as the app, use the app’s service name instead, app:3000. Caddy passes on the Host the browser asked for and sets X-Forwarded-Proto by itself (see nginx for why that matters). Then set this in Adiutor’s environment:

CLIENT_IP_HEADERS=x-real-ip

and leave TRUSTED_PROXIES empty.

A whole server block for HTTPS, with the certificate paths from your certificate tool, and a block that sends HTTP to HTTPS:

server {
listen 80;
server_name adiutor.dev;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
# nginx 1.25.1 or newer; older versions write "listen 443 ssl http2;" instead.
http2 on;
server_name adiutor.dev;
ssl_certificate /etc/letsencrypt/live/adiutor.dev/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/adiutor.dev/privkey.pem;
# Attachments up to 50 MB; nginx allows 1 MB unless told otherwise.
client_max_body_size 51m;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

X-Real-IP is set to the address that connected, whatever the client sent. Keep the Host and X-Forwarded-Proto lines too. Adiutor takes its own address from BETTER_AUTH_URL, but Next.js, which it runs on, refuses every form whose origin doesn’t match Host, and builds the address it redirects signed-out visitors to from both headers. nginx passes the Range header and the 206 answers that videos need through, unless you turn on caching for this location. Then set:

CLIENT_IP_HEADERS=x-real-ip

and leave TRUSTED_PROXIES empty. With the Docker image, use the app’s service name instead of 127.0.0.1 when nginx is on the same Docker network.

If you would rather keep X-Forwarded-For, where each proxy adds the address it saw to the right end, set TRUSTED_PROXIES instead of CLIENT_IP_HEADERS:

  • With a single proxy, any value works, for instance the proxy’s own address: it only makes Adiutor read the chain from the right.
  • With more hops (a load balancer or CDN in front of the proxy), list every one of their addresses.

Otherwise Adiutor sees a hop’s address, or none, instead of the client’s. When it sees none, it logs Better Auth’s warning “Rate limiting could not determine a client IP”.

Nothing to set. Vercel replaces X-Forwarded-For with the client’s address and drops what the client sent, so the default works: leave both settings empty. Don’t put another proxy or CDN in front of it without coming back to this page.

Behind Cloudflare, set CLIENT_IP_HEADERS=cf-connecting-ip, and only accept traffic from Cloudflare’s addresses (in your firewall), or anyone could send that header themselves.

Platforms that add to a client’s X-Forwarded-For instead of replacing it, such as AWS load balancers and Heroku-style routers, need their addresses in TRUSTED_PROXIES, like a second hop above.

  1. Sign in and open your account’s Activity tab. Under “Signed-in devices”, this device must show your own public address. Compare with curl https://icanhazip.com.

  2. Try a forged address, with a wrong password for your own account (here Alex Admin’s):

    Terminal window
    curl https://adiutor.dev/api/auth/sign-in/email -H 'Content-Type: application/json' -H 'Origin: https://adiutor.dev' -H 'X-Forwarded-For: 203.0.113.7' -H 'X-Real-IP: 203.0.113.7' -d '{"email":"[email protected]","password":"not-the-password"}'

    As a staff Admin, open your own account under Users, on its Activity tab. Under Recent activity, that failed attempt must show your own address, not 203.0.113.7.

  3. From another machine, the app’s own port must not answer: curl -m 5 http://<server address>:3000 should fail.

  4. The app’s log must not show “Rate limiting could not determine a client IP”.

Adiutor runs at https://adiutor.dev behind Caddy on the same server, with the app published on 127.0.0.1:3000. Alex Admin ([email protected]) sets CLIENT_IP_HEADERS=x-real-ip, restarts, then runs the checks above with the address 203.0.113.7. The failed attempt shows Alex’s own address, so it works.

  • A proxy that sets a header only helps while clients can’t reach the app around it: keep the port private.
  • Adiutor needs HTTPS: a production server refuses an http:// BETTER_AUTH_URL, except on this computer.

Adiutor's code is released under the MIT License. The Adiutor name and logo aren’t covered by it; see the notice.

Set in Inter and JetBrains Mono, under the SIL Open Font License (Inter, JetBrains Mono).