T09 · Insecure Skill Coding Practices
- Location
scripts/qr.py:369- Finding
Batch-Supplied Filenames Permit Path Traversal and Arbitrary File Overwrite
- Content
View full analysis
- Remediation
View remediation
Path: base = Path(output_dir).resolve() candidate_name = Path(supplied_name) if candidate_name.is_absolute(): raise ValueError("Absolute output paths are not allowed") candidate = (base / candidate_name).resolve() if candidate != base and base not in candidate.parents: raise ValueError("Output path escapes the configured directory") return candidate ``` Additional hardening should include: 1. Prefer accepting only a basename: ```python if Path(supplied_name).name != supplied_name: raise ValueError("Output filename must not contain directories") ``` 2. Restrict extensions to the format actually being generated. 3. Reject empty filenames and platform-specific special paths. 4. Consider refusing to overwrite existing files unless an explicit `--overwrite` option is supplied. 5. Evaluate symbolic links immediately before opening the destination, or open files using platform-specific no-follow protections where available. 6. Run the skill with the minimum filesystem permissions required. 7. Add regression tests covering `../`, absolute paths, nested traversal, symbolic links, and valid filenames. ]]>
