T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/autothread-telegram.sh:39
- Finding
- Unrestricted Telegram API endpoint override can disclose bot credentials and message content<![CDATA[ ## Vulnerability Details **File Location**: `scripts/autothread-telegram.sh:39-46, 81-83, 101-105, 113-117` **Vulnerability Type**: Unvalidated security-sensitive endpoint override **Risk Level**: High ### Vulnerable Code ```bash # AUTOTHREAD_OVERRIDE_TOKEN lets wrapper adapters (e.g. Nicegram) inject # a platform-specific token instead of the default Telegram one. BOT_TOKEN="${AUTOTHREAD_OVERRIDE_TOKEN:-}" if [ -z "$BOT_TOKEN" ]; then BOT_TOKEN=$(autothread_config_get '.channels.telegram.botToken // empty') fi # AUTOTHREAD_API_BASE is overridable for offline testing with a mock API. API="${AUTOTHREAD_API_BASE:-https://api.telegram.org}" ``` The attacker-controlled endpoint is subsequently used in requests containing the bot token, message content, sender attribution, and destination identifiers: ```bash CREATE_RESULT=$(curl -s "$API/bot${BOT_TOKEN}/createForumTopic" \ -d "chat_id=${CHAT_ID}" \ --data-urlencode "name=${TITLE}") ``` ```bash SEND_RESULT=$(curl -s "$API/bot${BOT_TOKEN}/sendMessage" \ -d "chat_id=${CHAT_ID}" \ -d "message_thread_id=${TOPIC_ID}" \ --data-urlencode "text=${QUOTED}" \ -d "parse_mode=HTML") ``` ```bash FWD_RESULT=$(curl -s "$API/bot${BOT_TOKEN}/forwardMessage" \ -d "chat_id=${CHAT_ID}" \ -d "from_chat_id=${CHAT_ID}" \ -d "message_id=${MESSAGE_ID}" \ -d "message_thread_id=${TOPIC_ID}") ``` ### Technical Analysis The script trusts the inherited `AUTOTHREAD_API_BASE` environment variable without validating its scheme, hostname, port, or destination. The Telegram bot token is embedded directly in each request URL as `/bot${BOT_TOKEN}/...`. If an attacker can influence the environment in which the adapter runs, the API base can be changed to an attacker-controlled HTTP or HTTPS service. The next invocation then transmits the bot token in the URL. Depending on which branch executes, the request also includes the chat ID, topic title, original message content, sender name, or original message ID. Thi ...[truncated 1300 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Hard-code `https://api.telegram.org` for production operation. 2. Remove `AUTOTHREAD_API_BASE` from the production adapter. 3. If mock-server support is required, require an explicit test mode such as `AUTOTHREAD_TEST_MODE=1`. 4. In test mode, allow only loopback destinations such as `https://127.0.0.1:<approved-port>` or a Unix socket. 5. Reject non-HTTPS destinations and validate the parsed hostname against an exact allowlist. 6. Do not place credentials in URLs when an API supports safer authentication mechanisms. Telegram requires its current URL token format, making strict destination validation especially important. 7. Sanitize the environment in the parent service before invoking adapters. 8. Add tests verifying that arbitrary domains, user-info URLs, redirects, and plaintext HTTP endpoints are rejected. 9. Consider using `curl --proto '=https' --max-redirs 0 --fail-with-body` for production requests. ]]>
