T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/archive-agent.sh:9
- Finding
- Path Traversal Through an Unvalidated Agent Identifier<![CDATA[ ## Vulnerability Details **File Location**: `scripts/archive-agent.sh`, lines 9-17 **Vulnerability Type**: Path traversal and unintended file archiving **Risk Level**: High ### Vulnerable Code ```bash AGENT_ID="$1" ARCHIVE_ROOT="${2:-$(pwd)/state/archive}" TS="$(date -u +'%Y%m%dT%H%M%SZ')" OUT="$ARCHIVE_ROOT/$AGENT_ID/$TS" mkdir -p "$OUT" cp -a "$HOME/.openclaw/agents/$AGENT_ID" "$OUT/agents-dir" 2>/dev/null || true cp -a "$HOME/.openclaw/workspace-$AGENT_ID" "$OUT/workspace" 2>/dev/null || true ``` ### Technical Analysis `AGENT_ID` is incorporated directly into both source and destination filesystem paths. The script does not restrict the identifier to an expected character set, canonicalize the resulting paths, or verify that the paths remain beneath the intended OpenClaw and archive directories. An identifier containing traversal components such as `../` can therefore escape the expected directories. For example, the source path: ```text $HOME/.openclaw/agents/../../.ssh ``` normalizes to a directory outside `$HOME/.openclaw/agents`. The destination is similarly constructed from untrusted input. Suppressing copy errors with `2>/dev/null || true` also allows the script to continue after a failed or partial copy, potentially creating an archive that appears successful but is incomplete. ### Attack Path 1. An attacker or untrusted automation supplies a crafted agent identifier to `archive-agent.sh`. 2. The identifier contains traversal sequences, such as `../../.ssh`. 3. `mkdir` resolves the traversal components while creating the archive destination. 4. `cp -a` resolves the crafted source path outside the intended OpenClaw agent directory. 5. User-readable sensitive files are copied into the archive destination. 6. If the archive directory is exposed to another user or process, the copied information can be retrieved from there. ### Impact Assessment The script does not itself elevate privileges, so access is limited to files readable ...[truncated 433 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Validate `AGENT_ID` before any filesystem operation using a strict allowlist, for example: ```bash if [[ ! "$AGENT_ID" =~ ^[A-Za-z0-9_-]+$ ]]; then echo "Invalid agent ID" >&2 exit 1 fi ``` 2. Canonicalize source and destination paths with `realpath` or an equivalent mechanism. 3. Verify that the canonical source remains beneath `$HOME/.openclaw/agents` or the expected workspace root. 4. Verify that the canonical destination remains beneath the configured archive root. 5. Reject absolute paths, path separators, `.` components, and `..` components in identifiers. 6. Remove `|| true` from archive copy operations. If an optional source does not exist, test that condition explicitly; otherwise, fail on copy errors. 7. Record which source directories were successfully archived and verify their presence before declaring the archive successful. ]]>
