T09 · Insecure Skill Coding Practices
- Location
video_pipeline.py:43- Finding
Shell Command Injection Through User-Controlled Video Path
- Content
View full analysis
Vulnerability Details
File Location:
video_pipeline.py, lines 43–50 and 79–81
Vulnerability Type: OS command injection caused by unsafe shell invocation
Risk Level: HighVulnerable Code
python def run_command(cmd, desc="", timeout=300): """Execute a command and record elapsed time.""" print(f"\n{'='*50}") print(f"Executing: {desc}") print(f"Command: {cmd[:100]}...") print('='*50) start = time.time() result = subprocess.run( cmd, shell=True, capture_output=True, text=True, timeout=timeout )python audio_path = "/tmp/video_audio.wav" cmd_extract = ( f'ffmpeg -i "{video_path}" -vn -acodec pcm_s16le ' f'-ar 16000 -ac 1 "{audio_path}" -y' ) run_command(cmd_extract, "Extract audio")Technical Analysis
VIDEO_PATHoriginates from a command-line argument or interactive user input and is passed tostep1_transcribe()without validation. The value is directly interpolated into a command string that is executed withshell=True.Wrapping the input in double quotes does not make it safe. An attacker can include a double quote followed by shell operators, command substitution, or another shell construct to terminate the intended argument and append an arbitrary command.
This is a direct command-injection boundary: untrusted data is converted into executable shell syntax rather than being passed to FFmpeg as an isolated argument.
Attack Path
- An attacker supplies a crafted value as the first command-line argument or interactive video path.
- The value contains syntax that closes the quoted FFmpeg input argument and introduces an additional shell command.
cmd_extractincorporates that syntax without escaping or validation.run_command()invokes the command through/bin/shbecauseshell=Trueis enabled.- The injected command executes with the same oper ...[truncated 624 chars]
- Remediation
View remediation
Remediation Suggestions
Remove shell interpretation and pass every command argument as a separate list element:
python def run_command(args, desc="", timeout=300): result = subprocess.run( args, shell=False, check=True, capture_output=True, text=True, timeout=timeout, ) return result.stdout run_command( [ "ffmpeg", "-i", video_path, "-vn", "-acodec", "pcm_s16le", "-ar", "16000", "-ac", "1", audio_path, "-y", ], "Extract audio", )Additionally:
- Validate that the input path points to an expected regular video file.
- Reject unexpected file types where the workflow has a strict format requirement.
- Do not attempt to solve shell injection only through manual quoting or escaping.
- Avoid logging complete user-supplied command strings.
- Run media-processing workers with minimal filesystem and network privileges.
