T09 · Insecure Skill Coding Practices
- Location
scripts/memory.py:64- Finding
Path Traversal Enables Arbitrary Markdown File Overwrite
- Content
View full analysis
- Remediation
View remediation
Path: if not identifier or Path(identifier).is_absolute(): raise ValueError("Invalid identifier") if identifier in {".", ".."} or "/" in identifier or "\\" in identifier: raise ValueError("Path separators are not allowed") base = base_dir.resolve() destination = (base / f"{identifier}.md").resolve() try: destination.relative_to(base) except ValueError as exc: raise ValueError("Destination escapes the memory directory") from exc return destination ``` 3. Use generated identifiers, such as UUIDs or hashes, for filenames and store user-supplied labels only inside file content. 4. Apply a conservative allowlist, such as letters, numbers, spaces, underscores, and hyphens, with a strict maximum length. 5. Use non-destructive creation where overwriting is not required, or explicitly confirm that an existing target is an expected managed file. 6. Add automated tests covering `../`, absolute paths, repeated traversal, backslash-based traversal, empty names, oversized names, and symbolic-link edge cases. 7. Run the Skill under a dedicated least-privileged account with write access limited to the memory directory. ]]>
