T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/backup_encrypted.sh:8
- Finding
- Predictable and Insufficiently Protected Temporary Backup Storage<![CDATA[ ## Vulnerability Details **File Location**: `scripts/backup_encrypted.sh:8-17, 44-54` **Vulnerability Type**: Unsafe temporary directory handling **Risk Level**: High ### Complete Code Snippet ```bash DATE_STR="$(date +"%Y-%m-%d_%H-%M-%S")" TMP_DIR="/tmp/openclaw_backup_$DATE_STR" ARCHIVE_NAME="openclaw_backup_$DATE_STR.tar.gz" ENCRYPTED_NAME="openclaw_backup_$DATE_STR.tar.gz.enc" STATE_DIR_NEW="$HOME/.openclaw" STATE_DIR_OLD="$HOME/.clawdbot" mkdir -p "$BACKUP_ROOT" mkdir -p "$TMP_DIR" if [ -d "$STATE_DIR_NEW" ]; then echo "✓ 发现: $STATE_DIR_NEW" cp -a "$STATE_DIR_NEW" "$TMP_DIR/" FOUND_ANY=1 fi if [ -d "$STATE_DIR_OLD" ]; then echo "✓ 发现: $STATE_DIR_OLD" cp -a "$STATE_DIR_OLD" "$TMP_DIR/" FOUND_ANY=1 fi ``` Equivalent behavior also appears in `scripts/backup.sh:8-16, 24-34` and is reproduced in `SKILL.md`. ### Technical Analysis The temporary directory name is derived from the current timestamp and is therefore predictable. It is created in the shared `/tmp` namespace with `mkdir -p`, rather than through an atomic facility such as `mktemp`. The script does not set a restrictive `umask`, verify that the path is a newly created directory owned by the current user, or explicitly assign mode `0700`. The directory receives complete copies of `~/.openclaw` and `~/.clawdbot`, which the project documentation states may contain API keys, bot tokens, conversations, memory, and configuration data. A pre-existing path can at minimum cause denial of service. Depending on platform behavior, default permissions, copied file modes, and local process access, temporary content may also become visible to unauthorized local users or monitoring processes. ### Attack Path 1. A local attacker predicts the timestamp-based `/tmp/openclaw_backup_YYYY-MM-DD_HH-MM-SS` name or continuously monitors for matching paths. 2. The victim starts a backup. 3. The script copies the complete OpenClaw state into the shared temporary namespace. 4. If dire ...[truncated 576 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Create the directory atomically with a random name: ```bash umask 077 TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/openclaw_backup.XXXXXXXX")" ``` - Verify that the result is a directory owned by the current user. - Explicitly enforce mode `0700` on the temporary directory. - Store the intermediate archive inside that protected directory rather than directly under `/tmp`. - Register cleanup immediately after creation: ```bash cleanup() { rm -rf -- "$TMP_DIR" } trap cleanup EXIT HUP INT TERM ``` - Apply the same correction to both backup scripts and to the code examples embedded in `SKILL.md`. ]]>
