T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/burn.sh:14- Finding
Unvalidated Agent Name Allows Directory Traversal and Destructive Operations Outside the Intended Agent Directory
- Content
View full analysis
Vulnerability Details
File Location:
scripts/burn.sh:14-21
Vulnerability Type: Directory traversal and insufficient path-boundary validation
Risk Level: HighVulnerable 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 fiTechnical Analysis
The
OPENCLAW_AGENTenvironment variable is incorporated directly intoSESSIONS_DIRwithout validation. An attacker can supply an agent name containing path separators and..components.The subsequent check is only a lexical prefix comparison. Because
SESSIONS_DIRis always constructed by prepending$HOME/.openclaw/agents/, even a path such as$HOME/.openclaw/agents/../../../../tmp/target/sessionssatisfies the string-prefix check. The script does not canonicalize the path withrealpathbefore 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
sessionsdirectory andsessions.json, the script can find, overwrite, and remove matching files there.Attack Path
- The attacker identifies or creates a writable target directory containing a
sessionssubdirectory. - The attacker places a
sessions.jsonfile and a file matching an accepted session identifier in that directory. - The attacker sets
OPENCLAW_AGENTto a traversal expression resolving to the target, such as a sequence of../components followed by the target path. - The attacker invokes
burn.shwith a valid session ID and--force. - The lexical prefix check succeeds because the unnormalized path still begins with
$HOME/.openclaw/agents/. - The s ...[truncated 543 chars]
- The attacker identifies or creates a writable target directory containing a
- Remediation
View remediation
Remediation Suggestions
- Validate
OPENCLAW_AGENTagainst 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.
- Validate
