T09 · Insecure Skill Coding Practices
- Location
scripts/sanitize.py:666- Finding
Arbitrary File Write Through Unvalidated Sanitized and Restored Paths
- Content
View full analysis
- Remediation
View remediation
Path: if relative_path.is_absolute(): raise ValueError("Absolute output paths are not permitted") base = base_dir.resolve() destination = (base / relative_path).resolve() try: destination.relative_to(base) except ValueError: raise ValueError("Output path escapes the designated directory") return destination ``` 3. Apply this validation to both sanitized and restored destinations. 4. Treat `_sanitize_config.json` and `_sanitize_record.json` as untrusted input and validate their schemas and value types. 5. Refuse to overwrite existing files unless the user explicitly authorizes it. 6. Consider mapping only basename-to-basename values rather than allowing arbitrary relative paths in `filename_mapping`. ]]>
