T09 · Insecure Skill Coding Practices
- Location
bin/watchdog.sh:11- Finding
Unvalidated Backup Automatically Replaces the Active Configuration
- Content
View full analysis
Vulnerability Details
File Location:
bin/watchdog.sh, lines 11-29
Vulnerability Type: Unsafe automatic configuration rollback
Risk Level: MediumVulnerable 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 --forceTechnical 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-*.jsonand 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
cpoperation can leave the live configuration partially written before the forced restart.Attack Path
- An attacker with the ability ...[truncated 1439 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse the status output with a real JSON parser and separately handle command failures, malformed output, timeouts, and an explicit inactive state.
- Require multiple failed probes or an explicitly armed rollback window before changing the active configuration.
- Resolve the backup with a safe file-selection mechanism rather than parsing
lsoutput. - Canonicalize the selected path and verify that it remains beneath the expected backup directory.
- Use
lstator equivalent checks to reject symbolic links and non-regular files. - Verify ownership and restrictive permissions before trusting a backup.
- Validate both JSON syntax and the complete OpenClaw configuration schema before installation.
- Store and verify a cryptographic digest or signature when backups are created.
- 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.
- Check every copy and restart operation for failure, aborting safely if any step fails.
- Avoid automatic rollback entirely when directory ownership or permissions do not satisfy the expected trust policy.
