kodeagent.pattern_detector#
Advanced AST-based security pattern detection. This provides a static analysis layer to catch malicious patterns that might bypass LLM review.
Perform AST-based pattern analysis on code. |
|
Detects suspicious patterns in Python code using AST analysis. |
Advanced AST-based security pattern detection. This provides a static analysis layer to catch malicious patterns that might bypass LLM review.
- class kodeagent.pattern_detector.SecurityPatternDetector[source]#
Bases:
NodeVisitorDetects suspicious patterns in Python code using AST analysis. This acts as a backup to LLM-based security review.
The following patterns are detected: - Dangerous builtins (exec, eval, compile, __import__) - Potential obfuscation (base64/hex decoding) - System command execution (subprocess, os.system) - Environment variable access - Infinite loops - Path traversal
Initialize the detector.
- kodeagent.pattern_detector.analyze_code_patterns(code: str) tuple[bool, str, int][source]#
Perform AST-based pattern analysis on code.
- Parameters:
code – Python source code to analyze
- Returns:
Tuple of (is_safe, reason, risk_score) - is_safe: False if critical violations found - reason: Description of violations - risk_score: Numeric risk score (0-100)