Back to skill

Security audit

Telegram Group Chat Setup

Security checks for vulnerabilities and agentic risk

Overview

The skill serves a legitimate Telegram setup task, but its helper script handles the bot token unsafely and could be tricked into running unintended local code.

Review before installing. Use only if you trust the skill and are comfortable with it reading the local MoltBot gateway config, using the Telegram bot token with Telegram's getMe API, patching gateway configuration, restarting the gateway, and allowing the bot to receive all group messages when privacy mode is disabled. The helper script should be fixed to pass the config path and API response as data rather than interpolating them into Python source before use.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/detect_bot_info.sh:16
Finding

Arbitrary Python Code Execution Through Unsafe Data Interpolation

Content
View full analysis

Vulnerability Details

File Location: scripts/detect_bot_info.sh, lines 16–52
Vulnerability Type: Python source injection
Risk Level: High

Vulnerable Code

bash
# Extract bot token from config
BOT_TOKEN=$(python3 -c "
import json, sys
with open('$CONFIG_PATH') as f:
    cfg = json.load(f)
# Support single account or multi-account
tg = cfg.get('channels', {}).get('telegram', {})
token = tg.get('botToken', '')
if not token:
    # Try first account
    accounts = tg.get('accounts', {})
    for acc in accounts.values():
        token = acc.get('botToken', '')
        if token:
            break
if not token:
    print(json.dumps({'error': 'No Telegram bot token found in config'}), file=sys.stderr)
    sys.exit(1)
print(token)
")

# Call Telegram getMe API
RESPONSE=$(curl -s "https://api.telegram.org/bot${BOT_TOKEN}/getMe")

# Parse and output
python3 -c "
import json, sys
data = json.loads('''$RESPONSE''')
if not data.get('ok'):
    print(json.dumps({'error': 'Telegram API error', 'details': data}), file=sys.stderr)
    sys.exit(1)
result = data['result']
print(json.dumps({
    'id': result['id'],
    'name': result.get('first_name', ''),
    'username': result.get('username', ''),
    'can_join_groups': result.get('can_join_groups', False),
    'can_read_all_group_messages': result.get('can_read_all_group_messages', False)
}))
"

Technical Analysis

The script embeds two variable values directly into source code passed to python3 -c:

  1. CONFIG_PATH is inserted into the expression with open('$CONFIG_PATH').
  2. The complete Telegram API response is inserted into json.loads('''$RESPONSE''').

Shell quoting does not make these values safe within the resulting Python program. A single quote in CONFIG_PATH, or a triple-single-quote sequence followed by Python syntax in RESPONSE, can terminate the intended Python string literal. T ...[truncated 2659 chars]

Remediation
View remediation

Remediation Suggestions

Never place variable data inside dynamically generated Python source. Pass the configuration path as a positional argument:

bash
BOT_TOKEN=$(python3 - "$CONFIG_PATH" <<'PY'
import json
import sys

with open(sys.argv[1], encoding="utf-8") as config_file:
    cfg = json.load(config_file)

tg = cfg.get("channels", {}).get("telegram", {})
token = tg.get("botToken", "")

if not token:
    accounts = tg.get("accounts", {})
    for account in accounts.values():
        token = account.get("botToken", "")
        if token:
            break

if not token:
    print(
        json.dumps({"error": "No Telegram bot token found in config"}),
        file=sys.stderr,
    )
    sys.exit(1)

print(token)
PY
)

Pass the API response through standard input so that the JSON parser receives it strictly as data:

bash
RESPONSE=$(curl --fail --show-error --silent \
    "https://api.telegram.org/bot${BOT_TOKEN}/getMe")

printf '%s' "$RESPONSE" | python3 -c '
import json
import sys

data = json.load(sys.stdin)
if not data.get("ok"):
    print(
        json.dumps({
            "error": "Telegram API error",
            "details": data,
        }),
        file=sys.stderr,
    )
    sys.exit(1)

result = data["result"]
print(json.dumps({
    "id": result["id"],
    "name": result.get("first_name", ""),
    "username": result.get("username", ""),
    "can_join_groups": result.get("can_join_groups", False),
    "can_read_all_group_messages":
        result.get("can_read_all_group_messages", False),
}))
'

Additional hardening should include:

  • Use curl --fail --show-error --silent so HTTP and transport errors cause a failure.
  • Set explicit connection and total timeouts.
  • Validate that the response content type and structure match the expected Telegram API schema.
  • Avoid logging the bot token or request URL because the token i ...[truncated 257 chars]
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (6)

Tp4

High
Category
MCP Tool Poisoning
Confidence
99% confidence
Finding

The skill claims it will safely patch gateway configuration, but the documented behavior also includes extracting a Telegram bot token from gateway config and calling an external API. This mismatch is dangerous because operators may approve the skill for one purpose while overlooking credential access and outbound network behavior, weakening informed consent and security review.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
93% confidence
Finding

The skill instructs use of shell execution (bash skills/groupchat-setup/scripts/detect_bot_info.sh) but does not declare any tool scope or allowed-tools boundaries. Undeclared shell capability increases risk because reviewers and enforcement layers cannot accurately constrain what the skill may execute, making abuse or accidental execution of unsafe commands more likely.

Content

No source excerpt is available for this finding.

External Transmission

Medium
Category
Data Exfiltration
Confidence
90% confidence
Finding

The skill instructs extracting the Telegram bot token from gateway configuration and embedding it in a request to https://api.telegram.org/bot<TOKEN>/getMe. Even though Telegram is the legitimate service, this is still external transmission of a sensitive credential and creates exposure through logs, shell history, proxies, debugging output, or misuse of the token if handling is not tightly controlled.

Content

Scanner excerpt · SKILL.md (reported line 56)May include surrounding context.

md
This reads the bot token from the gateway config and returns the bot's `name` and `username`.
If the script is unavailable, extract the bot token from `channels.telegram.botToken` in the
gateway config and call `https://api.telegram.org/bot<TOKEN>/getMe`.

### Step 2: Build mention patterns

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The document explicitly recommends disabling Telegram privacy mode so the bot can receive all group messages, but it does not prominently warn that this expands message collection to all group content, including messages not directed at the bot. In the context of a setup skill, users may follow these steps without understanding the privacy, consent, and data-handling implications for group participants.

Content

No source excerpt is available for this finding.

External Transmission

Medium
Category
Data Exfiltration
Confidence
60% confidence
Finding

Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.

Content

Scanner excerpt · scripts/detect_bot_info.sh (reported line 37)May include surrounding context.

sh
")

# Call Telegram getMe API
RESPONSE=$(curl -s "https://api.telegram.org/bot${BOT_TOKEN}/getMe")

# Parse and output
python3 -c "

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

This code reads a bot token from a local config file and immediately uses it in an outbound network request to api.telegram.org. Although calling Telegram is part of the script's functionality, the file contains no prompt, warning, or user-facing disclosure that a credential from local configuration will be sent over the network.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.