T09 · Insecure Skill Coding Practices
- Location
export.py:68- Finding
User-Controlled Account Name Permits Path Traversal in Exported Files
- Content
View full analysis
- Remediation
View remediation
str: sanitized = re.sub(r"[^A-Za-z0-9 _-]", "_", value).strip() if not sanitized: raise ValueError("Account name does not contain any safe characters") return sanitized[:100] def safe_output_path(filename: str) -> Path: destination = (OUTPUT_ROOT / filename).resolve() try: destination.relative_to(OUTPUT_ROOT) except ValueError: raise ValueError("Output path escapes the designated output directory") return destination ``` Use the sanitized account name for every generated filename and use `safe_output_path()` immediately before every file write. ]]>
