T09 · Insecure Skill Coding Practices
- Location
youtube_factory.py:362- Finding
Unrestricted Output Path Allows Filesystem Writes Outside the Intended Directory
- Content
View full analysis
Vulnerability Details
File Location:
youtube_factory.py, lines 362–365
Vulnerability Type: Improper path validation and path traversal
Risk Level: Highpython if output_name is None: output_name = re.sub(r'[^a-z0-9-]', '', topic.lower().replace(" ", "-"))[:50] video_dir = OUTPUT_DIR / output_name video_dir.mkdir(parents=True, exist_ok=True)Technical Analysis
The automatically generated output name is sanitized only when
output_nameisNone. A caller-supplied--outputvalue is used directly in the path expression without validation.Python's
pathlibpermits absolute path components and parent-directory components such as... Ifoutput_nameis absolute, combining it withOUTPUT_DIRresults in the absolute path taking precedence. If it is relative and contains traversal components, the resulting path can escape the intended output directory.The generation process subsequently writes predictable filenames such as
script.md,voiceover.mp3,metadata.json, and several video or image files into this directory. Some operations, includingPath.write_text()and FFmpeg invocations using-y, can overwrite existing files.Attack Path
- An attacker influences the
--outputargument passed to the Skill, directly or through an agent-generated invocation. - The attacker supplies an absolute path or traversal value, such as
--output /tmp/targetor--output ../../target. - The value bypasses the sanitization branch because
output_nameis notNone. video_dir.mkdir()creates or selects a directory outsideOUTPUT_DIR.- The Skill writes generated artifacts with predictable names into the attacker-selected location.
- If matching files already exist and the invoking account has write permission, those files may be overwritten.
Impact Assessment
Exploitation permits file creation and overwrite outside the declared
~/Videos/OpenClawoutput area. Th ...[truncated 466 chars]- An attacker influences the
- Remediation
View remediation
Remediation Suggestions
- Reject absolute output paths and any path containing
... - Resolve both the configured base directory and the requested destination, then verify that the destination remains beneath the base directory.
- Apply a strict allowlist to caller-provided directory names, not only automatically generated names.
- Refuse to overwrite existing output directories or files unless the user explicitly authorizes replacement.
- Use a newly created, uniquely named directory for each generation job where practical.
- Treat all agent-generated command arguments as untrusted input.
Example hardening:
python base_dir = OUTPUT_DIR.resolve() if output_name is None: output_name = re.sub( r"[^a-z0-9-]", "", topic.lower().replace(" ", "-") )[:50] elif not re.fullmatch(r"[A-Za-z0-9_-]{1,64}", output_name): raise ValueError("Invalid output directory name") video_dir = (base_dir / output_name).resolve() if video_dir.parent != base_dir: raise ValueError("Output directory must be directly under OUTPUT_DIR") video_dir.mkdir(parents=False, exist_ok=False)- Reject absolute output paths and any path containing
