import { ValidationRule, ValidationContext, ValidationSeverity } from '../interfaces'; /** * Options for the NoRegexLiteralRule */ export interface NoRegexLiteralOptions { /** * Block all regex literals regardless of content. * Use this for maximum security (AgentScript preset). * Default: false */ blockAll?: boolean; /** * Analyze regex patterns for ReDoS vulnerabilities. * Patterns scoring above the threshold will be blocked. * Default: true (when blockAll is false) */ analyzePatterns?: boolean; /** * ReDoS analysis level. * - 'catastrophic': Only detect exponential patterns (e.g., (a+)+) * - 'polynomial': Also detect polynomial patterns (e.g., .*a.*b) * Default: 'catastrophic' */ analysisLevel?: 'catastrophic' | 'polynomial'; /** * Vulnerability score threshold for blocking. * Patterns with scores >= this value will be blocked. * Default: 80 (REDOS_THRESHOLDS.BLOCK) */ blockThreshold?: number; /** * Vulnerability score threshold for warnings. * Patterns with scores >= this value will generate warnings. * Default: 50 (REDOS_THRESHOLDS.WARN) */ warnThreshold?: number; /** * Maximum regex pattern length. * Patterns longer than this will be blocked. * Default: 200 */ maxPatternLength?: number; /** * Whitelist of allowed patterns (exact match or regex). * These patterns bypass analysis. * Example: ['^[a-z]+$', /^\d{4}-\d{2}-\d{2}$/] */ allowedPatterns?: (string | RegExp)[]; } /** * Rule that blocks or analyzes regex literals for security vulnerabilities. * * This rule provides defense against ReDoS (Regular Expression Denial of Service) * attacks by: * 1. Optionally blocking all regex literals (for high-security environments) * 2. Analyzing patterns for catastrophic backtracking vulnerabilities * 3. Limiting pattern length to prevent complexity attacks * * @example * ```typescript * // Block all regex (AgentScript preset) * new NoRegexLiteralRule({ blockAll: true }) * * // Analyze patterns (Strict/Secure preset) * new NoRegexLiteralRule({ * analyzePatterns: true, * analysisLevel: 'catastrophic', * }) * * // Allow specific patterns * new NoRegexLiteralRule({ * analyzePatterns: true, * allowedPatterns: ['^[a-z]+$', /^\d+$/], * }) * ``` */ export declare class NoRegexLiteralRule implements ValidationRule { readonly name = "no-regex-literal"; readonly description = "Blocks or analyzes regex literals for security vulnerabilities"; readonly defaultSeverity = ValidationSeverity.ERROR; readonly enabledByDefault = false; private readonly options; constructor(options?: NoRegexLiteralOptions); validate(context: ValidationContext): void; private checkRegex; private isAllowedPattern; private getLocation; }