T09 · Insecure Skill Coding Practices
- Location
server.py:40- Finding
Unrestricted Execution of Model-Generated Python Code
- Content
View full analysis
Vulnerability Details
File Location:
server.py:40-70
Supporting Instruction Location:SKILL.md:27-33, 109-116, 151-153
Vulnerability Type: Arbitrary code execution without isolation
Risk Level: HighVulnerable Code:
python exec_globals = { "__builtins__": __builtins__, "__name__": "__main__", "__file__": os.path.join(OUTPUT_DIR, "temp_script.py"), } original_cwd = os.getcwd() os.chdir(OUTPUT_DIR) exec(processed_code, exec_globals)The Skill instructions also require generated code to be executed automatically:
text - Generate complete, executable Python code using python-pptx - After generating the code, invoke execute_pptx_code to execute itTechnical Analysis
The
execute_pptx_codeMCP tool accepts a caller-controlledpython_codestring and passes it directly to Python's in-processexecfunction. The execution globals explicitly expose the complete__builtins__object. Consequently, executed code can import modules, invoke subprocesses, inspect environment variables, read or modify files, open network connections, terminate the process, and mutate MCP server state._preprocess_codeonly uses regular expressions to rewrite some literalprs.save()andPresentation()calls. This is not a security boundary. Code can bypass those rewrites through aliases, variables, dynamic expressions, direct filesystem APIs, imported modules, or operating-system commands. Changing the current working directory tooutputsimilarly does not restrict access to absolute paths or parent directories.The code runs inside the MCP server process rather than an isolated worker. It therefore inherits all filesystem, network, credential, and operating-system permissions granted to that process. Content supplied to an AI could also indirectly influence generated code, making prompt or document content a potential entry point.
Attack Path
- An attacker ...[truncated 1742 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove general-purpose Python execution from the MCP interface. Replace
python_codewith a structured presentation specification containing only required concepts such as slides, text, shapes, layouts, colors, and output names. - Implement presentation construction in trusted server code using
python-pptx. Validate all structured fields against strict schemas, size limits, and enumerated operations. - If arbitrary execution is an unavoidable product requirement, execute each request in a disposable container or virtual machine rather than the MCP process.
- Configure the isolation boundary with:
- A dedicated unprivileged user.
- No host credentials or environment secrets.
- Network access disabled by default.
- A read-only root filesystem.
- Explicit, narrowly scoped input and output mounts.
- CPU, memory, process-count, file-size, and execution-time limits.
- Mandatory termination and cleanup after every invocation.
- A restrictive seccomp/AppArmor/SELinux policy where supported.
- Validate output filenames independently and reject path separators, traversal sequences, control characters, and unexpected extensions.
- Do not treat restricted globals, Python AST filtering, regular-expression rewriting, or removal of selected builtins as a sufficient sandbox; Python code must be isolated at the operating-system boundary.
- Require explicit user confirmation before executing generated code until the general-purpose execution interface is removed.
- Log execution metadata without recording secrets, and monitor repeated failures, abnormal resource use, and unexpected output files.
- Remove general-purpose Python execution from the MCP interface. Replace
