Fixed admin rate issues
This commit is contained in:
@@ -28,16 +28,20 @@ const strictLimiter = rateLimit({
|
||||
message: 'Too many write operations, please try again later.'
|
||||
});
|
||||
|
||||
// Auth-specific limiter
|
||||
// Auth-specific limiter with admin bypass capability
|
||||
const authLimiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000,
|
||||
max: config.isProduction ? 10 : 50,
|
||||
max: config.isProduction ? 30 : 50, // Increased from 10 to 30 for production
|
||||
keyGenerator,
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
trustProxy: true, // Explicitly trust proxy
|
||||
message: 'Too many login attempts, please try again later.',
|
||||
skipSuccessfulRequests: true
|
||||
skipSuccessfulRequests: true,
|
||||
skip: (req, res) => {
|
||||
// Skip rate limiting for authenticated admin users on certain admin endpoints
|
||||
return req.session?.isAdmin && req.path?.includes('/admin');
|
||||
}
|
||||
});
|
||||
|
||||
// Temp user rate limiter - stricter but allows for auto-refresh
|
||||
@@ -63,10 +67,22 @@ const conditionalTempLimiter = (req, res, next) => {
|
||||
return apiLimiter(req, res, next);
|
||||
};
|
||||
|
||||
// Admin-friendly limiter for admin operations
|
||||
const adminLimiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
max: 200, // High limit for admin operations
|
||||
keyGenerator,
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
trustProxy: true,
|
||||
message: 'Rate limit exceeded for admin operations. Please try again later.'
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
apiLimiter,
|
||||
strictLimiter,
|
||||
authLimiter,
|
||||
tempUserLimiter,
|
||||
conditionalTempLimiter
|
||||
conditionalTempLimiter,
|
||||
adminLimiter
|
||||
};
|
||||
Reference in New Issue
Block a user