T09 · Insecure Skill Coding Practices
- Location
scripts/anime_drama_pipeline.py:44- Finding
Shell Command Injection Through Story Content, Configuration, and File Paths
- Content
View full analysis
- Remediation
View remediation
0 and args[i - 1] == "--api-key" else value for i, value in enumerate(args) ] print(f"[CMD] {redacted}", file=sys.stderr) return subprocess.run( args, shell=False, capture_output=True, text=True, timeout=timeout, check=False, ) ``` 2. Construct RunningHub invocations without shell interpolation: ```python cmd = [ "python3", os.path.expanduser(RH_SCRIPT_APP), "--run", IMG_APP_ID, "--node", f"12:value={enhanced_prompt}", "-o", str(output_path), "--api-key", API_KEY, ] result = run(cmd, timeout=300, check=False) ``` 3. Invoke FFmpeg using an argument list: ```python cmd = [ "ffmpeg", "-y", "-f", "concat", "-safe", "0", "-i", str(list_file), "-c:v", "libx264", "-pix_fmt", "yuv420p", "-vf", "scale=1080:1920:force_original_aspect_ratio=decrease," "pad=1080:1920:(ow-iw)/2:(oh-ih)/2:black", str(output_path), ] ``` 4. Validate application IDs against the exact format accepted by RunningHub. 5. Resolve and validate output paths before use. If output must remain under an approved directory, enforce this after canonicalization. 6. Treat external helper output as untrusted. Validate returned paths and confirm that they identify expected regular files. 7. Add regression tests containing spaces, quotes, semicolons, backticks, and command-substitution syntax to verify that these values are passed only as literal arguments. ]]>
