T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/content_automator.py:136
- Finding
- Unescaped User-Controlled Title Enables FFmpeg Filtergraph Injection## Vulnerability Details **File Location**: `scripts/content_automator.py`, lines 136–142 **Vulnerability Type**: FFmpeg filtergraph injection **Risk Level**: Medium **Vulnerable Code**: ```python ffmpeg_cmd = [ "ffmpeg", "-y", "-f", "lavfi", "-i", f"color=c=black:s=1920x1080:d={audio_duration}", "-i", str(audio_path), "-vf", f"drawtext=text='{title}':fontsize=48:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2", "-c:v", "libx264", "-preset", "fast", "-crf", "23", "-c:a", "aac", "-b:a", "128k", "-shortest", str(output_path) ] ``` ### Technical Analysis The `title` parameter is incorporated directly into an FFmpeg `-vf` filtergraph expression without escaping FFmpeg filtergraph metacharacters. For the `script` command, this value originates from the user-controlled `--title` argument and reaches `assemble_video()` at lines 222–223. Passing the command as an argument list correctly prevents conventional shell command injection. It does not, however, prevent injection into FFmpeg's own expression and filtergraph grammar. Characters such as single quotes, colons, commas, semicolons, and backslashes can terminate or modify the `drawtext` expression. FFmpeg expansion syntax may also cause unintended interpretation. An attacker who can control the title can therefore invalidate the graph or attempt to append additional filters supported by the installed FFmpeg build. The exact secondary effects depend on available FFmpeg filters, protocols, and operating-system permissions. ### Attack Path 1. An attacker supplies a crafted value through the `script --title` command-line argument. 2. `cmd_script()` passes `args.title` unchanged to `assemble_video()` at lines 222–223. 3. `assemble_video()` concatenates the value into the `drawtext` filter expression at line 139. 4. FFmpeg parses attacker-supplied metacharacters as filtergraph syntax rather than literal title text. 5. The crafted grap ...[truncated 901 chars]
- Remediation
- ## Remediation Suggestions - Do not concatenate untrusted titles directly into an FFmpeg filtergraph. - Store the title in a controlled UTF-8 temporary text file and reference it through `drawtext`'s `textfile` option. - Disable text expansion with `expansion=none` where supported and suitable. - Properly escape both the text-file path and all FFmpeg filtergraph metacharacters; argument-list execution alone is insufficient. - Apply a reasonable title-length limit and reject control characters or unsupported Unicode sequences before invoking FFmpeg. - Run FFmpeg with least privilege in a sandbox or restricted container with minimal filesystem and network access. - Restrict unnecessary FFmpeg protocols and capabilities, such as through an appropriate `-protocol_whitelist`, after verifying the protocols required by the intended workflow. - Add tests using titles containing quotes, colons, commas, semicolons, brackets, percent signs, and backslashes to verify they are rendered literally rather than parsed as filter syntax.
