This guide provides a production TLS recipe for deploying Concord behind the Caddy web server as a reverse proxy with automated HTTPS, __Host- session cookie hardening, and spoof-resistant rate limiting.
Concord's server (services/api/src/main.ts) is a single Node.js process listening by default on port 4400. It does not terminate TLS natively or bind low ports directly.
Caddy provides:
- Automatic HTTPS: Issues and renews free Let's Encrypt or ZeroSSL TLS certificates with zero manual intervention.
- Modern TLS & HTTP/2 / HTTP/3: Enforces secure cipher suites out of the box.
- Clean Proxying: Transparently sets
X-Forwarded-For,X-Forwarded-Proto, andX-Forwarded-Hostheaders.
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddysudo dnf install 'dnf-command(copr)'
sudo dnf copr enable @caddy/caddy
sudo dnf install caddyIf deploying alongside Concord via Docker Compose:
services:
caddy:
image: caddy:2-alpine
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
depends_on:
- concord
concord:
image: concord:latest
restart: unless-stopped
environment:
- CONCORD_PUBLIC_URL=https://concord.example.com
- CONCORD_TRUST_PROXY=1
volumes:
- concord_data:/data
volumes:
caddy_data:
caddy_config:
concord_data:Create or edit /etc/caddy/Caddyfile:
concord.example.com {
# Terminate TLS and enforce HSTS
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
Referrer-Policy "strict-origin-when-cross-origin"
}
# Proxy to Concord Node API/dashboard
reverse_proxy 127.0.0.1:4400 {
header_up Host {host}
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
}
}Reload Caddy after saving:
sudo systemctl reload caddyConcord reads two essential environment variables to operate safely behind Caddy:
Set this to the public canonical HTTPS origin:
export CONCORD_PUBLIC_URL="https://concord.example.com"Code references: services/api/src/config.ts and services/api/src/auth-api.ts.
- When
CONCORD_PUBLIC_URLbegins withhttps://:sessions()setssecure = true.- The session cookie name changes from
concord_sessionto__Host-concord_session. - The Google OAuth state cookie changes from
concord_oauthto__Host-concord_oauth. - The cookies are emitted with flags
Secure; HttpOnly; SameSite=Strict; Path=/.
- If
CONCORD_PUBLIC_URLis omitted or set tohttp://, Concord emits a warning on startup:CONCORD_PUBLIC_URL is not https: sessions travel in the clear. Put TLS in front before anyone signs in.
Set this to the exact number of reverse proxy hops in front of Concord:
export CONCORD_TRUST_PROXY=1Code reference: services/api/src/auth-api.ts:28-43.
clientIp(c, trustProxyHops)parses theX-Forwarded-Forchain:const hops = (c.req.header("x-forwarded-for") ?? "").split(",").map((s) => s.trim()).filter(Boolean); const seen = hops[hops.length - trustProxyHops];
- Why
1? When Caddy receives a request, it appends the client's peer IP to the end ofX-Forwarded-For. WithCONCORD_TRUST_PROXY=1, Concord inspectshops[hops.length - 1], which is the IP verified by Caddy. - Spoof Resistance: If an attacker sends a crafted header
X-Forwarded-For: 1.1.1.1, Caddy appends the attacker's actual IP (e.g.198.51.100.2), making the header1.1.1.1, 198.51.100.2. Concord selects198.51.100.2and ignores the spoofed1.1.1.1. - Warning on Mismatch:
- Setting
CONCORD_TRUST_PROXY=0(or omitting it) makes Concord fall back togetConnInfo(c).remote.address, which is127.0.0.1(Caddy itself). All clients would then share a single rate-limit bucket. - Setting
CONCORD_TRUST_PROXYtoo high (e.g.2when only 1 proxy exists) allows callers to spoof their IP by prepending fake addresses inX-Forwarded-For.
- Setting
Run curl -i against the HTTP endpoint to confirm automatic redirect:
curl -i http://concord.example.comExpected response: HTTP/1.1 308 Permanent Redirect with Location: https://concord.example.com/.
Inspect the HTTPS headers:
curl -sI https://concord.example.com | grep -i strict-transport-securityExpected output:
strict-transport-security: max-age=31536000; includeSubDomains; preloadAuthenticate or sign up via the API or dashboard:
curl -i -X POST https://concord.example.com/api/auth/signin \
-H "Content-Type: application/json" \
-d '{"email":"operator@example.com","password":"your-secure-password"}'Inspect the Set-Cookie header in the response:
Set-Cookie: __Host-concord_session=...; Max-Age=2592000; Path=/; HttpOnly; Secure; SameSite=StrictKey attributes to verify:
- Name is prefixed with
__Host-(only accepted by browsers over HTTPS). Path=/is present.SecureandHttpOnlyflags are present.SameSite=Strictprevents CSRF attacks.
Concord enforces IP-based rate limiting on sensitive auth endpoints (services/api/src/auth-api.ts):
signin:<ip>: 20 attempts per 10 minutessignup:<ip>: 20 attempts per 60 minutesinvite:<ip>: 20 attempts per 10 minutesreset:<ip>: 20 attempts per 10 minutes
Test spoof resistance by sending requests with a forged X-Forwarded-For header:
curl -i -X POST https://concord.example.com/api/auth/signin \
-H "Content-Type: application/json" \
-H "X-Forwarded-For: 10.0.0.99" \
-d '{"email":"invalid@example.com","password":"bad-password"}'Check Caddy logs or repeat 20 times: Concord will lock out your real public IP, not 10.0.0.99. This proves CONCORD_TRUST_PROXY=1 successfully isolates the hop appended by Caddy.