guard_core.detection_engine
¶ContentPreprocessor(max_content_length=10000, preserve_attack_patterns=True, agent_handler=None, correlation_id=None)
¶guard_core/detection_engine/preprocessor.pyagent_handler = agent_handler
instance-attribute
¶attack_indicators = ['<script', 'javascript:', 'on\\w+=', 'SELECT\\s+.{0,50}?\\s+FROM', 'UNION\\s+SELECT', '\\.\\./', 'eval\\s*\\(', 'exec\\s*\\(', 'system\\s*\\(', '<?php', '<%', '{{', '{%', '<iframe', '<object', '<embed', 'onerror\\s*=', 'onload\\s*=', '\\$\\{', '\\\\x[0-9a-fA-F]{2}', '%[0-9a-fA-F]{2}']
instance-attribute
¶compiled_indicators = [(re.compile(pattern, re.IGNORECASE)) for pattern in (self.attack_indicators)]
instance-attribute
¶correlation_id = correlation_id
instance-attribute
¶max_content_length = max_content_length
instance-attribute
¶preserve_attack_patterns = preserve_attack_patterns
instance-attribute
¶decode_common_encodings(content)
async
¶guard_core/detection_engine/preprocessor.pyextract_attack_regions(content)
¶guard_core/detection_engine/preprocessor.pynormalize_unicode(content)
¶guard_core/detection_engine/preprocessor.pypreprocess(content)
async
¶guard_core/detection_engine/preprocessor.pypreprocess_batch(contents)
async
¶remove_excessive_whitespace(content)
¶remove_null_bytes(content)
¶guard_core/detection_engine/preprocessor.pytruncate_safely(content)
¶guard_core/detection_engine/preprocessor.pyPatternCompiler(default_timeout=5.0, max_cache_size=1000)
¶guard_core/detection_engine/compiler.pyMAX_CACHE_SIZE = 1000
class-attribute
instance-attribute
¶default_timeout = default_timeout
instance-attribute
¶max_cache_size = min(max_cache_size, 5000)
instance-attribute
¶batch_compile(patterns, validate=True)
async
¶guard_core/detection_engine/compiler.pyclear_cache()
async
¶compile_pattern(pattern, flags=re.IGNORECASE | re.MULTILINE)
async
¶guard_core/detection_engine/compiler.pycompile_pattern_sync(pattern, flags=re.IGNORECASE | re.MULTILINE)
¶create_safe_matcher(pattern, timeout=None)
¶guard_core/detection_engine/compiler.pyvalidate_pattern_safety(pattern, test_strings=None)
¶guard_core/detection_engine/compiler.pyPerformanceMonitor(anomaly_threshold=3.0, slow_pattern_threshold=0.1, history_size=1000, max_tracked_patterns=1000)
¶guard_core/detection_engine/monitor.pyanomaly_callbacks = []
instance-attribute
¶anomaly_threshold = max(1.0, min(10.0, float(anomaly_threshold)))
instance-attribute
¶history_size = max(100, min(10000, int(history_size)))
instance-attribute
¶max_tracked_patterns = max(100, min(5000, int(max_tracked_patterns)))
instance-attribute
¶pattern_stats = {}
instance-attribute
¶recent_metrics = deque(maxlen=history_size)
instance-attribute
¶slow_pattern_threshold = max(0.01, min(10.0, float(slow_pattern_threshold)))
instance-attribute
¶clear_stats()
async
¶get_pattern_report(pattern)
¶guard_core/detection_engine/monitor.pyget_problematic_patterns()
¶guard_core/detection_engine/monitor.pyget_slow_patterns(limit=10)
¶guard_core/detection_engine/monitor.pyget_summary_stats()
¶guard_core/detection_engine/monitor.pyrecord_metric(pattern, execution_time, content_length, matched, timeout=False, agent_handler=None, correlation_id=None)
async
¶guard_core/detection_engine/monitor.pyregister_anomaly_callback(callback)
¶SemanticAnalyzer()
¶guard_core/detection_engine/semantic.pyattack_keywords = {'xss': {'script', 'javascript', 'onerror', 'onload', 'onclick', 'onmouseover', 'alert', 'eval', 'document', 'cookie', 'window', 'location'}, 'sql': {'select', 'union', 'insert', 'update', 'delete', 'drop', 'from', 'where', 'order', 'group', 'having', 'concat', 'substring', 'database', 'table', 'column'}, 'command': {'exec', 'system', 'shell', 'cmd', 'bash', 'powershell', 'wget', 'curl', 'nc', 'netcat', 'chmod', 'chown', 'sudo', 'passwd'}, 'path': {'etc', 'passwd', 'shadow', 'hosts', 'proc', 'boot', 'win', 'ini'}, 'template': {'render', 'template', 'jinja', 'mustache', 'handlebars', 'ejs', 'pug', 'twig'}}
instance-attribute
¶attack_structures = {'tag_like': '<[^>]+>', 'function_call': '\\w+\\s*\\([^)]*\\)', 'command_chain': '[;&|]{1,2}', 'path_traversal': '\\.{2,}[/\\\\]', 'url_pattern': '[a-z]+://'}
instance-attribute
¶suspicious_chars = {'brackets': '[<>{}()\\[\\]]', 'quotes': '[\'\\"`]', 'slashes': '[/\\\\]', 'special': '[;&|$]', 'wildcards': '[*?]'}
instance-attribute
¶analyze(content)
¶guard_core/detection_engine/semantic.pyanalyze_attack_probability(content)
¶guard_core/detection_engine/semantic.pyanalyze_code_injection_risk(content)
¶guard_core/detection_engine/semantic.pycalculate_entropy(content)
¶guard_core/detection_engine/semantic.pydetect_encoding_layers(content)
¶guard_core/detection_engine/semantic.pydetect_obfuscation(content)
¶guard_core/detection_engine/semantic.pyextract_suspicious_patterns(content)
¶guard_core/detection_engine/semantic.pyextract_tokens(content)
¶guard_core/detection_engine/semantic.pyget_threat_score(analysis_results)
¶guard_core/detection_engine/semantic.py