T09 · Insecure Skill Coding Practices
- Location
scripts/pika_effect.py:293- Finding
Server-Controlled Task ID Permits Output Path Traversal
- Content
View full analysis
Vulnerability Details
File Location:
scripts/pika_effect.py:254-259andscripts/pika_effect.py:284-293
Vulnerability Type: Path traversal and arbitrary file overwrite
Risk Level: HighVulnerable Code
python task_id = response.get("taskId") if not task_id: print(json.dumps(response, ensure_ascii=False, indent=2)) return print("taskId =", task_id) if not args.no_download: wait_for_task(hive, task_id, Path(args.output_dir))python for index, item in enumerate(task.get("items", []), 1): if item.get("status") == "FAILED": print("[failed]", item.get("errorMessage"), file=sys.stderr) result_url = item.get("resultUrl") if item.get("status") == "COMPLETED" and result_url: download(result_url, output_dir / "{}_{}.mp4".format(task_id, index))Technical Analysis
The task ID returned by the remote generation service is inserted directly into a destination path without validation or sanitization.
pathlib.Pathdoes not prevent traversal when a path component contains sequences such as../.The resulting destination is subsequently opened in write-binary mode by
download(). Parent directories are also created automatically. A malicious or compromised service could therefore construct a task ID that causes the result to be written outside the configured output directory.Although the generated filename always receives an
_<index>.mp4suffix, the attacker can still target writable paths with a compatible filename or create files in unintended directories.Attack Path
- The user submits a generation request to the configured AI Hive API.
- A compromised or malicious API response supplies a task ID containing path traversal components.
- The same service returns a completed task and a controlled result URL.
wait_for_task()concatenates the untrusted task ID into the output path.download()creates the ...[truncated 632 chars]
- Remediation
View remediation
Remediation Suggestions
- Validate task IDs against a strict allowlist before using them, for example
^[A-Za-z0-9_-]{1,128}$. - Do not use remote identifiers directly as filenames. Generate a local random filename and store the remote task ID only as metadata.
- Resolve both the output directory and final destination with
Path.resolve(). - Verify that the resolved destination is contained beneath the resolved output directory before opening it.
- Refuse absolute paths, path separators, dot components, control characters, and platform-specific separator variants.
- Use exclusive file creation where overwriting is not required.
- Validate task IDs against a strict allowlist before using them, for example
