Skip to content

Commit 574dffc

Browse files
committed
fix: set trust proxy to 2 for Cloudflare + nginx chain (#507)
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.
1 parent 9a1b077 commit 574dffc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const app = express();
2121
app.use(compression());
2222

2323
// logging
24-
app.enable("trust proxy"); // for :remote-addr
24+
app.set("trust proxy", 2); // Cloudflare → nginx → Express
2525
app.use(logging.stdout());
2626
app.use(logging.stderr());
2727

0 commit comments

Comments
 (0)