/** * Safe Regex Utilities * * Mitigates ReDoS (Regular Expression Denial of Service) risks when * constructing RegExp from user-provided patterns (e.g. hook matchers * in config). Since patterns are user-authored and local, the risk is * low, but these guards prevent accidental catastrophic backtracking. * * Provides: * - Static detection of patterns prone to catastrophic backtracking * - Bounded regex test that limits input length * - Regex-special-character escaping for safe interpolation */ /** * Check whether a regex pattern string is likely vulnerable to ReDoS * via catastrophic backtracking. * * This is a heuristic check — it will not catch every possible ReDoS * pattern, but it reliably detects the most common dangerous structures * (nested quantifiers, overlapping alternations with quantifiers). * * @param pattern - The regex source string to analyse * @returns Object with `safe` boolean and optional `reason` string */ export declare function checkReDoSRisk(pattern: string): { reason?: string; safe: boolean; }; /** * Test a regex against an input string with ReDoS safeguards: * 1. Input length is capped to prevent long-input amplification. * 2. Returns false (no match) if input exceeds the cap — tool names * and similar identifiers should always be short. * * @param regex - The compiled RegExp to test * @param input - The string to test against * @param maxLen - Maximum allowed input length (default 1024) * @returns true if the regex matches the (bounded) input */ export declare function safeRegexTest(regex: RegExp, input: string, maxLen?: number): boolean; /** * Escape all regex-special characters in a string so it can be safely * interpolated into a RegExp pattern as a literal. * * @param str - The string to escape * @returns The escaped string safe for `new RegExp(...)` interpolation */ export declare function escapeRegExp(str: string): string; //# sourceMappingURL=safe-regex.d.ts.map