Good Code
The good version sets a specific proxy trust depth and applies a clear rate limit policy.
Lesson 09
Configure client IP trust deliberately before using IP-based controls.
import express from "express";
import { rateLimit } from "express-rate-limit";
export function createApp() {
const app = express();
app.set("trust proxy", 1);
app.use(rateLimit({
windowMs: 60_000,
limit: 120,
standardHeaders: true,
legacyHeaders: false,
}));
return app;
}import express from "express";
import { rateLimit } from "express-rate-limit";
export function createApp() {
const app = express();
app.set("trust proxy", true);
app.use(rateLimit({ windowMs: 60_000, limit: 10_000 }));
return app;
}The good version sets a specific proxy trust depth and applies a clear rate limit policy.
The bad version trusts every proxy hop and sets a limit so high that the control is mostly decorative.