From f4668644da5412e1b26565efabd36aa444d5ce5b Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Tue, 28 Apr 2026 22:21:42 +1000 Subject: [PATCH] fix: set trust proxy to 2 for Cloudflare + nginx chain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit express-rate-limit v8.4+ rejects `trust proxy = true` because it allows anyone to spoof X-Forwarded-For and bypass rate limiting (ERR_ERL_PERMISSIVE_TRUST_PROXY). Setting it to 2 trusts exactly the two known proxy hops (Cloudflare → nginx → Express) while still resolving the correct client IP for logging and rate limiting. --- app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.ts b/app.ts index 30264dfb..e36a49db 100644 --- a/app.ts +++ b/app.ts @@ -21,7 +21,7 @@ const app = express(); app.use(compression()); // logging -app.enable("trust proxy"); // for :remote-addr +app.set("trust proxy", 2); // Cloudflare → nginx → Express app.use(logging.stdout()); app.use(logging.stderr());