T09 · Insecure Skill Coding Practices
- Location
scripts/safe_delete.py:96- Finding
Arbitrary Permanent Recursive Deletion Without Enforced Safety Boundaries
- Content
View full analysis
Vulnerability Details
File Location:
scripts/safe_delete.py:96-191
Vulnerability Type: Unsafe arbitrary-path deletion
Risk Level: HighVulnerable Code
python # Additional safety check for important paths path_str = str(path).lower() danger_patterns = [ 'documents', 'desktop', 'pictures', 'movies', 'downloads', 'music', '.ssh', 'credentials' ] if any(pattern in path_str for pattern in danger_patterns): print("\n⚠️ WARNING: This path may contain important personal data!") print(" Consider backing up before deletion.") response = input("\nDelete this item? [y/N]: ").strip().lower() return response == 'y'python if response == '' or response == 'none': return [] elif response == 'all': return items else: selected = [] # Parse response parts = response.replace(' ', '').split(',') for part in parts: try: if '-' in part: # Range: 1-5 start, end = part.split('-') start_idx = int(start) - 1 end_idx = int(end) - 1 for i in range(start_idx, end_idx + 1): if 0 <= i < len(items): selected.append(items[i]) else: # Single number idx = int(part) - 1 if 0 <= idx < len(items): selected.append(items[idx]) except ValueError: print(f"⚠️ Ignoring invalid selection: {part}") continue return selectedpython def delete_path(path): """ Delete a file or directory. Returns: (success, message) """ try: path_obj = Path(path) if not path_obj.exists(): return (False, "Path does not exist") if path_obj.is_file(): path_obj.unlink() elif ...[truncated 2719 chars]- Remediation
View remediation
Remediation Suggestions
- Canonicalize every target with
Path.resolve(strict=True)before applying policy checks. - Reject filesystem roots, the user's home directory itself, system directories, and security-sensitive locations such as
~/.sshand~/Library/Keychains. - Compare paths by resolved path components rather than substring matching.
- Require the user to type an exact confirmation phrase such as
DELETE /resolved/pathfor sensitive or large targets. - Disable the batch
alloption whenever the list contains protected, personal-data, credential, or large targets. - Require per-item confirmation for dangerous batch entries.
- Implement the active-use, permission, system-path, user-data, and size checks documented in
references/safety_rules.md. - Prefer moving files to the macOS Trash so accidental deletion remains recoverable.
- Refuse to operate under elevated privileges unless an explicitly documented system-cleanup mode is selected.
- Add automated tests covering home-directory deletion, credential paths, system paths, path normalization, batch approval, and large deletions.
- Canonicalize every target with
