T09 · Insecure Skill Coding Practices
Error
- Location
- references/core_workflow.md:33
- Finding
- Shell Command Injection Through Documented User-Content Interpolation<![CDATA[ ## Vulnerability Details **File Location**: `references/core_workflow.md:33-49`; related invocation guidance in `SKILL.md:151-153` **Vulnerability Type**: Shell command injection **Risk Level**: High ### Vulnerable Code Snippet ```markdown - **Reply 2**: Split the content into 3,000-character batches at natural sentence boundaries, and invoke `python scripts/check_sensitive_words.py --content="..."` for each batch. - **Text input**: 1. First calculate the character count. 2. If it does not exceed 3,000 characters, directly invoke `python scripts/check_sensitive_words.py --content="copy content"`. - **Text file input**: 1. Invoke `python scripts/check_sensitive_words.py --file=/path/to/file.txt --extract-only`. 2. If the returned length does not exceed 3,000, directly invoke `python scripts/check_sensitive_words.py --content="extracted content"`. - **Web address**: 1. Invoke `python scripts/check_sensitive_words.py --url=https://example.com --extract-only`. 2. If the returned length does not exceed 3,000, directly invoke `python scripts/check_sensitive_words.py --content="extracted content"`. ``` The related quick-reference instructions in `SKILL.md:151-153` likewise direct the agent to place text into a quoted `--content="..."` argument. ### Technical Analysis The workflow instructs the agent to insert attacker-controlled copy or extracted website content directly into a command-line template. If the agent executes this template through a shell, double quotes do not prevent shell command substitution. Constructs such as `$(command)` and backticks are evaluated by common POSIX shells even when they occur inside double quotes. Other shell metacharacters and crafted quoting can also alter command parsing depending on how the agent constructs the final command. The Python script itself uses `argparse` safely once started; the vulnerability occurs before Python receives the argument, during shell interpretation. ### Attack Path 1. An ...[truncated 1510 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Never construct a shell command by interpolating user-controlled text. 2. Launch the script with an argument-array process API and disable shell processing. For example: ```python subprocess.run( ["python", "scripts/check_sensitive_words.py", "--content", content], shell=False, check=True, text=True, capture_output=True, ) ``` 3. Prefer passing arbitrary content over standard input or through a securely created temporary file. This avoids command-line parsing risks and operating-system argument-length limits. 4. Update `references/core_workflow.md` and `SKILL.md` to explicitly prohibit `shell=True`, `os.system`, shell-form tool invocations, and string-built commands. 5. If only a shell-based tool interface is available, redesign the script to read content from standard input rather than relying only on `--content`. 6. Treat text extracted from files and websites as untrusted input subject to the same protections as directly supplied user content. 7. Add regression tests containing command substitutions, backticks, quotes, semicolons, newlines, and other shell metacharacters, verifying that they are passed literally and never executed. ]]>
