T09 · Insecure Skill Coding Practices
- Location
seedance.py:242- Finding
macOS Command Injection Through User-Controlled Download Path
- Content
View full analysis
Vulnerability Details
File Location:
seedance.py, lines 242–255
Vulnerability Type: OS command injection
Risk Level: Highpython if download_dir and video_url: download_path = Path(download_dir).expanduser() download_path.mkdir(parents=True, exist_ok=True) filename = f"seedance_{task_id}_{int(time.time())}.mp4" filepath = download_path / filename print(f"\nDownloading video to {filepath}...") try: urllib.request.urlretrieve(video_url, str(filepath)) print(f"Saved to: {filepath}") # Open on macOS if sys.platform == "darwin": os.system(f'open "{filepath}"')Technical Analysis
The
download_dirvalue originates from the user-controlled--downloadcommand-line argument. It becomes part offilepath, which is interpolated directly into a command passed toos.system().os.system()invokes a shell. Enclosing the path in double quotes does not neutralize all shell syntax: command substitution such as$(...)remains active inside double quotes, and embedded quote characters can alter the command structure. Consequently, a crafted download directory can introduce shell commands.The vulnerable call is reached only on macOS and after a video has been downloaded successfully. The Base64 processing elsewhere in the file is not itself malicious: it encodes a user-selected local image into a data URL for submission to the declared Volcengine Ark video-generation API.
Attack Path
- An attacker influences the value supplied to the CLI's
--downloadoption. - The value contains shell-interpreted syntax, such as command substitution, while still representing a creatable directory path.
- The Skill submits or waits for a video-generation task.
- The remote task succeeds and returns a video URL.
- The tool downloads the video into the attacker-influenced path.
- On macOS, the tool constructs
open "<filepath>"and passes it toos.system(). - The shell ev ...[truncated 667 chars]
- An attacker influences the value supplied to the CLI's
- Remediation
View remediation
Remediation Suggestions
Replace the shell invocation with an argument-vector API that does not perform shell parsing:
python import subprocess if sys.platform == "darwin": subprocess.run(["open", str(filepath)], check=False)Additional hardening measures:
- Avoid
os.system(),shell=True, and string-built shell commands for all path handling. - Resolve the requested output directory and, where appropriate, restrict it to an approved workspace root.
- Reject output paths containing NUL characters and handle path errors explicitly.
- Consider making automatic opening opt-in rather than executing it after every successful download.
- Add a regression test using download paths containing spaces, quotes, dollar signs, parentheses, and command-substitution syntax; verify that no secondary command is executed.
- Avoid
