T09 · Insecure Skill Coding Practices
- Location
script/src/split_region.py:190- Finding
Spreadsheet-Controlled Output Filename Enables Path Traversal and Arbitrary File Overwrite
- Content
View full analysis
- Remediation
View remediation
str: value = re.sub(r"[^A-Za-z0-9 _.-]", "_", value).strip() value = value.replace("..", "_") return value[:100] or "table" base = Path(output_dir).resolve() name = safe_component(filename) + ".csv" destination = (base / name).resolve() if base not in destination.parents: raise ValueError("Output path escapes the designated directory") ``` 5. Use collision-resistant filenames or exclusive file creation to avoid silently replacing existing files. 6. Add tests for `../`, absolute paths, Windows drive paths, path separators, Unicode separator variants, and long filenames. ]]>
