Basic Usage
Why Pre-Scanning?
The JavaScript parser itself can be vulnerable to:- Memory exhaustion - Extremely large files
- Stack overflow - Deeply nested expressions
- CPU exhaustion - Complex regex patterns
- Parsing hangs - Malformed Unicode sequences
Mandatory Limits
These limits protect against parser crashes and cannot be overridden:| Limit | Maximum | Purpose |
|---|---|---|
ABSOLUTE_MAX_INPUT_SIZE | 100MB | Prevents memory exhaustion |
ABSOLUTE_MAX_NESTING | 200 levels | Prevents parser stack overflow |
ABSOLUTE_MAX_LINE_LENGTH | 100,000 chars | Prevents minified/obfuscated DoS |
ABSOLUTE_MAX_LINES | 1,000,000 | Prevents extremely long files |
ABSOLUTE_MAX_STRING | 5MB | Prevents huge embedded strings |
ABSOLUTE_MAX_REGEX_LENGTH | 1,000 chars | Prevents ReDoS via complex patterns |
Pre-Scanner Presets
| Config | AgentScript | STRICT | SECURE | STANDARD | PERMISSIVE |
|---|---|---|---|---|---|
| maxInputSize | 100KB | 500KB | 1MB | 5MB | 10MB |
| maxLineLength | 2,000 | 5,000 | 8,000 | 10,000 | 50,000 |
| maxLines | 1,000 | 2,000 | 5,000 | 10,000 | 100,000 |
| maxNestingDepth | 20 | 30 | 40 | 50 | 100 |
| regexMode | block | analyze | analyze | analyze | allow |
| blockBidiPatterns | YES | YES | YES | NO | NO |
| blockInvisibleChars | YES | YES | NO | NO | NO |
Using Presets
Regex Handling Modes
The pre-scanner supports three regex handling modes:Block Mode
Block ALL regex literals (AgentScript default, maximum security):Analyze Mode
Allow regex but analyze for ReDoS patterns:Allow Mode
Allow all regex without analysis (Permissive only):ReDoS Detection
The pre-scanner detects dangerous regex patterns that cause exponential backtracking:| Pattern | Score | Example | Risk |
|---|---|---|---|
| Nested quantifier | 90 | (a+)+ | Exponential backtracking |
| Star in repetition | 85 | (a+){2,} | Exponential backtracking |
| Repetition in star | 85 | (a{2,})+ | Exponential backtracking |
| Overlapping alternation | 80 | (a|ab)+ | Exponential backtracking |
| Greedy backtracking | 75 | (.*a)+ | Polynomial backtracking |
| Multiple greedy | 70 | .*foo.*bar | Polynomial backtracking |
Manual ReDoS Analysis
Unicode Security
The pre-scanner detects Unicode-based attacks:Bidirectional Text (Trojan Source)
Invisible Characters
Custom Configuration
Related
- Overview - Getting started with ast-guard
- AgentScript Preset - LLM code validation
- Security Rules - AST validation rules