T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/create-agent.sh:157- Finding
Unrestricted Workspace Path Allows Arbitrary File Creation and Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
scripts/create-agent.sh, lines 157–404
Vulnerability Type: Unrestricted filesystem write destination and unsafe overwrite behavior
Risk Level: HighVulnerable Code
bash # ─── Step 1: Create workspace directory ─────────────────────────────── echo -e "${CYAN}[1/6]${NC} ${YELLOW}Creating workspace...${NC}" mkdir -p "$WORKSPACE" mkdir -p "$WORKSPACE/memory" mkdir -p "$WORKSPACE/skills" # ─── Step 2: Generate workspace files ───────────────────────────────── echo -e "${CYAN}[2/6]${NC} ${YELLOW}Generating workspace files...${NC}" # --- SOUL.md --- cat > "$WORKSPACE/SOUL.md" << SOULEOF # $NAME $EMOJI ... SOULEOF # --- AGENTS.md --- cat > "$WORKSPACE/AGENTS.md" << AGENTSEOF ... AGENTSEOF # --- IDENTITY.md --- cat > "$WORKSPACE/IDENTITY.md" << IDENTITYEOF ... IDENTITYEOF # --- TOOLS.md --- cat > "$WORKSPACE/TOOLS.md" << TOOLSEOF ... TOOLSEOF # --- USER.md --- cat > "$WORKSPACE/USER.md" << USEREOF ... USEREOF # --- HEARTBEAT.md --- cat > "$WORKSPACE/HEARTBEAT.md" << HEARTBEATEOF ... HEARTBEATEOF TODAY=$(date +%Y-%m-%d) cat > "$WORKSPACE/memory/$TODAY.md" << MEMEOF ... MEMEOFTechnical Analysis
The script accepts
--workspaceas an arbitrary path and uses it directly for directory creation and file writes. It does not:- Canonicalize the destination with
realpath. - Restrict the destination to an approved workspace root.
- Reject symbolic links in the path or at target filenames.
- Check whether the destination already contains files.
- Require confirmation before overwriting existing files.
- Use exclusive file creation semantics.
Shell quoting prevents direct command injection through
WORKSPACE, but it does not prevent path abuse. Thecat > fileredirections truncate existing files and follow symbolic links. Consequently, a user or upstream agent capable of controlling the workspac ...[truncated 1738 chars]- Canonicalize the destination with
- Remediation
View remediation
Remediation Suggestions
- Define an approved workspace root, such as
$HOME/.openclaw/workspaces, and reject destinations outside it. - Resolve both the approved root and requested destination with
realpathbefore comparing them. - Reject an existing non-empty workspace unless the user supplies a separate explicit overwrite option.
- Check every destination component and target file with
lstator equivalent logic, rejecting symbolic links. - Create files using exclusive semantics and restrictive permissions, such as a controlled
umask 077and no-clobber behavior. - Create content in a private temporary directory and atomically rename it into place only after validation succeeds.
- If updates to an existing workspace are supported, back up each affected file and present an exact change summary before applying it.
- Ensure the script refuses privileged execution unless it is explicitly required and justified.
- Define an approved workspace root, such as
