/** * Configuration interfaces and preset configurations for the pre-scanner. * * @module pre-scanner/config */ /** * Regex handling modes for the pre-scanner. */ export type RegexMode = 'block' | 'analyze' | 'allow'; /** * ReDoS analysis levels. * - 'catastrophic': Only detect patterns that cause exponential backtracking * - 'polynomial': Also detect patterns that cause polynomial slowdowns */ export type RegexAnalysisLevel = 'catastrophic' | 'polynomial'; /** * Configuration for the pre-scanner. * All limits are validated against mandatory caps and cannot exceed them. */ export interface PreScannerConfig { /** * Maximum input size in bytes. * Default: varies by preset (AgentScript: 100KB, Strict: 500KB, etc.) * Cannot exceed MANDATORY_LIMITS.ABSOLUTE_MAX_INPUT_SIZE (100MB) */ maxInputSize: number; /** * Maximum line length in characters. * Default: varies by preset (AgentScript: 2000, Strict: 5000, etc.) * Cannot exceed MANDATORY_LIMITS.ABSOLUTE_MAX_LINE_LENGTH (100,000) */ maxLineLength: number; /** * Maximum number of lines. * Default: varies by preset (AgentScript: 1000, Strict: 2000, etc.) * Cannot exceed MANDATORY_LIMITS.ABSOLUTE_MAX_LINES (1,000,000) */ maxLines: number; /** * Maximum bracket nesting depth (prevents parser stack overflow). * Default: varies by preset (AgentScript: 20, Strict: 30, etc.) * Cannot exceed MANDATORY_LIMITS.ABSOLUTE_MAX_NESTING (200) */ maxNestingDepth: number; /** * Maximum consecutive operators (e.g., ++++++). * Prevents parser confusion attacks. * Default: 10 */ maxConsecutiveOperators: number; /** * How to handle regex literals: * - 'block': Block all regex literals (AgentScript default) * - 'analyze': Allow but check for ReDoS patterns (Strict/Secure/Standard default) * - 'allow': Allow all regex without analysis (Permissive) */ regexMode: RegexMode; /** * Maximum regex pattern length (for 'analyze' mode). * Default: 200 * Cannot exceed MANDATORY_LIMITS.ABSOLUTE_MAX_REGEX_LENGTH (1000) */ maxRegexLength?: number; /** * Maximum number of regex literals per file (for 'analyze' mode). * Default: 20 * Cannot exceed MANDATORY_LIMITS.ABSOLUTE_MAX_REGEX_COUNT (50) */ maxRegexCount?: number; /** * ReDoS analysis level (for 'analyze' mode). * - 'catastrophic': Only detect exponential patterns (e.g., (a+)+) * - 'polynomial': Also detect polynomial patterns (e.g., .*a.*b) */ regexAnalysisLevel?: RegexAnalysisLevel; /** * Maximum single string literal length. * Default: varies by preset (AgentScript: 10KB, etc.) * Cannot exceed MANDATORY_LIMITS.ABSOLUTE_MAX_STRING (5MB) */ maxStringLength: number; /** * Maximum total string content across all literals. * Default: varies by preset * Cannot exceed MANDATORY_LIMITS.ABSOLUTE_MAX_TOTAL_STRING_CONTENT (50MB) */ maxTotalStringContent: number; /** * Enable Unicode pre-check for BiDi attacks. * Default: true for all presets except Permissive */ unicodePreCheck: boolean; /** * Block BiDi direction override characters (Trojan Source attacks). * Default: true for all presets except Permissive * When true, blocks: U+202A-E (LRE, RLE, PDF, LRO, RLO), U+2066-9 (LRI, RLI, FSI, PDI) */ blockBidiPatterns: boolean; /** * Block invisible/zero-width characters. * Default: true for AgentScript/Strict */ blockInvisibleChars?: boolean; } /** * Partial configuration for customization */ export type PartialPreScannerConfig = Partial; /** * Pre-scanner preset levels (mirrors the main preset levels) */ export type PreScannerPresetLevel = 'agentscript' | 'strict' | 'secure' | 'standard' | 'permissive'; /** * AgentScript preset - Maximum security for AI agent orchestration * * Key restrictions: * - 100KB max input (agents shouldn't need large scripts) * - Block ALL regex (agents use API filtering, not regex) * - Short line length limits * - Strict BiDi/unicode blocking */ export declare const AGENTSCRIPT_PRESCANNER_CONFIG: PreScannerConfig; /** * Strict preset - High security with ReDoS analysis */ export declare const STRICT_PRESCANNER_CONFIG: PreScannerConfig; /** * Secure preset - Balanced security with ReDoS analysis */ export declare const SECURE_PRESCANNER_CONFIG: PreScannerConfig; /** * Standard preset - Reasonable defaults with ReDoS analysis */ export declare const STANDARD_PRESCANNER_CONFIG: PreScannerConfig; /** * Permissive preset - Minimal restrictions * WARNING: Should only be used for trusted code in controlled environments */ export declare const PERMISSIVE_PRESCANNER_CONFIG: PreScannerConfig; /** * Map of preset levels to configurations */ export declare const PRESCANNER_PRESETS: Record; /** * Get a pre-scanner configuration by preset level */ export declare function getPreScannerPreset(level: PreScannerPresetLevel): PreScannerConfig; /** * Create a custom configuration by merging with a preset * All limits are automatically clamped to mandatory maximums */ export declare function createPreScannerConfig(basePreset: PreScannerPresetLevel, overrides?: PartialPreScannerConfig): PreScannerConfig; /** * Comparison table for documentation purposes. * * | Config | AgentScript | STRICT | SECURE | STANDARD | PERMISSIVE | * |---------------------|-------------|----------|----------|----------|------------| * | maxInputSize | 100KB | 500KB | 1MB | 5MB | 10MB | * | maxLineLength | 2000 | 5000 | 8000 | 10000 | 50000 | * | maxLines | 1000 | 2000 | 5000 | 10000 | 100000 | * | maxNestingDepth | 20 | 30 | 40 | 50 | 100 | * | regexMode | 'block' | 'analyze'| 'analyze'| 'analyze'| 'allow' | * | blockBidiPatterns | YES | YES | YES | NO | NO | * | blockInvisibleChars | YES | YES | NO | NO | NO | */