T09 · Insecure Skill Coding Practices
- Location
scripts/restore.sh:8- Finding
Unvalidated Archive Extraction into the User Home Directory
- Content
View full analysis
Vulnerability Details
File Location:
scripts/restore.sh:8-33
Vulnerability Type: Unsafe archive extraction
Risk Level: Highbash BACKUP_FILE="${1:-$LATEST_BACKUP}" if [ -z "$BACKUP_FILE" ]; then echo "❌ No backup found in $BACKUP_DIR" exit 1 fi if [ ! -f "$BACKUP_FILE" ]; then echo "❌ Backup file not found: $BACKUP_FILE" exit 1 fi echo "📦 Restoring from: $BACKUP_FILE" # Stop gateway echo "🛑 Stopping gateway..." openclaw gateway stop # Backup current state if [ -d "$HOME/.openclaw" ]; then mv "$HOME/.openclaw" "$HOME/.openclaw-pre-restore-$(date +%Y%m%d_%H%M)" echo "✅ Current state backed up to ~/.openclaw-pre-restore-*" fi # Extract backup tar -xzf "$BACKUP_FILE" -C "$HOME"Technical Analysis
The script accepts an arbitrary archive path from its first argument and validates only that the path refers to a regular file. It does not verify the archive's provenance, expected directory structure, member paths, file types, symbolic links, hard links, ownership metadata, or integrity before extracting it directly into
$HOME.A malicious archive can contain absolute paths, traversal components such as
../, unsafe links, special files, or entries outside the expected.openclaw/hierarchy. Depending on the behavior and version of the installedtar, these entries may overwrite or create files elsewhere under the invoking user's accessible filesystem.Even where path traversal protections prevent direct writes outside the extraction directory, an attacker-controlled archive can replace OpenClaw configuration, credentials, agent definitions, workspace state, Telegram session data, or scheduled-task definitions. The script then restarts the gateway, causing restored attacker-controlled state to be consumed.
Attack Path
- An attacker creates a crafted
.tar.gzarchive containing malicious paths, links, or attacker-controlled files under ...[truncated 1185 chars]
- An attacker creates a crafted
- Remediation
View remediation
Remediation Suggestions
- Treat every supplied backup archive as untrusted until it has been validated.
- List and inspect archive members before extraction. Reject:
- Absolute paths.
- Empty or malformed member names.
- Any
..path component. - Entries outside the expected
.openclaw/top-level directory. - Symbolic links, hard links, device nodes, FIFOs, and other unexpected file types.
- Extract into a newly created private temporary directory with mode
0700, rather than directly into$HOME. - Use restrictive extraction options supported by the deployed
tar, including disabling restoration of archive ownership and avoiding unsafe permission metadata. - After extraction, verify that the staged tree contains only expected paths and that all resolved paths remain inside the staging directory.
- Authenticate backups with a signature or MAC and restore only archives from a trusted source.
- Replace the existing
.openclawdirectory atomically only after validation and successful staging. - Check whether
openclaw gateway stopsucceeded before modifying the current state. - If extraction or validation fails, restore the previous state automatically and avoid restarting the gateway with a partial tree.
