T09 · Insecure Skill Coding Practices
- Location
scripts/download_video.py:268- Finding
Path Traversal Through an Untrusted Creator Name
- Content
View full analysis
|]', "_", title) save_path = AUDIO_DIR / blogger / f"{video_id}.m4a" ``` ### Technical Analysis The creator nickname originates in remotely obtained MediaCrawler data and is propagated into the cleaned CSV as the `博主` field. `download_video.py` then uses this field directly as a filesystem path component. The code sanitizes the title into `safe_title`, but that sanitized value is not used when constructing `save_path`. The creator name is neither sanitized nor checked for absolute paths, parent-directory components, path separators, or containment under `AUDIO_DIR`. With `pathlib`, an absolute right-hand operand can replace the preceding base path. Relative values containing `..` can escape the intended directory after path resolution. The destination is later created and passed to ffmpeg, which is invoked with `-y` and can overwrite an existing destination. ### Attack Path 1. An attacker controls a creator nickname returned through the scraped data, or supplies a crafted cleaned CSV. 2. The nickname contains an absolute path or traversal sequence, such as `../../outside`. 3. The ...[truncated 853 chars]- Remediation
View remediation
str: value = re.sub(r'[\\/:*?"<>|]', "_", value).strip() value = value.replace("..", "_") return value[:100] or "unknown_creator" safe_blogger = safe_component(blogger) save_path = (AUDIO_DIR / safe_blogger / f"{video_id}.m4a").resolve() audio_root = AUDIO_DIR.resolve() if save_path.parent != audio_root and audio_root not in save_path.parents: raise ValueError("Audio destination escapes AUDIO_DIR") ``` - Validate and sanitize `video_id` as well, preferably requiring the expected numeric Douyin identifier format. - Consider disabling unconditional ffmpeg overwrite behavior or requiring explicit confirmation before replacing an existing file. - Apply equivalent containment checks to subtitle, CSV, model, and summary destinations. ]]>
