/** * Utility functions for URL building, header manipulation, and query string handling */ import { URL } from "url"; import { ProxyLogger } from "./logger"; /** * Builds a URL from source and optional base with security validation */ export declare function buildURL(source: string, base?: string, logger?: ProxyLogger, requestId?: string, req?: Request): URL; /** * Filters out a specific header (case-insensitive) */ export declare function filterHeaders(headers: Record, filter: string): Record; /** * Converts Headers object to plain object */ export declare function headersToRecord(headers: Headers): Record; /** * Converts plain object to Headers object with security validation */ export declare function recordToHeaders(record: Record, logger?: ProxyLogger, requestId?: string, req?: Request): Headers; /** * Builds query string from parameters with security validation */ export declare function buildQueryString(params: Record | string, logger?: ProxyLogger, requestId?: string, req?: Request): string; /** * Validates HTTP method for security issues */ export declare function validateHttpMethod(method: string, logger?: ProxyLogger, requestId?: string, req?: Request): void; /** * Securely normalizes a path by removing directory traversal sequences and ensuring it stays within allowed bounds * @param inputPath - The input path that may contain traversal sequences * @param allowedPrefix - The prefix that the normalized path must start with (e.g., "/files/") * @returns The normalized path that is safe from directory traversal * @throws Error if the path attempts to escape the allowed prefix */ export declare function normalizeSecurePath(inputPath: string, allowedPrefix: string): string; /** * Security configuration constants for DoS prevention */ export declare const SECURITY_LIMITS: { readonly MAX_ITERATIONS: 1000; readonly MAX_CONCURRENCY: 50; readonly MAX_FILE_SIZE: number; readonly MAX_STRING_LENGTH: 1000; readonly MAX_TIMEOUT: 60000; readonly MAX_QUERY_PARAMS: 100; readonly MAX_HEADERS: 50; readonly MAX_URL_LENGTH: 2048; }; /** * Validates and limits numeric parameters to prevent DoS attacks * @param value - The numeric value to validate * @param max - Maximum allowed value * @param paramName - Name of the parameter for error messages * @returns The validated and limited value */ export declare function validateNumericLimit(value: number, max: number, paramName: string): number; /** * Validates string length to prevent memory exhaustion attacks * @param value - The string to validate * @param maxLength - Maximum allowed length * @param paramName - Name of the parameter for error messages * @returns The validated string */ export declare function validateStringLength(value: string, maxLength: number, paramName: string): string; /** * Validates file size to prevent resource exhaustion * @param size - The file size in bytes * @param maxSize - Maximum allowed size in bytes * @returns The validated size */ export declare function validateFileSize(size: number, maxSize?: number): number; /** * Validates URL length to prevent memory exhaustion * @param url - The URL string to validate * @returns The validated URL string */ export declare function validateUrlLength(url: string): string; /** * Creates a rate limiter function to prevent DoS attacks * @param maxRequests - Maximum requests allowed per window * @param windowMs - Time window in milliseconds * @returns Rate limiter function */ export declare function createRateLimiter(maxRequests: number, windowMs: number): (identifier: string) => boolean; //# sourceMappingURL=utils.d.ts.map