T09 · Insecure Skill Coding Practices
- Location
skills/weekly-report/scripts/history_manager.py:34- Finding
Path Traversal Enables File Read, Write, and Deletion Outside the History Directory
- Content
View full analysis
- Remediation
View remediation
str: return date.fromisoformat(value).isoformat() ``` 2. Construct filenames only from normalized values: ```python safe_start = normalize_date(week_start) safe_end = normalize_date(week_end) filename = f"{safe_start}_{safe_end}.md" ``` 3. Resolve and verify the final path before every read, write, or deletion: ```python history_dir = get_history_dir().resolve() filepath = (history_dir / filename).resolve() if filepath.parent != history_dir: raise ValueError("Invalid report path") ``` 4. Reject path separators, absolute paths, NUL characters, and traversal components as defense in depth. 5. Apply the same helper function consistently to save, get, and delete operations. 6. Create history files with restrictive permissions because weekly reports may contain confidential work information. ]]>
