T09 · Insecure Skill Coding Practices
- Location
clips_machine.py:396- Finding
User-Controlled Output Path Can Escape the Intended Output Directory
- Content
View full analysis
- Remediation
View remediation
Path: base = OUTPUT_DIR.resolve() candidate_name = Path(output_name) if ( candidate_name.is_absolute() or len(candidate_name.parts) != 1 or output_name in ("", ".", "..") ): raise ValueError("Output must be a single directory name") candidate = (base / candidate_name).resolve() if not candidate.is_relative_to(base): raise ValueError("Output directory escapes the configured output root") candidate.mkdir(parents=False, exist_ok=False) return candidate ``` Replace the vulnerable construction with: ```python output_dir = safe_output_directory(output_name) ``` If compatibility with older Python versions is required, perform containment validation using `os.path.commonpath()` instead of `Path.is_relative_to()`. ]]>
