T09 · Insecure Skill Coding Practices
Error
- Location
- core/dynamic_tracer.py:34
- Finding
- Dynamic analysis executes untrusted code without enforcing resource limits or a timeout<![CDATA[ ## Vulnerability Details **File Location**: `core/dynamic_tracer.py:34-35, 48-55, 73-83, 115-129` **Vulnerability Type**: Uncontrolled execution of untrusted code **Risk Level**: High ### Vulnerable Code ```python def __init__(self, timeout: float = 5.0): self.timeout = timeout self.trace = ExecutionTrace() ``` ```python # Check if code is safe to attempt execution if not self._is_safe_to_execute(code): findings.append(Finding( level=RiskLevel.MEDIUM, category="dynamic_analysis_skipped", description="Code contains constructs unsafe for dynamic analysis", file=str(file_path), line=0, confidence=0.7, )) return findings ``` ```python # Execute in sandbox exec(compiled, restricted_globals) self.trace.completed = True ``` ```python def _is_safe_to_execute(self, code: str) -> bool: """Quick check if code looks safe to execute""" dangerous_patterns = [ "while True:", # Infinite loops "__import__", "eval(", "exec(", ] code_lower = code.lower() for pattern in dangerous_patterns: if pattern in code_lower: return False return True ``` ### Technical Analysis The scanner performs in-process execution of Python files supplied by an untrusted Skill. Although the constructor accepts a five-second timeout, `self.timeout` is never used to interrupt or terminate execution. The safety check is a substring denylist rather than a resource-control boundary. It only detects a few exact textual forms. Equivalent resource-exhaustion constructs such as `while 1:`, computationally expensive loops, deep recursion, or memory-intensive expressions are not rejected. RestrictedPython constrains access to selected Python operations, but it does not independently enforce wall-clock, CPU, or memory limits. Because execution occurs synchronously in the scanner process, a resource-exhaustion payload can hang or terminate the security tool ...[truncated 1197 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not execute untrusted Skill code inside the main scanner process. - Move each dynamic-analysis job into a disposable child process, container, or sandboxed virtual machine. - Enforce a real wall-clock timeout and forcibly terminate the entire child process tree when it expires. - Apply operating-system CPU, address-space, process-count, and open-file limits. - Disable networking and provide a read-only or disposable filesystem. - Run the worker under a dedicated, unprivileged account with no access to user credentials or sensitive environment variables. - Default to static analysis unless the user explicitly enables dynamic execution after receiving a clear warning. - Treat timeout, memory-limit, or sandbox failures as security findings rather than silently continuing. - Add regression tests covering alternate infinite loops, recursion, large allocations, process termination, and timeout cleanup. ]]>
