Express rate limiter counts all users as one behind a proxy: the trust proxy fix
Developers deploying Express apps behind hosts like Render, Railway, Fly.io, or Nginx often find express-rate-limit grouping every user into a single shared limit. The cause is that Express does not trust the X-Forwarded-For header by default, so req.ip resolves to the proxy's address instead of the real client. The recommended remedy is setting the trust proxy option in Express before the rate limiter middleware runs. The article cautions that the value, such as 1 for one hop, must match the actual proxy topology rather than be guessed, since miscounted hops can let clients spoof their IP. It also advises verifying the resolved client IP with a diagnostic endpoint across real deployment paths.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in