/** * Regex detection and ReDoS analysis for the pre-scanner. * Detects regex literals and analyzes them for catastrophic backtracking. * * @module pre-scanner/checks/regex-check */ import type { PreScannerConfig } from '../config'; import type { ScanState } from '../scan-state'; /** * ReDoS pattern types and their vulnerability scores */ export declare const REDOS_PATTERNS: { /** Nested quantifiers: (a+)+ */ readonly NESTED_QUANTIFIER: { readonly name: "nested_quantifier"; readonly baseScore: 90; }; /** Overlapping alternation: (a|a)+ */ readonly OVERLAPPING_ALTERNATION: { readonly name: "overlapping_alternation"; readonly baseScore: 80; }; /** Greedy backtracking: (.*a)+ */ readonly GREEDY_BACKTRACKING: { readonly name: "greedy_backtracking"; readonly baseScore: 75; }; /** Multiple greedy: .*.* */ readonly MULTIPLE_GREEDY: { readonly name: "multiple_greedy"; readonly baseScore: 70; }; /** Repetition inside star: (a{2,})+ */ readonly REPETITION_IN_STAR: { readonly name: "repetition_in_star"; readonly baseScore: 85; }; /** Star inside repetition: (a+){2,} */ readonly STAR_IN_REPETITION: { readonly name: "star_in_repetition"; readonly baseScore: 85; }; /** Overlapping character classes: [a-z]+[a-z]+ */ readonly OVERLAPPING_CLASSES: { readonly name: "overlapping_classes"; readonly baseScore: 50; }; }; /** * Thresholds for ReDoS detection */ export declare const REDOS_THRESHOLDS: { /** Block immediately - critical vulnerability */ readonly BLOCK: 80; /** Warn but allow - suspicious pattern */ readonly WARN: 50; /** Safe - no detected issues */ readonly SAFE: 0; }; /** * Result of ReDoS analysis for a single pattern */ export interface ReDoSAnalysisResult { /** The analyzed pattern */ pattern: string; /** Is the pattern vulnerable? */ vulnerable: boolean; /** Vulnerability score (0-100) */ score: number; /** Type of vulnerability detected */ vulnerabilityType?: string; /** Human-readable explanation */ explanation?: string; } /** * Detect regex literals in source code. * This uses a simplified heuristic approach that may have false positives/negatives * but is safe for security purposes (may block valid code, won't allow attacks). * * @param source - The source code to scan * @param config - Pre-scanner configuration * @param state - Scan state for recording issues */ export declare function detectRegexLiterals(source: string, config: PreScannerConfig, state: ScanState): void; /** * Analyze a regex pattern for ReDoS vulnerabilities. * Uses static analysis to detect dangerous patterns. * Input is safely bounded to prevent the analyzer itself from being vulnerable. */ export declare function analyzeForReDoS(pattern: string, level: 'catastrophic' | 'polynomial'): ReDoSAnalysisResult; /** * Calculate star height (nesting depth of quantifiers). * Star height > 1 indicates potential vulnerability. * * Uses a group stack to properly track nested quantified groups. * For example, (a+)+ has star height 2: * - Level 1: a+ (char with quantifier) * - Level 2: (a+)+ (group containing quantified content, itself quantified) */ export declare function calculateStarHeight(pattern: string): number; /** * Perform regex checks. */ export declare function performRegexChecks(source: string, config: PreScannerConfig, state: ScanState): void;