T09 · Insecure Skill Coding Practices
Error
- Location
- lib/cb-common.sh:31
- Finding
- Configuration File Is Executed as Unrestricted Shell Code<![CDATA[ ## Vulnerability Details **File Location**: `lib/cb-common.sh:31-39` **Vulnerability Type**: Arbitrary code execution through unsafe configuration loading **Risk Level**: High ### Vulnerable Code ```bash # 加载配置 # Usage: cb_load_config # 设置: CLAWBARS_SERVER, CLAWBARS_API_KEY, CLAWBARS_USER_TOKEN cb_load_config() { local config_file="${CLAWBARS_CONFIG:-$HOME/.clawbars/config}" # 从配置文件加载(如果存在) if [[ -f "$config_file" ]]; then # shellcheck source=/dev/null source "$config_file" fi ``` ### Technical Analysis `cb_load_config` treats `~/.clawbars/config`, or the path supplied through `CLAWBARS_CONFIG`, as executable shell code. The `source` builtin does not parse only configuration assignments: it executes functions, command substitutions, redirections, process launches, and any other shell syntax contained in the file. Nearly every capability and scenario script sources `cb-common.sh` and invokes `cb_load_config`. Consequently, modifying this nominal configuration file creates a broad code-execution path that activates when a normal ClawBars operation is run. The risk is increased because `CLAWBARS_CONFIG` can redirect loading to an arbitrary local file. The implementation performs no ownership, permission, symlink, or content validation before executing it. ### Attack Path 1. An attacker obtains write access to `~/.clawbars/config`, supplies a malicious shared configuration file, or influences the `CLAWBARS_CONFIG` environment variable. 2. The attacker inserts shell commands, for example a command substitution or executable statement, into that file. 3. The victim invokes any capability or scenario that calls `cb_load_config`. 4. `source "$config_file"` executes the attacker-controlled commands in the current shell. 5. The commands inherit the invoking process's filesystem access, environment, network access, and ClawBars credentials. ### Impact Assessment Successful exploitation provides arbitrary command execut ...[truncated 387 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not use `source`, `.`, `eval`, or shell execution to load configuration. - Parse an allowlist containing only `CLAWBARS_SERVER`, `CLAWBARS_API_KEY`, and `CLAWBARS_USER_TOKEN`. - Reject command substitutions, shell metacharacters, functions, redirections, and unknown keys. - Validate that the configuration is a regular file, is owned by the invoking user, is not a symbolic link, and is not group- or world-writable. - Require restrictive permissions such as mode `0600` because the file may contain credentials. - Prefer a non-executable format such as JSON and parse it with `jq`. - Treat `CLAWBARS_CONFIG` as a trusted administrative setting or validate its resolved path before use. ]]>
