import { ValidationRule, ValidationContext, ValidationSeverity } from '../interfaces'; /** * Options for the NoRegexMethodsRule */ export interface NoRegexMethodsOptions { /** * Methods to block on strings. * These methods accept regex as arguments. * Default: ['match', 'matchAll', 'search', 'replace', 'replaceAll', 'split'] */ blockedStringMethods?: string[]; /** * Methods to block on regex objects. * These methods execute regex matching. * Default: ['test', 'exec'] */ blockedRegexMethods?: string[]; /** * Allow methods when the first argument is a string literal (not regex). * For example: "hello".split(",") is safe. * Default: true */ allowStringArguments?: boolean; /** * Custom error message template. * Placeholders: {method} */ messageTemplate?: string; } /** * Rule that blocks regex method calls to prevent ReDoS attacks. * * Even if regex literals are blocked, an attacker could potentially * construct regex through other means and use these methods. This rule * provides defense-in-depth by blocking the execution paths. * * **Blocked patterns:** * - `string.match(regex)` * - `string.matchAll(regex)` * - `string.search(regex)` * - `string.replace(regex, ...)` * - `string.replaceAll(regex, ...)` * - `string.split(regex)` * - `regex.test(string)` * - `regex.exec(string)` * * **Allowed (when allowStringArguments is true):** * - `"hello".split(",")` - string argument, not regex * - `"hello".replace("l", "x")` - string argument * * @example * ```typescript * // Block all regex methods (AgentScript preset) * new NoRegexMethodsRule() * * // Allow string arguments * new NoRegexMethodsRule({ allowStringArguments: true }) * * // Custom blocked methods * new NoRegexMethodsRule({ * blockedStringMethods: ['match', 'replace'], * blockedRegexMethods: ['test'], * }) * ``` */ export declare class NoRegexMethodsRule implements ValidationRule { readonly name = "no-regex-methods"; readonly description = "Blocks regex method calls to prevent ReDoS attacks"; readonly defaultSeverity = ValidationSeverity.ERROR; readonly enabledByDefault = false; private readonly blockedStringMethods; private readonly blockedRegexMethods; private readonly allowStringArguments; private readonly messageTemplate; constructor(options?: NoRegexMethodsOptions); validate(context: ValidationContext): void; private checkMethodCall; private getMethodName; private hasStringArgument; private hasRegexArgument; private isRegexLiteral; private isStringLiteral; private report; private getLocation; }