T09 · Insecure Skill Coding Practices
- Location
video_transition.py:251- Finding
Predictable Temporary Manifest Enables File Clobbering and FFmpeg Concat-List Injection
- Content
View full analysis
str: """简单合并视频(无转场)""" list_file = os.path.join(os.path.dirname(output_path), "video_list.txt") with open(list_file, 'w', encoding='utf-8') as f: for path in video_paths: f.write(f"file '{os.path.abspath(path)}'\n") cmd = [ "ffmpeg", "-y", "-f", "concat", "-safe", "0", "-i", list_file, "-c:v", "libx264", "-c:a", "aac", output_path ] subprocess.run(cmd, check=True, capture_output=True, encoding='utf-8', errors='replace') os.remove(list_file) return output_path ``` ### Technical Analysis The fallback concatenation routine creates its manifest using the fixed filename `video_list.txt` in the output directory. It opens that path with overwrite semantics without verifying whether it already exists or is a symbolic link. If an attacker can modify the selected output directory, they can create `video_list.txt` as a symbolic link to another file writable by the process. Opening the manifest then follows the link and truncates or overwrites the target. The final `os.remove()` removes the manifest path or symbolic link, while the linked target remains corrupted. The routine also embeds absolute input paths directly into FFmpeg concat-demuxer syntax: ```python f.write(f"file '{os.path.abspath(path)}'\n") ``` Single quotes and line breaks in a supplied filename are not escaped or rejected. A crafted path can therefore terminate the intended `file` directive and add further concat-manifest directives. The use of `-safe 0` disables FFmpeg's safe-path restrictions, increasing the range of paths the injected manifest can reference. The issue is reachable directly through `concat_sim ...[truncated 2074 chars]- Remediation
View remediation
