T09 · Insecure Skill Coding Practices
- Location
scripts/nano_main_image.py:216- Finding
Server-Controlled Task Identifier Enables Output Path Traversal
- Content
View full analysis
Vulnerability Details
File Location:
scripts/nano_main_image.py, lines 216–270
Vulnerability Type: Path traversal and arbitrary file overwrite
Risk Level: MediumVulnerable Code
python task_id = response.get("taskId") if not task_id: print(json.dumps(response, ensure_ascii=False, indent=2)) return print("[main-image]", args.platform, args.asset, "taskId =", task_id) if args.required_text: print("[text-check] Contains specified text; manually verify it before publication") if not args.no_download: wait_and_download(api, task_id, Path(args.output_dir))python if item.get("status") == "COMPLETED" and item.get("resultUrl"): safe_download( item["resultUrl"], output_dir / "{}_{}.png".format(task_id, index), )Technical Analysis
The task identifier originates in a remote API response and crosses a trust boundary without validation. It is subsequently incorporated directly into the local output path.
Python's
pathlibdoes not remove traversal components. A task identifier containing path separators and..components can therefore cause the destination to resolve outsideoutput_dir. An absolute task identifier can also supersede the preceding output directory. The download routine creates missing parent directories and opens the destination withwb, which truncates an existing file at the resulting path.Exploitation requires control over, or compromise of, the configured AI Hive API response. HTTPS reduces network interception risk but does not protect against a compromised service, compromised service credentials, or malicious server-side behavior.
Attack Path
- An attacker gains the ability to control responses from the configured AI Hive service.
- The image-generation response returns a crafted
taskId, such as one containing directory traversal components. - The script accepts the identifier and passes i ...[truncated 963 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not use a server-provided task identifier as a local filename. Generate a local random filename instead and store the task identifier only as metadata.
- If the identifier must appear in the filename, enforce a strict allowlist such as
^[A-Za-z0-9_-]{1,128}$. - Resolve both the output directory and candidate destination, then verify that the destination remains beneath the output directory using
Path.resolve()andPath.relative_to(). - Reject absolute paths, path separators, traversal components, control characters, and platform-specific separator variants.
- Avoid silent replacement by opening new output files in exclusive mode or requiring explicit overwrite approval.
- Write into a temporary file inside the validated output directory and atomically rename it after download and content validation succeed.
