T09 · Insecure Skill Coding Practices
- Location
scripts/synthesize_qwen3.py:72- Finding
Voice-plan path traversal allows files to be written outside the designated output directory
- Content
View full analysis
Vulnerability Details
File Location:
scripts/synthesize_qwen3.py, lines 72–88
Vulnerability Type: Unrestricted file path and arbitrary file overwrite
Risk Level: MediumVulnerable Code
python for segment in plan["segments"]: output = args.public_dir / segment["output"] if output.exists() and not args.overwrite: print(f"Skip {output}") continue voice = plan["voices"][segment["speaker"]] instruction = "。".join(part for part in [voice.get("instruct", "").strip(), segment.get("instruct", "").strip()] if part) kwargs = {"text": segment["text"], "language": segment.get("language", language), "instruct": instruction or None} if mode == "voice-design": wavs, rate = model.generate_voice_design(**kwargs) else: speaker = voice.get("speaker") if not speaker: raise ValueError(f"{segment['speaker']}: custom-voice requires speaker") wavs, rate = model.generate_custom_voice(**kwargs, speaker=speaker) output.parent.mkdir(parents=True, exist_ok=True) sf.write(output, wavs[0], rate)Technical Analysis
The output path is constructed by joining the user-selected
public_dirwith theoutputvalue taken directly from the JSON voice plan. The code does not reject:- Absolute paths, which cause
pathlibto discard the intended base directory. - Parent-directory components such as
../. - Symbolic-link destinations.
- Output paths outside the renderer's public asset directory.
Consequently, a voice plan can direct generated audio to any filesystem location writable by the process. Existing files are skipped by default, but they are overwritten when the caller supplies
--overwrite. Files that do not already exist can be created outsidepublic_dirwithout that option.Validation in
require_plan()only checks whether the output value is present; it does not validate or confine the path. ...[truncated 1435 chars]- Absolute paths, which cause
- Remediation
View remediation
Remediation Suggestions
-
Reject absolute output paths and parent-directory traversal before performing any writes.
-
Resolve both the base directory and candidate destination, then verify that the destination remains under the base:
python public_dir = args.public_dir.expanduser().resolve() relative_output = Path(segment["output"]) if relative_output.is_absolute() or ".." in relative_output.parts: raise ValueError("segment output must be a relative path without parent traversal") output = (public_dir / relative_output).resolve() if not output.is_relative_to(public_dir): raise ValueError("segment output escapes public_dir") -
Restrict output extensions to expected audio formats such as
.wav. -
Refuse symbolic-link destinations and consider using secure, exclusive file creation.
-
Require per-file confirmation before replacing existing files rather than relying only on a global
--overwriteoption. -
Apply the same path-confinement validation to all plan-controlled file paths.
-
