T09 · Insecure Skill Coding Practices
- Location
scripts/apply_lesson.py:8- Finding
Unvalidated Date and Workspace Arguments Permit Arbitrary File Writes
- Content
View full analysis
- Remediation
View remediation
str: parsed = datetime.strptime(value, "%Y-%m-%d") canonical = parsed.strftime("%Y-%m-%d") if value != canonical: raise ValueError("Date must use canonical YYYY-MM-DD format") return canonical ``` 2. Reject absolute paths, path separators, null bytes, `.` components, and `..` components in any value used as a filename. 3. Resolve and verify every destination before writing: ```python root = (workspace / "memory").resolve() destination = (root / f"{date}.md").resolve() if not destination.is_relative_to(root): raise ValueError("Output path escapes the memory directory") ``` 4. Apply an equivalent containment check to the `memory/lessonloop` log directory. 5. Do not accept arbitrary workspaces in normal Agent operation. Obtain the workspace from trusted configuration or enforce containment beneath an approved root. 6. Refuse symlink output files or safely open files using platform facilities that prevent symlink following. 7. Use restrictive creation permissions and atomic writes for memory files. 8. Add regression tests covering absolute paths, `../` traversal, nested separators, symlinks, malformed dates, and unauthorized workspace roots. ]]>
