Honour forwarded headers only from MEALQUEST_TRUSTED_PROXY
Add internal/forwarded: parse the trusted proxy list (comma-separated IPs and CIDRs, validated at load), resolve each request's client IP and scheme, and expose them through context helpers. X-Forwarded-For and X-Forwarded-Proto are honoured only when the TCP peer is trusted; the client is the rightmost X-Forwarded-For address that is not a trusted proxy. Malformed forwarded headers from a trusted peer get 400. The router resolves every request first; a slog handler adds client_ip to request-scoped log lines. The auth routes refuse requests whose resolved scheme differs from MEALQUEST_PUBLIC_URL's, so a proxy that is not trusted fails loudly instead of breaking Secure cookies. The OIDC redirect URI is still built only from MEALQUEST_PUBLIC_URL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,10 @@ export MEALQUEST_OIDC_ALLOWED_GROUPS=mealquest-admin
|
||||
# and always MEALQUEST_SESSION_MAX after sign-in (default 4320h).
|
||||
# export MEALQUEST_SESSION_IDLE=720h
|
||||
# export MEALQUEST_SESSION_MAX=4320h
|
||||
# Optional: comma-separated IPs/CIDRs of reverse proxies whose
|
||||
# X-Forwarded-For/-Proto headers are honoured (production: Traefik). Unset
|
||||
# trusts no peer, which is right for local development.
|
||||
# export MEALQUEST_TRUSTED_PROXY=10.60.1.33
|
||||
make dev
|
||||
```
|
||||
|
||||
@@ -47,7 +51,8 @@ make dev
|
||||
(which proxies `/api`, `/auth` and `/media` to `:8080`). Open
|
||||
http://localhost:5173. Configuration is environment-only and fails fast:
|
||||
every variable above is required except the commented-out session
|
||||
lifetimes (when set they must be positive, with MAX at least IDLE), and
|
||||
lifetimes (when set they must be positive, with MAX at least IDLE) and
|
||||
trusted proxy list (every entry must be an IP or CIDR), and
|
||||
secrets are read only from files named by `*_FILE` variables. `MEALQUEST_PUBLIC_URL`, `MEALQUEST_OIDC_ISSUER` and the
|
||||
endpoints the issuer advertises must be `https://`; plain `http://` is
|
||||
accepted only for `localhost`, `127.0.0.1` and `[::1]`.
|
||||
|
||||
Reference in New Issue
Block a user