T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:197
- Finding
- Shell Command Injection Through Untrusted URL and File-Path Interpolation<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:197-199`; related unsafe filesystem commands appear at `SKILL.md:252-253`, `SKILL.md:270-271`, and `SKILL.md:287` **Vulnerability Type**: Command injection and unsafe filesystem command construction **Risk Level**: High ### Vulnerable Code ```markdown | YouTube | Bash: `yt-dlp --write-auto-sub --sub-lang "en" --skip-download --print title --print description -o "/tmp/yt-%(id)s" "{url}"` then Read the `.vtt` file and clean it (see transcript cleaning below) | | Local file | `Read(filepath)` | | Audio | Bash: `whisper "{path}" --output_format txt` if available; otherwise note as placeholder | ``` Related command templates: ```markdown c. Move raw file: Bash `mv unsorted/raw/{filename} {category}/raw/{filename}`. d. Move summary file: Bash `mv unsorted/summary/{filename} {category}/summary/{filename}`. ``` ```markdown 4. Move raw and summary files via Bash `mv`. 5. Delete the old empty category directory via Bash `rm -r` after confirming it is empty. ``` ```markdown 1. Rename directory via Bash `mv`. ``` ### Technical Analysis The Skill instructs the agent to construct shell commands by inserting URLs, local paths, filenames, and category names directly into Bash command text. These values can originate from user input or attacker-controlled imported directory structures. The `mv` examples do not quote their operands. Consequently, whitespace, wildcard characters, shell metacharacters, redirection operators, or option-like filenames can change the meaning of the command. Even the quoted URL and audio-path placeholders are unsafe if the agent performs literal textual substitution without robust shell escaping. Embedded quotes or shell substitutions may terminate or alter the intended argument. The templates also fail to: - Insert `--` before file operands to stop option parsing. - Canonicalize and constrain paths to the configured knowledge-base directory. - Reject control characters or she ...[truncated 1904 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not construct shell command strings containing user-controlled values. 2. Invoke `yt-dlp` and `whisper` through a process API that accepts an executable and a separate argument array. 3. Replace shell-based `mv`, directory creation, and deletion with native filesystem APIs. 4. If a shell is unavoidable: - Apply context-appropriate escaping to every dynamic operand. - Place `--` before path operands. - Reject null bytes, control characters, newlines, and shell metacharacters. - Never concatenate multiple operations into one command. 5. Resolve every source and destination to a canonical absolute path and verify that applicable write, move, and deletion targets remain beneath the configured knowledge-base root. 6. Restrict category slugs to a conservative allowlist such as `^[a-z0-9]+(?:-[a-z0-9]+)*$`. 7. Treat imported filenames as opaque data; generate safe internal filenames rather than reusing untrusted names in shell commands. 8. Before deletion, verify through a filesystem API that the directory is empty, is not a symbolic link, and remains inside the expected root. 9. Use securely created per-operation temporary directories instead of predictable `/tmp/yt-*` paths, and remove them through native APIs. ]]>
