/** * Regex Timeout Wrapper (Task 007) * * Provides timeout protection for regex execution to prevent * ReDoS attacks that bypass static detection. * * ## Defense-in-Depth Strategy * - Static detection catches known dangerous patterns (in security.ts) * - This module adds runtime timing checks for novel attack patterns * - Short inputs bypass overhead for performance * * ## Limitations * - JavaScript main thread regex cannot be truly interrupted * - This implementation uses timing checks, not true cancellation * - For true cancellation, would need Worker threads (future enhancement) */ /** * Options for regex timeout wrapper */ export interface RegexTimeoutOptions { /** Timeout in milliseconds (default: 100) */ timeout?: number; /** Throw error on timeout (default: true) */ throwOnTimeout?: boolean; /** Minimum input length to apply timeout protection (default: 1000) */ minInputLengthForTimeout?: number; } /** Default timeout options */ export declare const DEFAULT_REGEX_TIMEOUT_OPTIONS: Required; /** * Execute regex test with timeout protection. * * Uses timing checks as defense-in-depth against ReDoS attacks. * For short inputs (<1000 chars by default), skips timeout overhead. * * @param pattern - Regex pattern or RegExp object * @param input - String to test * @param options - Timeout options * @returns Test result or false if timeout/error * @throws SecurityError if timeout and throwOnTimeout=true * * @example * ```typescript * // Basic usage * const matches = safeRegexTest(/hello/, 'hello world'); * * // With custom timeout * const matches = safeRegexTest(/complex.*pattern/, longInput, { timeout: 50 }); * * // Silent failure mode * const matches = safeRegexTest(pattern, input, { throwOnTimeout: false }); * ``` */ export declare function safeRegexTest(pattern: RegExp | string, input: string, options?: RegexTimeoutOptions): boolean; /** * Execute regex match with timeout protection. * * Uses timing checks as defense-in-depth against ReDoS attacks. * For short inputs (<1000 chars by default), skips timeout overhead. * * @param pattern - Regex pattern or RegExp object * @param input - String to match * @param options - Timeout options * @returns Match result or null if timeout/error * @throws SecurityError if timeout and throwOnTimeout=true * * @example * ```typescript * // Basic usage * const match = safeRegexMatch(/(\d+)/, 'value: 123'); * * // With custom timeout * const match = safeRegexMatch(/complex.*pattern/, longInput, { timeout: 50 }); * ``` */ export declare function safeRegexMatch(pattern: RegExp | string, input: string, options?: RegexTimeoutOptions): RegExpMatchArray | null; /** * Execute regex replace with timeout protection. * * @param pattern - Regex pattern or RegExp object * @param input - String to process * @param replacement - Replacement string or function * @param options - Timeout options * @returns Replaced string or original if error * @throws SecurityError if timeout and throwOnTimeout=true */ export declare function safeRegexReplace(pattern: RegExp | string, input: string, replacement: string | ((substring: string, ...args: any[]) => string), options?: RegexTimeoutOptions): string; /** * Create a safe regex executor with pre-configured options. * * @param options - Default options for all operations * @returns Object with safe regex methods * * @example * ```typescript * const safeRegex = createSafeRegexExecutor({ timeout: 50 }); * const matches = safeRegex.test(/pattern/, input); * const result = safeRegex.match(/pattern/, input); * ``` */ export declare function createSafeRegexExecutor(options?: RegexTimeoutOptions): { test: (pattern: RegExp | string, input: string, overrides?: RegexTimeoutOptions) => boolean; match: (pattern: RegExp | string, input: string, overrides?: RegexTimeoutOptions) => RegExpMatchArray | null; replace: (pattern: RegExp | string, input: string, replacement: string | ((substring: string, ...args: any[]) => string), overrides?: RegexTimeoutOptions) => string; }; //# sourceMappingURL=regex-timeout.d.ts.map