T09 · Insecure Skill Coding Practices
- Location
scripts/ai_worker.py:274- Finding
Unrestricted Execution of Database-Supplied Python Test Code
- Content
View full analysis
Vulnerability Details
File Location:
scripts/ai_worker.py, lines 274-291
Vulnerability Type: Arbitrary code execution through untrusted test content
Risk Level: HighVulnerable Code
python test_code = ut.get('test_code', '') if tool_name == "python3" or tool_name == "python": return self._run_python_test(test_code, project_dir) elif tool_name == "moon": return self._run_moon_test(project_dir) else: return True def _run_python_test(self, test_code: str, project_dir: str) -> bool: """Run Python tests""" try: result = subprocess.run( ["python3", "-c", test_code], cwd=project_dir, capture_output=True, text=True, timeout=30 ) return result.returncode == 0 except Exception as e: print(f" Python test exception: {e}") return FalseTechnical Analysis
The worker retrieves
test_codedirectly from the SQLiteunit_teststable and supplies it to a full Python interpreter throughpython3 -c. The subprocess is not isolated and inherits the invoking user's operating-system privileges, environment, filesystem access, and network capabilities.The timeout limits execution duration but does not restrict the operations the test can perform. There is no test-content validation, human approval boundary, sandbox, network restriction, filesystem allowlist, reduced-privilege account, or process-level containment.
Executing tests is consistent with the declared functionality, but executing database-controlled tests with unrestricted host privileges exceeds the minimum privileges necessary. AI-generated tests, imported databases, or locally modified database records therefore become arbitrary code-execution channels.
Attack Path
- An attacker or compromised generation process inserts malicious Python into
unit_tests.test_code. - The associated M ...[truncated 1383 chars]
- An attacker or compromised generation process inserts malicious Python into
- Remediation
View remediation
Remediation Suggestions
- Execute generated tests in an ephemeral sandbox or container rather than directly on the host.
- Use a dedicated unprivileged account with no access to user credentials or unrelated projects.
- Disable network access by default and permit it only through an explicit, documented policy.
- Mount only the required project files, preferably read-only except for a dedicated temporary output directory.
- Remove secrets and unnecessary variables from the subprocess environment.
- Apply CPU, memory, process-count, file-size, and execution-time limits.
- Require explicit human approval before executing newly generated or externally supplied test code.
- Record the test-content hash and approval identity so the approved code can be verified immediately before execution.
- Treat the SQLite database as a sensitive executable-content store and restrict its filesystem permissions.
- Do not rely on source-text filtering as the primary defense; Python code cannot be safely sandboxed using a simple import or keyword denylist.
