This commit is contained in:
Matthias Hochmeister
2026-03-13 21:01:54 +01:00
parent ab29c43735
commit b7b4fe2fc9
14 changed files with 566 additions and 60 deletions

View File

@@ -34,14 +34,20 @@ const authLimiter = rateLimit({
});
app.use('/api/auth', authLimiter);
// General rate limiter — skip auth routes (they have their own limiter above)
// General rate limiter — skip auth routes (own limiter above) and authenticated
// requests (Bearer token present). Auth middleware validates the token downstream;
// rate-limiting authenticated dashboard polling would cause 429 floods.
app.use('/api', rateLimit({
windowMs: environment.rateLimit.windowMs,
max: environment.rateLimit.max,
message: 'Too many requests from this IP, please try again later.',
standardHeaders: true,
legacyHeaders: false,
skip: (req) => req.path.startsWith('/auth'),
skip: (req) => {
if (req.path.startsWith('/auth')) return true;
const auth = req.headers.authorization;
return typeof auth === 'string' && auth.startsWith('Bearer ');
},
}));
// Body parsing middleware