T09 · Insecure Skill Coding Practices
- Location
SKILL.md:55- Finding
MPV Option Injection Through User-Supplied Media Arguments
- Content
View full analysis
"`. - If user gives search text, run: - `yt-dlp --print "%(title)s | Duration: %(duration_string)s | Uploaded: %(upload_date>%Y-%m-%d)s | https://youtu.be/%(id)s" "ytsearch5:"` - Search output includes title, duration, upload date, and URL; prefer newest or user-confirmed result when ambiguity exists. ### YouTube Playback Command Contract - Required binaries: `yt-dlp` and `mpv`. - On missing binary, return a clear install hint and run dependency initialization: - `Error: yt-dlp not found. Install with: sudo apt install yt-dlp` - `Error: mpv not found. Install with: sudo apt install mpv` - If user provides a specific list of URLs, queue all in order with one command: - `mpv --no-video "" "" "" ...` - If user requests a specific list but provides titles/queries, resolve each item and queue in order: - `yt-dlp -f bestaudio -g "ytsearch1:"` ... `yt-dlp -f bestaudio -g "ytsearch1:"` - then `mpv --no-video "" "" ...` ``` The related sanitization requirement at `SKILL.md`, line 131, only removes selected shell metacharacters: ```markdown - **Input sanitisation**: before interpolating any user-supplied text into a shell command, strip shell metacharacters (`` ` ``, `$`, `(`, `)`, `{`, `}`, `|`, `;`, `&`, `<`, `>`, `\`, `'`, `"`) to prevent command injection. ``` ### Technical Analysis The documented commands pass user-supplied URLs directly to `mpv` without an option terminator. Shell quoting prevents whitespace splitting and ordinary shell metacharacter interpretation, but it does not prevent the invoked program from interpreting an argument beginning with `-` or `--` as a command-line option. Consequently, an input s ...[truncated 2136 chars]- Remediation
View remediation
" ``` For queues: ```bash mpv --no-video -- "" "" "" ``` 3. Apply the same validation to stream URLs returned by `yt-dlp`, even though those values are normally tool-generated. 4. Avoid blacklist-based sanitization as the primary defense. Preserve legitimate URL characters while enforcing expected structure and invoking commands through an argument-array API rather than a shell where supported. 5. Add regression tests covering: - `--script=/path/file.lua` - `--config-dir=/path` - `-v` - URLs containing spaces or shell metacharacters - Valid HTTP and HTTPS media URLs 6. Run MPV with the least-privileged account practical and restrict access to sensitive local files to reduce impact if another MPV option-handling issue is discovered. ]]>
