anythingmcp
anythingmcp copied to clipboard
Trust only the configured proxies for the client IP
Problem
The backend sets Express trust proxy to true. With that setting Express takes the client address (req.ip) from the leftmost entry of X-Forwarded-For, and that entry is whatever the client sent.
req.ip keys the global per-IP rate limit (ThrottlerGuard) and the stricter limits on sign-in and password reset. A client that changes the header on every request is never counted twice, so those limits do not hold. The request log also records the address from the leftmost header entry, so the logged client address can be chosen by the client.
Proposal
- Trust forwarded headers only from configured proxies, with a safe default instead of
true. - Default: proxies on private networks (loopback, link-local, private ranges). This fits the bundled Caddy / frontend setups and LAN proxies, keeps the real client address behind any number of private hops, and never reaches an address the client injected.
- A
TRUST_PROXYvariable for other setups: a hop count,false, or a list of addresses / CIDR ranges. - Log the active setting at startup and warn when
trueis set explicitly. - Take the logged client address from Express (
req.ip) instead of the raw header.
Behaviour
- Self-hosted: no change needed behind Caddy, nginx or Traefik on the same host or Docker network. A proxy that reaches the backend from a public address needs
TRUST_PROXY. - Cloud: same default; the proxy sits on the private container network.