T09 · Insecure Skill Coding Practices
- Location
scripts/create_agent.sh:7- Finding
Unsanitized Agent Identifier Allows Filesystem Path Traversal
- Content
View full analysis
}" MAIN="$HOME/.openclaw/workspace" WS="$HOME/.openclaw/workspace-$AGENT_ID" ``` ```bash # Create agent directory in shared workspace mkdir -p "$MAIN/agents/$AGENT_ID" touch "$MAIN/agents/$AGENT_ID/INBOX.md" touch "$MAIN/agents/$AGENT_ID/OUTBOX.md" # Create budget file TODAY=$(date +%Y-%m-%d) cat > "$MAIN/agents/$AGENT_ID/BUDGET.json" << EOF { "daily_limit_output_tokens": 50000, "today": "$TODAY", "used_output_tokens": 0, "spawns": [], "status": "active", "warnings": [], "consecutive_overbudget_days": 0 } EOF ``` ### Technical Analysis The script accepts `AGENT_ID` from the command line and interpolates it directly into several filesystem paths. Shell quoting prevents word splitting and shell metacharacter expansion, but it does not prevent path separators or `..` traversal components from being interpreted by the filesystem. Consequently, the constructed path under `$MAIN/agents` is not guaranteed to remain within that directory. The script then creates directories, creates or updates `INBOX.md` and `OUTBOX.md`, and truncates or creates `BUDGET.json` at the resolved location. The workspace path is constructed using the same unvalidated identifier. Depending on the identifier, embedded slashes and traversal components can also place workspace content outside the expected `~/.openclaw/workspace-` location. ### Attack Path 1. An attacker or untrusted automation invokes the script with an identifier containing traversal components, such as `../../../target`. 2. The script constructs `$MAIN/agents/../../../target`. 3. The operating system normalizes the traversal components and resolves the path outside `$MAIN/agents`. 4. `mkdir -p` creates the attacker-selecte ...[truncated 906 chars]- Remediation
View remediation
&2 exit 1 fi ``` - Set a reasonable maximum identifier length. - Explicitly reject `/`, `\`, `.`, `..`, control characters, and leading hyphens. - Canonicalize each destination and verify that it remains beneath its intended parent before creating or writing files. - Refuse to operate if any relevant parent or destination is a symbolic link. - Create files with restrictive permissions, such as through `umask 077`. - Add regression tests covering absolute paths, repeated traversal components, embedded slashes, control characters, whitespace, and symlinked destinations. ]]>
