T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/with_server.py:69
- Finding
- Shell Command Injection Through User-Controlled Server Command## Vulnerability Details **File Location**: `scripts/with_server.py`, lines 69–74 **Vulnerability Type**: OS command injection through unsafe shell invocation **Risk Level**: High ### Vulnerable Code ```python # Use shell=True to support commands with cd and && process = subprocess.Popen( server['cmd'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) ``` ### Technical Analysis The value supplied through the repeatable `--server` command-line argument is passed directly to `subprocess.Popen` with `shell=True`. Consequently, the system shell interprets the entire value, including command separators, redirections, substitutions, pipelines, and other shell syntax. Arbitrary server command execution is part of the utility's declared functionality. Nevertheless, this implementation lacks a security boundary between an intended executable and additional shell operations. It becomes exploitable when an agent or wrapper constructs `--server` from untrusted repository content, browser content, configuration, or task input. The explicit support for `cd ... && ...` does not require exposing unrestricted shell interpretation; a working directory can instead be passed through `cwd`, while the executable and its arguments can be supplied as an argument array. ### Attack Path 1. An attacker places a crafted server command in repository documentation, configuration, test instructions, or other content that may influence an automated agent. 2. The agent uses that value as the `--server` argument to `scripts/with_server.py`. 3. The script assigns the argument to `server['cmd']`. 4. `subprocess.Popen(..., shell=True)` forwards the complete string to the operating-system shell. 5. The shell interprets attacker-supplied operators or substitutions and executes unintended commands alongside or instead of the development server. 6. Those commands run with the same operating-system identity ...[truncated 715 chars]
- Remediation
- ## Remediation Suggestions 1. Remove `shell=True` and execute commands as explicit argument arrays with `shell=False`. 2. Add a dedicated `--cwd` option rather than supporting `cd DIRECTORY && COMMAND` through shell syntax. 3. Define server commands using a structured format containing the executable, arguments, and working directory. For example: ```python process = subprocess.Popen( server_argv, shell=False, cwd=server_cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) ``` 4. Never construct executable arguments from browser DOM content, remote responses, repository instructions, or other untrusted text without validation and explicit user approval. 5. If shell syntax must be retained for compatibility, make it an explicit opt-in mode, clearly warn that it grants arbitrary command execution, and require confirmation before running commands derived from external or project-controlled content. 6. Where practical, validate executables against an allowlist appropriate to the testing environment and run the utility in a restricted account or sandbox with minimal filesystem, credential, and network access.
