T09 · Insecure Skill Coding Practices
- Location
scripts/dub.py:57- Finding
Path Traversal Allows File Writes Outside the Intended Output Directory
- Content
View full analysis
- Remediation
View remediation
str: if not isinstance(value, str) or not SAFE_ID.fullmatch(value): raise ValueError(f"Invalid {field}") return value ``` 2. Resolve the final destination and enforce containment within the resolved output directory: ```python base = out_dir.resolve() candidate = (base / f"{sid}_{cid}_{idx}.wav").resolve() if candidate != base and base not in candidate.parents: raise ValueError("Output path escapes the output directory") ``` 3. Reject absolute paths, `..`, path separators, null bytes, and identifiers of unexpected types. 4. Consider generating filenames from trusted internal identifiers rather than raw input values. If source identifiers must be retained, map them to sanitized names or stable hashes. 5. Avoid overwriting existing files by using exclusive creation where practical, or require an explicit overwrite option. ]]>
