T09 · Insecure Skill Coding Practices
Warning
- Location
- bin/watchdog.sh:11
- Finding
- Unvalidated Backup Automatically Replaces the Active Configuration## Vulnerability Details **File Location**: `bin/watchdog.sh`, lines 11-29 **Vulnerability Type**: Unsafe automatic configuration rollback **Risk Level**: Medium ### Vulnerable Code ```bash # 1. 探测 Gateway 状态 # 尝试使用 openclaw status --probe 进行深探测 if ! openclaw gateway status --json | grep -q '"state": "active"'; then echo "[$(date)] ⚠️ Gateway detected as DOWN or UNREACHABLE." >> "$LOG_FILE" # 2. 查找最新的有效备份 LATEST_BACKUP=$(ls -t "$BACKUP_DIR"/openclaw-*.json 2>/dev/null | head -n 1) if [ -n "$LATEST_BACKUP" ]; then echo "[$(date)] 🔄 Attempting recovery using backup: $LATEST_BACKUP" >> "$LOG_FILE" # 3. 执行回滚 (先备份坏掉的,以防万一) cp "$CONFIG_FILE" "$BACKUP_DIR/failed-config-$(date +%Y%m%d-%H%M%S).json" cp "$LATEST_BACKUP" "$CONFIG_FILE" # 4. 重启 Gateway echo "[$(date)] 🚀 Restarting Gateway..." >> "$LOG_FILE" openclaw gateway restart --force ``` ### Technical Analysis The health check relies on searching command output for the exact text `"state": "active"`. A command failure, malformed response, permission error, temporary timeout, or harmless JSON-formatting change is therefore treated as a confirmed Gateway outage. Once this condition occurs, the script selects the newest pathname matching `openclaw-*.json` and copies it over the active configuration. It does not verify that the selected object: - Is a regular file rather than a symbolic link or another special object. - Resolves to a canonical path inside the expected backup directory. - Is owned by the expected user. - Has safe permissions. - Contains valid JSON. - Conforms to the expected OpenClaw configuration schema. - Represents a trusted backup. The replacement is also not atomic. An interrupted `cp` operation can leave the live configuration partially written before the forced restart. ### Attack Path 1. An attacker with the ability ...[truncated 1439 chars]
- Remediation
- ## Remediation Suggestions 1. Parse the status output with a real JSON parser and separately handle command failures, malformed output, timeouts, and an explicit inactive state. 2. Require multiple failed probes or an explicitly armed rollback window before changing the active configuration. 3. Resolve the backup with a safe file-selection mechanism rather than parsing `ls` output. 4. Canonicalize the selected path and verify that it remains beneath the expected backup directory. 5. Use `lstat` or equivalent checks to reject symbolic links and non-regular files. 6. Verify ownership and restrictive permissions before trusting a backup. 7. Validate both JSON syntax and the complete OpenClaw configuration schema before installation. 8. Store and verify a cryptographic digest or signature when backups are created. 9. Copy the validated configuration to a temporary file in the same directory, set safe permissions, synchronize it, and atomically rename it over the active file. 10. Check every copy and restart operation for failure, aborting safely if any step fails. 11. Avoid automatic rollback entirely when directory ownership or permissions do not satisfy the expected trust policy.
