T09 · Insecure Skill Coding Practices
- Location
scripts/transcribe.sh:47- Finding
Remote video title enables Python code injection
- Content
View full analysis
/dev/null || echo "") fi ``` ```bash if [ -n "$TITLE" ]; then SAFE_TITLE=$(sanitize "$TITLE") FILE_BASE="${VIDEO_ID}_${SAFE_TITLE}" echo " Title: $TITLE" fi ``` ```bash if [ -n "$META_JSON" ] && [ "$META_JSON" != "{}" ]; then echo "$META_JSON" | python3 -c " import sys, json d = json.load(sys.stdin) out = { 'bvid': d.get('id',''), 'title': d.get('title',''), 'uploader': d.get('uploader',''), 'uploader_id': d.get('uploader_id',''), 'description': d.get('description',''), 'duration': d.get('duration',0), 'upload_date': d.get('upload_date',''), 'view_count': d.get('view_count',0), 'like_count': d.get('like_count',0), 'tags': d.get('tags',[]), 'url': d.get('webpage_url',''), 'filename_base': '$FILE_BASE' } json.dump(out, sys.stdout, ensure_ascii=False, indent=2) " > "$OUT_DIR/${FILE_BASE}.meta.json" 2>/dev/null fi ``` ### Technical Analysis The video title is obtained from remotely controlled `yt-dlp` metadata and incorporated into `FILE_BASE`. The `sanitize` function only removes characters considered invalid in filenames: ```bash sanitize() { echo "$1" | sed 's/[\/\\:*?"<>|]/_/g' | sed 's/ */ /g' | head -c 120 } ``` It does not remove or encode apostrophes, semicolons, newlines, or other Python syntax. The resulting value is interpolated directly into a dynamically constructed `python3 -c` program: ```python 'filename_base': '$FILE_BASE' ``` A malicious title containing an apostrophe can terminate this Python string literal and introduce additional Python statements or expressions. Those statements execute under the identity ...[truncated 1490 chars]- Remediation
View remediation
"$OUT_DIR/${FILE_BASE}.meta.json" ``` Additional hardening should include: 1. Use `printf '%s'` instead of `echo` when processing arbitrary metadata. 2. Normalize or reject control characters and newlines in filenames. 3. Apply an explicit filename allowlist and deterministic length limit. 4. Test titles containing quotes, newlines, shell metacharacters, and Unicode control characters. 5. Run media-processing scripts in a restricted environment without unnecessary credentials or write access. ]]>
