T09 · Insecure Skill Coding Practices
- Location
references/code-templates.md:400- Finding
Unrestricted Model-Controlled Shell Execution with Bypassable Command Filtering
- Content
View full analysis
Vulnerability Details
File Location:
references/code-templates.md:400-415,references/code-templates.md:759-770, andreferences/code-templates.md:944-953
Vulnerability Type: Command injection through unrestricted shell execution
Risk Level: HighVulnerable Code:
python class BashTool(BaseTool): name = "bash" description = "Execute a shell command and return output" parameters = BashParams async def execute(self, p: BashParams) -> str: try: r = subprocess.run( p.command, shell=True, capture_output=True, text=True, timeout=p.timeout ) except subprocess.TimeoutExpired: return f"Command timed out after {p.timeout}s" out = r.stdout or "" if r.stderr: out += f"\nSTDERR:\n{r.stderr}"python def setup_security(api: ExtensionAPI): @api.on("authorize_tool_call") async def block_dangerous(event: ToolCallEvent, ctx): if event.name == "bash": cmd = event.arguments.get("command", "") dangerous = ["rm -rf /", "rm -rf ~", "sudo rm", ":(){:|:&};:"] for pattern in dangerous: if pattern in cmd: return ToolCallResult( blocked=True, reason=f"Blocked dangerous command: {pattern}", ) return None # Do not blockpython tools = ToolRegistry() for t in (ReadTool(), WriteTool(), EditTool(), BashTool(), GrepTool(), FindTool(), LsTool()): tools.register(t) session = Session.create_new() compaction = CompactionStrategy(max_tokens=200_000, summariser=provider) agent = Agent(provider=provider, tools=tools, session=session, compaction=compaction)Technical Analysis
BashToolpasses an entirely model-controlled string tosubprocess.run()withshell=True. ...[truncated 2147 chars]- Remediation
View remediation
Remediation Suggestions
- Run shell operations inside an operating-system sandbox or isolated container by default.
- Restrict writable paths to a canonical workspace root and deny access to host credentials, configuration directories, device files, and system paths.
- Disable network access by default and grant it only for explicitly approved tasks.
- Avoid
shell=True. Prefer a structured executable and argument array, with strict validation of the executable and each argument. - Maintain an allowlist of permitted commands and operations rather than a blacklist of dangerous substrings.
- Require explicit user approval for commands that mutate state, invoke interpreters, install software, access the network, or cross workspace boundaries.
- Apply resource controls for execution time, total tool runtime, process count, memory, output size, and child processes.
- Record shell calls, approval decisions, normalized arguments, results, and durations in a protected audit log.
- Treat repository files and tool output as untrusted data and ensure they cannot override authorization policy.
