better logging
This commit is contained in:
@ -152,9 +152,10 @@ export class SharedSecurityManager {
|
||||
*
|
||||
* @param route - The route to check
|
||||
* @param context - The request context
|
||||
* @param routeConnectionCount - Current connection count for this route (optional)
|
||||
* @returns Whether access is allowed
|
||||
*/
|
||||
public isAllowed(route: IRouteConfig, context: IRouteContext): boolean {
|
||||
public isAllowed(route: IRouteConfig, context: IRouteContext, routeConnectionCount?: number): boolean {
|
||||
if (!route.security) {
|
||||
return true; // No security restrictions
|
||||
}
|
||||
@ -165,6 +166,14 @@ export class SharedSecurityManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- Route-level connection limit ---
|
||||
if (route.security.maxConnections !== undefined && routeConnectionCount !== undefined) {
|
||||
if (routeConnectionCount >= route.security.maxConnections) {
|
||||
this.logger?.debug?.(`Route connection limit (${route.security.maxConnections}) exceeded for route ${route.name || 'unnamed'}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Rate limiting ---
|
||||
if (route.security.rateLimit?.enabled && !this.isWithinRateLimit(route, context)) {
|
||||
this.logger?.debug?.(`Rate limit exceeded for route ${route.name || 'unnamed'}`);
|
||||
@ -304,6 +313,20 @@ export class SharedSecurityManager {
|
||||
// Clean up rate limits
|
||||
cleanupExpiredRateLimits(this.rateLimits, this.logger);
|
||||
|
||||
// Clean up IP connection tracking
|
||||
let cleanedIPs = 0;
|
||||
for (const [ip, info] of this.connectionsByIP.entries()) {
|
||||
// Remove IPs with no active connections and no recent timestamps
|
||||
if (info.connections.size === 0 && info.timestamps.length === 0) {
|
||||
this.connectionsByIP.delete(ip);
|
||||
cleanedIPs++;
|
||||
}
|
||||
}
|
||||
|
||||
if (cleanedIPs > 0 && this.logger?.debug) {
|
||||
this.logger.debug(`Cleaned up ${cleanedIPs} IPs with no active connections`);
|
||||
}
|
||||
|
||||
// IP filter cache doesn't need cleanup (tied to routes)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user