T09 · Insecure Skill Coding Practices
- Location
scripts/backup_rollb_plugin.py:90- Finding
Unvalidated Archive Extraction Allows Writes Outside the Intended Directory
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This backup tool is broadly purpose-aligned, but it automatically snapshots sensitive OpenClaw data and can overwrite the live installation without enough safeguards.
Review carefully before installing. This skill may continuously copy sensitive OpenClaw state into local archives, and rollback can replace your current configuration and interrupt services. Use it only if you trust local backup storage, understand the retention behavior, and are comfortable validating backups before restore.
scripts/backup_rollb_plugin.py:90Unvalidated Archive Extraction Allows Writes Outside the Intended Directory
scripts/backup_openclaw.sh:5Sensitive OpenClaw State Is Stored in Unencrypted Archives Without Explicit Permission Enforcement
scripts/backup_rollb_plugin.py:80Restore Operation Reports Success After Failed or Partial Restoration
Tool calls are chained to bypass individual safety checks or escalate capabilities beyond what any single tool call would allow.
# 清理旧备份(只保留MAX_BACKUPS个)
cd "$BACKUP_DIR" || exit
ls -t openclaw_*.tar.gz 2>/dev/null | tail -n +$((MAX_BACKUPS+1)) | xargs rm -f 2>/dev/null
echo "[$(date)] 🧹 旧备份已清理,保留最近${MAX_BACKUPS}个"
else
echo "[$(date)] ❌ 备份失败"
The rollback flow stops services and performs an in-place restore immediately, with no confirmation, dry-run, warning, or post-extraction validation. In a skill context where commands may be triggered quickly or indirectly, this materially increases the chance of accidental destructive rollback, service outage, and recovery from an untrusted or wrong backup.
The documentation describes a rollback flow that extracts an archive over the current installation and restarts the Gateway, but it does not clearly warn users that this is a destructive operation that can overwrite the active state and cause service interruption. In an operational backup/restore skill, lack of an explicit warning can lead to accidental invocation, unintended data loss, or outage even if the underlying feature is intentional.
This manifest file describes a backup/rollback system that can restore prior versions of OpenClaw configuration, which may overwrite current state. The description presents the feature as protective but does not warn users about data reversion or configuration replacement effects.
The command descriptions for rollback advertise restoring backups but do not disclose that invoking them may replace current configuration with an older version. For markdown/manifest content, safety-sensitive behaviors affecting user data or system integrity should be accompanied by explicit warnings.
The module description and command/help text are presented only in Chinese, and the runtime usage/error strings are also fixed to Chinese. This forces a specific language for user-facing interaction without any opt-in or locale selection mechanism.
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
name = b.stem.replace("openclaw_", "")
date_part, time_part = name.split("_")
ts = f"{date_part[:4]}-{date_part[4:6]}-{date_part[6:]} {time_part[:2]}:{time_part[2:4]}:{time_part[4:]}"
size = subprocess.run(["du", "-h", str(b)], capture_output=True, text=True).stdout.split()[0]
result.append({"timestamp": name, "time": ts, "size": size, "file": str(b)})
return result
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
]
cmd = ["tar", "-czf", str(backup_file), "-C", str(OPENCLAW_DIR.parent), OPENCLAW_DIR.name] + exclude
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0 and backup_file.exists():
size = subprocess.run(["du", "-h", str(backup_file)], capture_output=True, text=True).stdout.split()[0]
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0 and backup_file.exists():
size = subprocess.run(["du", "-h", str(backup_file)], capture_output=True, text=True).stdout.split()[0]
log(f"Backup OK: {backup_file} ({size})")
# 清理旧备份
After a successful backup, the code silently deletes older archives beyond MAX_BACKUPS using unlink(). This is a destructive file operation, and the current implementation provides no user-facing warning or notice that retention cleanup will remove prior backups.
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
# 备份当前状态
pre_backup = BACKUP_DIR / f"pre_rollback_{timestamp}.tar.gz"
exclude = ["--exclude=backups", "--exclude=media"]
subprocess.run(
["tar", "-czf", str(pre_backup), "-C", str(OPENCLAW_DIR.parent), OPENCLAW_DIR.name] + exclude,
capture_output=True
)
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
# 停止服务
for svc in ["openclaw-gateway", "vector-search", "openclaw-gateway-guardian"]:
subprocess.run(["systemctl", "--user", "stop", svc], capture_output=True)
# 解压还原
result = subprocess.run(
Restoring by extracting a tar archive directly into the target parent directory is dangerous because archive contents are not validated before extraction. If a malicious or tampered backup is placed in the backup directory, tar may overwrite arbitrary files under the restore path or abuse symlinks/path traversal semantics, leading to destructive file replacement and possible code execution on next service start.
subprocess.run(["systemctl", "--user", "stop", svc], capture_output=True)
# 解压还原
result = subprocess.run(
["tar", "-xzf", str(backup_file), "-C", str(OPENCLAW_DIR.parent)],
capture_output=True, text=True
)
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
)
# 重启服务
subprocess.run(["systemctl", "--user", "start", "openclaw-gateway"], capture_output=True)
return {"ok": True, "pre_backup": str(pre_backup), "restored": timestamp}
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
)
# 重启服务
subprocess.run(["systemctl", "--user", "start", "openclaw-gateway"], capture_output=True)
return {"ok": True, "pre_backup": str(pre_backup), "restored": timestamp}
This code file contains natural-language strings that force a specific language for usage instructions, which can violate language/locale policy when no user opt-in or justified regional constraint is provided. The same pattern continues in runtime messages, indicating the skill is not language-neutral or configurable.
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
else:
formatted = name
size = subprocess.run(
["du", "-h", str(b)],
capture_output=True, text=True
).stdout.split()[0]
The diff feature extracts the selected backup archive into a temporary directory without validating archive members. Although the target is temporary, a malicious tarball can still use path traversal or crafted links to write outside tmpdir, which can clobber files accessible to the current user.
with tempfile.TemporaryDirectory() as tmpdir:
# 解压备份到临时目录
subprocess.run(["tar", "-xzf", str(backup_file), "-C", tmpdir], capture_output=True)
backup_extract = Path(tmpdir) / ".openclaw"
# 对比关键配置文件
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
# 先停止gateway
print("🛑 停止 Gateway...")
subprocess.run(["systemctl", "--user", "stop", "openclaw-gateway"], capture_output=True)
subprocess.run(["systemctl", "--user", "stop", "vector-search"], capture_output=True)
subprocess.run(["systemctl", "--user", "stop", "openclaw-gateway-guardian"], capture_output=True)
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
# 先停止gateway
print("🛑 停止 Gateway...")
subprocess.run(["systemctl", "--user", "stop", "openclaw-gateway"], capture_output=True)
subprocess.run(["systemctl", "--user", "stop", "vector-search"], capture_output=True)
subprocess.run(["systemctl", "--user", "stop", "openclaw-gateway-guardian"], capture_output=True)
openclaw_dir = Path.home() / ".openclaw"
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
print("🛑 停止 Gateway...")
subprocess.run(["systemctl", "--user", "stop", "openclaw-gateway"], capture_output=True)
subprocess.run(["systemctl", "--user", "stop", "vector-search"], capture_output=True)
subprocess.run(["systemctl", "--user", "stop", "openclaw-gateway-guardian"], capture_output=True)
openclaw_dir = Path.home() / ".openclaw"
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
# 备份当前状态
current_backup = openclaw_dir / f"pre_rollback_{timestamp}.tar.gz"
print("📦 备份当前状态...")
subprocess.run(
["tar", "-czf", str(current_backup), "-C", str(openclaw_dir.parent), openclaw_dir.name, "--exclude=backups"],
capture_output=True
)
Extracting a tar.gz archive directly into the user's home-parent directory without validating archive members is dangerous because malicious backups can exploit path traversal or symlink/hardlink entries to overwrite files outside the intended .openclaw directory. Since backup files are restored from disk and treated as trusted, a poisoned archive could replace configs or other user files and compromise service behavior on restart.
# 解压还原
print("🔄 还原到备份...")
result = subprocess.run(
["tar", "-xzf", str(backup_file), "-C", str(openclaw_dir.parent)],
capture_output=True, text=True
)
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
# 重启服务
print("🚀 重启服务...")
subprocess.run(["systemctl", "--user", "start", "openclaw-gateway"], capture_output=True)
subprocess.run(["systemctl", "--user", "start", "vector-search"], capture_output=True)
subprocess.run(["systemctl", "--user", "start", "openclaw-gateway-guardian"], capture_output=True)
return f"✅ 成功还原到 {timestamp},当前状态已备份到 pre_rollback_{timestamp}.tar.gz"
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
print("🚀 重启服务...")
subprocess.run(["systemctl", "--user", "start", "openclaw-gateway"], capture_output=True)
subprocess.run(["systemctl", "--user", "start", "vector-search"], capture_output=True)
subprocess.run(["systemctl", "--user", "start", "openclaw-gateway-guardian"], capture_output=True)
return f"✅ 成功还原到 {timestamp},当前状态已备份到 pre_rollback_{timestamp}.tar.gz"