T09 · Insecure Skill Coding Practices
- Location
scripts/rollback.py:18- Finding
Arbitrary Recursive Directory Deletion During Rollback
- Content
View full analysis
Tuple[bool, str]: if not os.path.exists(self.backup_dir): return False, f"Backup directory does not exist: {self.backup_dir}" try: if os.path.exists(self.project_path): shutil.rmtree(self.project_path) shutil.copytree(self.backup_dir, self.project_path) return True, "Rollback completed" except Exception as e: return False, f"Rollback failed: {str(e)}" ``` ### Technical Analysis Both `backup_dir` and `project_path` originate from required command-line arguments. Converting them with `os.path.abspath()` only normalizes their syntax; it does not establish that they are safe, related, or valid Android project and backup directories. The rollback operation recursively deletes `project_path` before validating the backup contents or confirming that the backup can be restored. The implementation does not reject: - Filesystem roots or other sensitive system paths. - The current user's home directory. - Paths that are equal to or nested inside one another. - Symlink-mediated path redirection. - Directories that are not Android projects. - Backup directories that are unreadable, incomplete, or otherwise invalid. If `shutil.copytree()` fails after deletion, the target directory remains deleted. ### Attack Path 1. An attacker or operator invokes the rollback script with a sensitive directory as `--project-path`. 2. The attacker supplies any existing directory as `--backup-dir`. 3. The script confirms only that the backup path exists. 4. `shutil.rmtree()` recursively deletes the supplied project path. 5. ...[truncated 751 chars]- Remediation
View remediation
