UNPKG

@push.rocks/smartproxy

Version:

A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.

112 lines (111 loc) 3.68 kB
import type { IRouteConfig, IRouteContext } from '../../proxies/smart-proxy/models/route-types.js'; import type { IIpValidationResult, ISecurityLogger } from './security-utils.js'; /** * Shared SecurityManager for use across proxy components * Handles IP tracking, rate limiting, and authentication */ export declare class SharedSecurityManager { private logger?; private connectionsByIP; private rateLimits; private ipFilterCache; private maxConnectionsPerIP; private connectionRateLimitPerMinute; private cleanupInterval; /** * Create a new SharedSecurityManager * * @param options - Configuration options * @param logger - Logger instance */ constructor(options: { maxConnectionsPerIP?: number; connectionRateLimitPerMinute?: number; cleanupIntervalMs?: number; routes?: IRouteConfig[]; }, logger?: ISecurityLogger); /** * Get connections count by IP * * @param ip - The IP address to check * @returns Number of connections from this IP */ getConnectionCountByIP(ip: string): number; /** * Track connection by IP * * @param ip - The IP address to track * @param connectionId - The connection ID to associate */ trackConnectionByIP(ip: string, connectionId: string): void; /** * Remove connection tracking for an IP * * @param ip - The IP address to update * @param connectionId - The connection ID to remove */ removeConnectionByIP(ip: string, connectionId: string): void; /** * Check if IP is authorized based on route security settings * * @param ip - The IP address to check * @param allowedIPs - List of allowed IP patterns * @param blockedIPs - List of blocked IP patterns * @returns Whether the IP is authorized */ isIPAuthorized(ip: string, allowedIPs?: string[], blockedIPs?: string[]): boolean; /** * Validate IP against rate limits and connection limits * * @param ip - The IP address to validate * @returns Result with allowed status and reason if blocked */ validateIP(ip: string): IIpValidationResult; /** * Check if a client is allowed to access a specific route * * @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 */ isAllowed(route: IRouteConfig, context: IRouteContext, routeConnectionCount?: number): boolean; /** * Check if a client IP is allowed for a route * * @param route - The route to check * @param clientIp - The client IP * @returns Whether the IP is allowed */ private isClientIpAllowed; /** * Check if request is within rate limit * * @param route - The route to check * @param context - The request context * @returns Whether the request is within rate limit */ private isWithinRateLimit; /** * Validate HTTP Basic Authentication * * @param route - The route to check * @param authHeader - The Authorization header * @returns Whether authentication is valid */ validateBasicAuth(route: IRouteConfig, authHeader?: string): boolean; /** * Clean up caches to prevent memory leaks */ private cleanupCaches; /** * Clear all IP tracking data (for shutdown) */ clearIPTracking(): void; /** * Update routes for security checking * * @param routes - New routes to use */ setRoutes(routes: IRouteConfig[]): void; }