/** * Safe regex compiler — ReDoS 방지용 경량 가드. * * rule JSON 의 verifier.params.pattern 등 user-controlled regex 를 hook 런타임에 * 그대로 new RegExp() 하면 catastrophic backtracking 으로 hook hang 위험이 있다. * re2 같은 linear-time 엔진 의존은 native binding 을 추가시키므로, 여기서는 * **패턴 복잡도 제한** + **입력 크기 제한** 으로 1차 방어. * * 정책: * - 패턴 길이 ≤ 500자. * - 중첩 quantifier (`(...)+)+` / `(...)*)*` / `(.+)+`) 같은 catastrophic 신호 거부. * - backreference `\1..\9` 금지. * - compile 실패 또는 거부 시 null 반환 → 호출자가 skip. */ export interface SafeRegexResult { regex: RegExp | null; reason: string | null; } /** * 패턴을 안전하게 컴파일. 거부되거나 실패 시 { regex: null, reason } 반환. * 호출자는 reason 을 log.debug 로 기록하고 skip 하는 것이 권장 사용법. */ export declare function compileSafeRegex(pattern: string, flags?: string): SafeRegexResult; /** 입력을 MAX_INPUT_LEN 으로 자른 뒤 regex.test() 수행. 입력 DoS 방어. */ export declare function safeRegexTest(regex: RegExp, input: string): boolean;