T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/burn.sh:14
- Finding
- Unvalidated Agent Name Allows Directory Traversal and Destructive Operations Outside the Intended Agent Directory## Vulnerability Details **File Location**: `scripts/burn.sh:14-21` **Vulnerability Type**: Directory traversal and insufficient path-boundary validation **Risk Level**: High ### Vulnerable Code ```bash AGENT="${OPENCLAW_AGENT:-main}" SESSIONS_DIR="$HOME/.openclaw/agents/$AGENT/sessions" # Safety: validate sessions dir structure EXPECTED_PARENT="$HOME/.openclaw/agents" if [[ "$SESSIONS_DIR" != "$EXPECTED_PARENT/"* ]]; then echo -e "${RED}FATAL:${NC} Session dir doesn't match expected parent" exit 1 fi ``` ### Technical Analysis The `OPENCLAW_AGENT` environment variable is incorporated directly into `SESSIONS_DIR` without validation. An attacker can supply an agent name containing path separators and `..` components. The subsequent check is only a lexical prefix comparison. Because `SESSIONS_DIR` is always constructed by prepending `$HOME/.openclaw/agents/`, even a path such as `$HOME/.openclaw/agents/../../../../tmp/target/sessions` satisfies the string-prefix check. The script does not canonicalize the path with `realpath` before enforcing the directory boundary. The later file verification also compares non-canonical path strings and therefore does not correct this weakness. If the traversed destination contains a `sessions` directory and `sessions.json`, the script can find, overwrite, and remove matching files there. ### Attack Path 1. The attacker identifies or creates a writable target directory containing a `sessions` subdirectory. 2. The attacker places a `sessions.json` file and a file matching an accepted session identifier in that directory. 3. The attacker sets `OPENCLAW_AGENT` to a traversal expression resolving to the target, such as a sequence of `../` components followed by the target path. 4. The attacker invokes `burn.sh` with a valid session ID and `--force`. 5. The lexical prefix check succeeds because the unnormalized path still begins with `$HOME/.openclaw/agents/`. 6. The s ...[truncated 543 chars]
- Remediation
- ## Remediation Suggestions - Validate `OPENCLAW_AGENT` against a strict allowlist, such as `^[A-Za-z0-9_-]+$`. - Explicitly reject `/`, `\`, `.` and `..` path components. - Canonicalize both the agents directory and selected sessions directory using `realpath`. - Verify that the canonical sessions path is a strict descendant of the canonical agents directory. - Perform the same canonical containment check for every file immediately before destructive operations. - Consider resolving agent names from a trusted configuration rather than accepting an unrestricted environment variable. - Refuse to follow symbolic links in the directory hierarchy where supported.
