Nguyễn Việt Thành’s Post

Your API has no rate limiter. That means anyone can do this: for (let i = 0; i < 100000; i++) {  fetch('/api/login', { method: 'POST', body: credentials }); } Brute-force your login endpoint. Scrape all your data. Crash your server with a burst. Rate limiting is not optional. Here's how I implement it in Express/Node.js: import rateLimit from 'express-rate-limit'; const loginLimiter = rateLimit({  windowMs: 15 * 60 * 1000, // 15 minutes  max: 10, // max 10 login attempts per window  message: { error: 'Too many attempts. Try again in 15 minutes.' },  standardHeaders: true,  legacyHeaders: false, }); app.post('/api/auth/login', loginLimiter, authController.login); Different endpoints need different limits: → Login: strict (10/15min) — brute force target → Public search: relaxed (100/min) — UX matters → File upload: very strict (5/hour) — resource cost I added this to every project after forgetting it in my first one. Security is not a feature you add at the end. It's a constraint you build around from day 1. #Backend #Security #NodeJS #APIDesign #WebSecurity

To view or add a comment, sign in

Explore content categories