T09 · Insecure Skill Coding Practices
- Location
scripts/videogen.py:399- Finding
Server-Controlled Task Type Enables Output Path Traversal
- Content
View full analysis
Vulnerability Details
File Location:
scripts/videogen.py, lines 399-407
Vulnerability Type: Path traversal through an untrusted filename component
Risk Level: MediumComplete Code Snippet
python task_type = task.get("taskType", "task") for i, item in enumerate(succeeded): result_url = item.get("resultUrl") if not result_url: continue ext = ".mp4" if "video" in task_type.lower() else ".png" filename = f"{task_type}_{task_id}_{i+1}{ext}" out_path = out_dir / filename download_file(result_url, out_path)The
taskTypevalue originates from a remote API response and is incorporated directly into a local output path. No filename sanitization or resolved-path containment check is performed. A malicious or compromised API server could return a value containing absolute-path syntax, path separators, or parent-directory components such as../.pathlib.Pathdoes not automatically constrain the resulting path toout_dir. Consequently, the constructed destination can escape the intended download directory.Attack Path
- An attacker compromises or impersonates the configured API endpoint, or convinces the user to set
--base-urlorAI_HIVE_BASE_URLto an attacker-controlled service. - The user submits or polls a generation task.
- The hostile service returns a successful task object whose
taskTypecontains path traversal components. - The script combines that value with the output directory without sanitization.
download_file()opens the resulting path in write mode and writes attacker-controlled response content.- An existing file at the escaped destination may be overwritten if the process has write permission.
Impact Assessment
Exploitation provides arbitrary file-write or overwrite capability within the filesystem permissions of the user running the Skill. It does not independently grant elevated operating-system privileges ...[truncated 432 chars]
- An attacker compromises or impersonates the configured API endpoint, or convinces the user to set
- Remediation
View remediation
Remediation Suggestions
- Do not use remote response fields as filename components. Generate filenames exclusively from locally defined constants and validated identifiers.
- If
taskTypemust be retained, replace every character outside a strict allowlist such as[A-Za-z0-9_-]. - Apply the same validation to
task_id, because it also contributes to the filename. - Resolve both the output directory and candidate path, then verify that the candidate remains inside the output directory before opening it.
- Refuse absolute paths, path separators, empty names,
.components, and..components. - Consider exclusive file creation or an explicit overwrite policy to prevent accidental replacement of existing output files.
Example containment strategy:
python import re safe_task_type = re.sub(r"[^A-Za-z0-9_-]", "_", str(task_type)) safe_task_id = re.sub(r"[^A-Za-z0-9_-]", "_", str(task_id)) base = out_dir.resolve() candidate = ( base / f"{safe_task_type}_{safe_task_id}_{i + 1}{ext}" ).resolve() if base not in candidate.parents: raise SystemExit("Refusing output path outside the selected directory") download_file(result_url, candidate)
