T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/cc-bridge.sh:27
- Finding
- Environment-Controlled Command Injection Through CLAUDE_BIN<![CDATA[ ## Vulnerability Details **File Location**: `scripts/cc-bridge.sh`, lines 27 and 137-145 **Vulnerability Type**: Shell command injection **Risk Level**: High ### Vulnerable Code ```bash CLAUDE_BIN="${CLAUDE_BIN:-$HOME/.local/bin/claude}" ``` ```bash # 构建启动命令: # - unset CLAUDECODE/CLAUDE_CODE 防止 "nested session" 错误 # - export TERM 保证 CC 可以正常渲染 local launch_cmd launch_cmd="unset CLAUDECODE CLAUDE_CODE; export TERM=xterm-256color; exec '$CLAUDE_BIN'" # 在 tmux 中启动 claude # - set history-limit 为大滚动缓冲区,确保长会话不丢内容 tmux new-session -d -s "$TMUX_NAME" -x 220 -y 50 "bash --login -c '$launch_cmd'" ``` ### Technical Analysis The script permits the `CLAUDE_BIN` environment variable to override the expected Claude Code executable. It then interpolates that value into `launch_cmd`, which is embedded inside another command string passed to `bash --login -c`. The single quotes around `CLAUDE_BIN` do not provide a reliable security boundary because the resulting string is subsequently nested inside another single-quoted shell command. A malicious value containing quote characters and shell metacharacters can terminate the intended quoting context and append arbitrary commands. This is a command-construction vulnerability: untrusted or insufficiently validated data becomes shell syntax instead of remaining a single executable-path argument. ### Attack Path 1. An attacker gains influence over the environment used to launch OpenClaw or the bridge, such as through a service configuration, wrapper script, deployment variable, compromised shell initialization, or another environment-injection weakness. 2. The attacker sets `CLAUDE_BIN` to a value containing quote-breaking syntax and an additional shell command. 3. A user or agent invokes: ```bash cc-bridge.sh "<session_id>" start ``` 4. `do_start` interpolates the malicious value into `launch_cmd`. 5. The nested `bash --login -c` evaluates the injected syntax. 6. The attacker's comm ...[truncated 614 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not build a nested shell command by concatenating `CLAUDE_BIN`. - Validate that the configured executable is an absolute path to an expected, executable regular file. - Reject values containing control characters or shell syntax rather than attempting to escape them manually. - Prefer passing the executable as a positional parameter so it remains data: ```bash [[ "$CLAUDE_BIN" == /* ]] || { echo "[cc-bridge] CLAUDE_BIN must be an absolute path" >&2 return 1 } [[ -f "$CLAUDE_BIN" && -x "$CLAUDE_BIN" ]] || { echo "[cc-bridge] CLAUDE_BIN is not an executable file" >&2 return 1 } tmux new-session -d -s "$TMUX_NAME" -x 220 -y 50 \ env -u CLAUDECODE -u CLAUDE_CODE TERM=xterm-256color \ "$CLAUDE_BIN" ``` - If a login shell is strictly required, supply the executable through a positional parameter rather than interpolating it: ```bash tmux new-session -d -s "$TMUX_NAME" -x 220 -y 50 \ bash --login -c 'unset CLAUDECODE CLAUDE_CODE; export TERM=xterm-256color; exec "$1"' \ cc-bridge "$CLAUDE_BIN" ``` - Consider removing the environment override entirely when runtime configurability is unnecessary. - Run the bridge under a dedicated, least-privileged operating-system account. ]]>
