T09 · Insecure Skill Coding Practices
- Location
scripts/undo_manager.py:113- Finding
Arbitrary File Move and Overwrite Through Forged Undo Records
- Content
View full analysis
- Remediation
View remediation
Path: resolved_path = path.expanduser().resolve(strict=False) resolved_root = root.expanduser().resolve(strict=True) if not resolved_path.is_relative_to(resolved_root): raise ValueError(f"Path is outside the approved root: {resolved_path}") return resolved_path ``` 3. **Validate paths according to operation type** - For `create` undo records, require the source to be an approved Markdown card under a recognized card directory. - For `delete` and `batch_delete`, require the source to be inside `TRASH_DIR` and the destination to be inside an approved note directory. - For `update`, require the target to be an approved Markdown card under `CARDS_DIR`. 4. **Reject symbolic-link attacks** - Reject symlink sources and destinations. - Validate resolved paths immediately before each move or write to reduce time-of-check/time-of-use exposure. - Use filesystem operations that avoid following symlinks where supported. 5. **Avoid trusting serialized paths** - Store an immutable card identifier and operation identifier rather than arbitrary absolute paths. - Reconstruct approved paths from trusted application state when performing an undo. - Co ...[truncated 672 chars]
