Expand description
Input validation and path safety utilities for Contracts & Flow commands.
This module provides security-focused validation functions to mitigate:
- TIGER-02: Path traversal attacks via malicious file paths
- TIGER-03: Unbounded recursion in CFG/slice computation
- TIGER-04: Memory exhaustion from large SSA graphs
- TIGER-08: Stack overflow from deeply nested ASTs
All file paths are canonicalized and checked against project boundaries. Resource limits are enforced to prevent denial-of-service conditions.
Constants§
- MAX_
AST_ DEPTH - Maximum AST traversal depth (TIGER-08 mitigation). Prevents stack overflow from deeply nested source code.
- MAX_
CFG_ DEPTH - Maximum CFG/slice recursion depth (TIGER-03 mitigation). Prevents stack overflow from deeply recursive control flow analysis.
- MAX_
CONDITIONS_ PER_ FUNCTION - Maximum number of conditions to report per function.
- MAX_
FILE_ SIZE - Maximum file size for analysis (10 MB). Files larger than this will be rejected (TIGER-04 partial mitigation).
- MAX_
FUNCTION_ NAME_ LEN - Maximum function name length.
- MAX_
SSA_ NODES - Maximum SSA nodes to construct (TIGER-04 mitigation). Prevents memory exhaustion from extremely large SSA graphs.
- WARN_
FILE_ SIZE - Warning threshold for file size (1 MB). Files larger than this emit a warning but are still processed.
Functions§
- check_
ast_ depth - Check if AST depth exceeds limit.
- check_
depth_ limit - Check if a depth limit has been exceeded.
- check_
ssa_ node_ limit - Check if SSA node count exceeds limit.
- has_
path_ traversal_ pattern - Check if a path contains path traversal patterns.
- read_
file_ safe - Safely read a file with size limits and UTF-8 validation.
- read_
file_ safe_ with_ warning - Read a file safely, emitting a warning for large files.
- validate_
file_ path - Validate and canonicalize a file path.
- validate_
file_ path_ in_ project - Validate a file path ensuring it stays within a project root.
- validate_
function_ name - Validate a function name for safety.
- validate_
line_ numbers - Validate line number range.