T09 · Insecure Skill Coding Practices
- Location
scripts/openclaw_memory_fusion.py:1654- Finding
Untrusted Rollback Manifest Enables Arbitrary File Deletion and Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
scripts/openclaw_memory_fusion.py, lines 1654–1683 and 2212–2222
Vulnerability Type: Unvalidated file paths from an untrusted rollback manifest
Risk Level: HighVulnerable Code
python def rollback_manifest(manifest_path: Path, dry_run: bool = False) -> Dict[str, Any]: manifest = read_json(manifest_path) if manifest.get("status") == "rolled_back": return {"rolled_back": False, "reason": "manifest already rolled back", "manifest_path": str(manifest_path)} deleted: List[str] = [] restored: List[str] = [] for path_str in reversed(manifest.get("created_files", [])): path = Path(path_str) if path.exists(): if not dry_run: path.unlink() deleted.append(str(path)) for item in manifest.get("backups", []): original = Path(item["path"]) backup = Path(item["backup"]) if backup.exists(): if not dry_run: original.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(backup, original) restored.append(str(original)) if not dry_run: manifest["status"] = "rolled_back" manifest["rolled_back_at"] = datetime.now().isoformat(timespec="seconds") manifest_path.write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")The caller allows an arbitrary manifest path:
python def cmd_rollback(args: argparse.Namespace) -> int: layout = Layout(resolve_workspace(args.workspace), resolve_config_path(args.config)) layout.ensure_dirs() manifest_path = None if args.manifest: manifest_path = Path(args.manifest).expanduser() elif args.latest: manifest_path = latest_manifest_path(layout) if not manifest_path: raise SystemExit("No manifest found for rollback.") payload = rollback_manifest(manifest_path, dry_run=args.dry_run) print(json.dumps(payload, ...[truncated 2566 chars]- Remediation
View remediation
Remediation Suggestions
-
Restrict explicit manifests to the trusted manifest directory:
python manifest_root = layout.manifests_dir.resolve() manifest_path = manifest_path.resolve(strict=True) if not manifest_path.is_relative_to(manifest_root): raise SystemExit("Manifest must be inside the workspace manifest directory.") -
Validate the manifest against a strict schema. Reject missing, unexpected, or incorrectly typed fields.
-
Canonicalize every deletion and restoration destination and require it to be within the configured workspace or an explicit allowlist of files legitimately managed by the command.
-
Require each backup source to be inside the checkpoint directory recorded for that manifest:
python checkpoint_root = Path(manifest["checkpoint_root"]).resolve(strict=True) backup = Path(item["backup"]).resolve(strict=True) if not backup.is_relative_to(checkpoint_root): raise SystemExit("Backup path is outside the trusted checkpoint.") -
Reject symlink targets and verify file type before deletion or restoration. Use safe file-descriptor-based operations where practical to reduce time-of-check/time-of-use races.
-
Cross-check each path against trusted mutation state rather than treating manifest content as authoritative. Consider signing manifests or storing an integrity hash in protected local state.
-
Make rollback a dry run by default and require an explicit
--applyoption for mutations. -
Display the validated deletion and restoration list and require confirmation for interactive use.
-
Add tests covering arbitrary absolute paths,
..traversal, symlink escapes, manipulated checkpoint paths, malformed manifests, and restoration destinations outside the workspace.
-
