T09 · Insecure Skill Coding Practices
- Location
scripts/bing_image_downloader.py:127- Finding
User-Controlled Keyword Enables Arbitrary Output Directory Selection
- Content
View full analysis
- Remediation
View remediation
Path: slug = re.sub(r"[^A-Za-z0-9_-]+", "_", keyword).strip("_") if not slug: raise ValueError("Keyword does not produce a valid directory name") destination = (DOWNLOAD_ROOT / slug).resolve() if destination.parent != DOWNLOAD_ROOT: raise ValueError("Output directory escapes the download root") return destination ``` 5. Consider generating a hash-based directory identifier while retaining the original keyword only in metadata. 6. Run the downloader as an unprivileged account with write access limited to the download root. 7. Add tests for absolute paths, `../` traversal, Windows drive paths, separators, Unicode separator variants, and empty sanitized names. ]]>
