Back to skill

Security audit

Telegram Bot Manager

Security checks for vulnerabilities and agentic risk

Overview

This Telegram/OpenClaw helper is mostly purpose-aligned, but it should be reviewed because it handles bot tokens in ways that can expose them locally.

Review before installing if the bot token is sensitive or production-grade. Use a disposable or rotated token, avoid passing tokens as command-line arguments, check that OpenClaw config and backup files are owner-only readable, and run the sudo webhook setup commands only on systems where you intend to change nginx, firewall, and certificate configuration.

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 (2)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/setup_bot.py:42
Finding

OpenClaw configuration secrets are copied into files without enforced restrictive permissions

Content
View full analysis

Vulnerability Details

File Location: scripts/setup_bot.py:42-55, scripts/setup_bot.py:76-105
Vulnerability Type: Plaintext sensitive-data storage with insecure file permissions
Risk Level: High

Vulnerable Code

python
def backup_config(self) -> bool:
    """Backup existing config"""
    if not self.config_path.exists():
        print(f"\nℹ️  No existing config found at {self.config_path}")
        return True

    backup_path = self.config_path.with_suffix('.json.backup')

    try:
        with open(self.config_path, 'r') as f:
            config = json.load(f)

        with open(backup_path, 'w') as f:
            json.dump(config, f, indent=2)

        print(f"\n✅ Backed up existing config to {backup_path}")
        return True
python
def update_config(self, bot_token: str) -> bool:
    """Update OpenClaw config with Telegram settings"""
    print(f"\n📝 Updating OpenClaw configuration...")

    config = self.load_config()

    # Ensure telegram section exists
    if 'telegram' not in config:
        config['telegram'] = {}

    # Update telegram settings
    config['telegram'].update({
        'enabled': True,
        'token': bot_token,
        'pairing': True,
        'streamMode': 'partial'
    })

    # Ensure telegram plugin is enabled
    if 'plugins' not in config:
        config['plugins'] = []

    if 'telegram' not in config['plugins']:
        config['plugins'].append('telegram')

    try:
        # Write updated config
        with open(self.config_path, 'w') as f:
            json.dump(config, f, indent=2)

Technical Analysis

The setup script stores the Telegram bot token directly in /home/openclaw/.openclaw/openclaw.json. It also copies the entire existing configuration into the predictable backup file /home/openclaw/.openclaw/openclaw.json.backup.

Neither operation explicitly creates the destination with ...[truncated 1877 chars]

Remediation
View remediation

Remediation Suggestions

  1. Create configuration and backup files with owner-only permissions:
    python
    fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
    with os.fdopen(fd, "w") as f:
        json.dump(config, f, indent=2)
    
  2. Apply os.chmod(path, 0o600) and verify that the file is owned by the expected OpenClaw account.
  3. Confirm that /home/openclaw/.openclaw is not writable or traversable by unauthorized users.
  4. Write updates to a securely created temporary file in the same directory, flush and synchronize it, set mode 0600, and atomically replace the destination with os.replace().
  5. Avoid copying the full configuration into an unprotected backup. If a backup is required, protect it identically to the primary configuration and document its secret-bearing nature.
  6. Prefer a secret manager, protected credential file, or environment-variable reference instead of embedding the token directly in JSON.
  7. Validate file type and ownership before overwriting either destination to reduce unsafe link or unexpected-file handling.

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/setup_bot.py:189
Finding

Telegram bot tokens are exposed through interactive echo, terminal output, process arguments, shell history, and URL-based commands

Content
View full analysis

Vulnerability Details

File Location: scripts/setup_bot.py:30, scripts/setup_bot.py:189-209; scripts/test_bot.py:188-200; README.md:75-80; SKILL.md:29-30; references/OPENCLAW_CONFIG.md:243-251; references/WEBHOOK_SETUP.md:93-99, 359-365
Vulnerability Type: Sensitive credential disclosure
Risk Level: Medium

Vulnerable Code

The setup prompt uses ordinary input(), which displays the secret as it is typed:

python
token = input("\nEnter your bot token: ").strip()

The setup script subsequently prints the complete token into the terminal:

python
def show_next_steps(self, bot_token: str):
    """Show next steps for using the bot"""
    print(f"\n" + "=" * 60)
    print("🎉 Setup Complete!")
    print("=" * 60)

    print(f"\n📱 Next Steps:")
    print(f"1. Open Telegram and search for your bot")
    print(f"2. Send /start to begin conversation")
    print(f"3. The bot will provide pairing instructions")
    print(f"4. Follow the pairing process to link your Telegram account")

    print(f"\n🔧 Manual Commands:")
    print(f"   Check status: openclaw status")
    print(f"   View logs: openclaw gateway logs -f")
    print(f"   Restart: openclaw gateway restart")

    print(f"\n🧪 Testing:")
    print(f"   Run: python3 telegram-bot-manager/scripts/test_bot.py")
    print(f"   Or: export TELEGRAM_BOT_TOKEN={bot_token}")
    print(f"        python3 telegram-bot-manager/scripts/test_bot.py")

The test script accepts the token as a positional command-line argument:

python
def main():
    """Main function"""
    # Get bot token from environment or argument
    bot_token = os.getenv('TELEGRAM_BOT_TOKEN')

    if len(sys.argv) > 1:
        bot_token = sys.argv[1]

    if not bot_token:
        print("❌ No bot token provided")
        print("\nUsage:")
        print("  python3 test_bot.py YOUR_BOT_TOKEN")
        print("  or")
        print
...[truncated 3572 chars]
Remediation
View remediation

Remediation Suggestions

  1. Replace visible token entry with hidden input:
    python
    from getpass import getpass
    token = getpass("Enter your bot token: ").strip()
    
  2. Never print the token or construct an export command containing its value. Display only a redacted fingerprint if identification is necessary.
  3. Remove positional command-line token support from test_bot.py.
  4. Accept the token through a protected secret manager, a restricted credential file, or an environment variable injected without being typed into shell history.
  5. Warn users that environment variables may still be exposed through debugging dumps or inherited by child processes.
  6. Remove all documentation that recommends embedding tokens in command lines.
  7. For monitoring, read the token from a mode-0600 credential file or secret-management facility rather than assigning it in the script.
  8. Use POST requests where supported, suppress verbose command output, and ensure application, proxy, and CI logging systems redact Telegram token patterns.
  9. Rotate any token that has already appeared in shell history, logs, recordings, or committed scripts by using BotFather’s revocation workflow.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
Findings (36)

Tp4

High
Category
MCP Tool Poisoning
Confidence
99% confidence
Finding

The code does not perform Telegram bot management, token validation, webhook configuration, network connectivity checks, or any interaction with api.telegram.org. Instead, its primary purpose is to validate and package a generic skill into a .skill file for distribution/upload. This is a materially different purpose from the declared Telegram integration management functionality, so the description does not accurately represent the code.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The README includes a real-looking Telegram bot token in command examples and explicitly demonstrates passing it as a positional command-line argument. Even if the token is illustrative, users may copy this pattern into real use, exposing secrets via shell history, process listings, logs, or terminal recordings. In the context of a bot-management skill, this is more dangerous because handling bot tokens is a core workflow and readers are likely to reuse the exact examples.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
93% confidence
Finding

The skill documentation instructs use of shell commands, network access, and references local files/scripts, yet the manifest does not declare any tool scope or allowed tools. This creates an under-specified trust boundary: an agent may execute capabilities broader than reviewers or policy expect, increasing the chance of unintended file, environment, or network access during bot management tasks.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The token-validation example embeds the bot token directly in a curl command, which will transmit the secret to Telegram and may expose it in shell history, terminal logs, process listings, or agent telemetry. Because Telegram bot tokens grant control of the bot, accidental disclosure can lead to bot takeover, message access, impersonation, or forced token rotation.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The examples show bot tokens embedded directly in JSON config, environment variable exports, and URL-based curl commands without warning that these secrets may be exposed through shell history, process listings, logs, browser/terminal recordings, or accidental copy/paste. In a bot-management skill, this is especially risky because users are likely to substitute real production tokens verbatim.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The documentation warns not to commit tokens, yet elsewhere includes realistic-looking bot token examples and export snippets that normalize placing secrets directly into files and shell commands. Even if the tokens are placeholders, this pattern increases the chance users paste real credentials into configs, screenshots, shell history, logs, or version control.

Content

No source excerpt is available for this finding.

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 51)May include surrounding context.

md
# Set up DNS A record pointing to your server IP

# Install certbot for Let's Encrypt
sudo apt update
sudo apt install certbot python3-certbot-nginx

# Get SSL certificate

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 52)May include surrounding context.

md
# Set up DNS A record pointing to your server IP

# Install certbot for Let's Encrypt
sudo apt update
sudo apt install certbot python3-certbot-nginx

# Get SSL certificate

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 264)May include surrounding context.

md
# Set up DNS A record pointing to your server IP

# Install certbot for Let's Encrypt
sudo apt update
sudo apt install certbot python3-certbot-nginx

# Get SSL certificate

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 302)May include surrounding context.

md
# Set up DNS A record pointing to your server IP

# Install certbot for Let's Encrypt
sudo apt update
sudo apt install certbot python3-certbot-nginx

# Get SSL certificate

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/OPENCLAW_CONFIG.md (reported line 127)May include surrounding context.

sudo apt install certbot python3-certbot-nginx

Get SSL certificate

sudo certbot --nginx -d your-domain.com

text

#### Firewall Configuration

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 55)May include surrounding context.

sudo apt install certbot python3-certbot-nginx

Get SSL certificate

sudo certbot --nginx -d your-domain.com

text

#### Firewall Configuration

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 62)May include surrounding context.

sudo apt install certbot python3-certbot-nginx

Get SSL certificate

sudo certbot --nginx -d your-domain.com

text

#### Firewall Configuration

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 63)May include surrounding context.

sudo apt install certbot python3-certbot-nginx

Get SSL certificate

sudo certbot --nginx -d your-domain.com

text

#### Firewall Configuration

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 164)May include surrounding context.

sudo apt install certbot python3-certbot-nginx

Get SSL certificate

sudo certbot --nginx -d your-domain.com

text

#### Firewall Configuration

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 165)May include surrounding context.

sudo apt install certbot python3-certbot-nginx

Get SSL certificate

sudo certbot --nginx -d your-domain.com

text

#### Firewall Configuration

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
70% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/WEBHOOK_SETUP.md (reported line 267)May include surrounding context.

sudo apt install certbot python3-certbot-nginx

Get SSL certificate

sudo certbot --nginx -d your-domain.com

text

#### Firewall Configuration

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

The manifest describes managing Telegram bot setup, token validation, and connectivity to api.telegram.org. While editing OpenClaw configuration fits that scope, invoking openclaw gateway restart adds host-level process control via subprocess execution, which is a broader operational capability than the stated Telegram-management purpose requires.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/setup_bot.py (reported line 167)May include surrounding context.

python
print(f"\n🔄 Restarting OpenClaw gateway...")
        
        try:
            result = subprocess.run(
                ['openclaw', 'gateway', 'restart'],
                capture_output=True,
                text=True,

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

The script prints the full bot token in a suggested export command, which can expose the secret in terminal scrollback, logs, screenshots, and shell history if the command is copied verbatim. A Telegram bot token grants control over the bot API, so disclosure can let an unauthorized party impersonate or abuse the bot.

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 · SKILL.md (reported line 30)May include surrounding context.

md
class TelegramBotTester:
    def __init__(self, bot_token: str):
        self.bot_token = bot_token
        self.base_url = f"https://api.telegram.org/bot{bot_token}"
        
    def test_connectivity(self) -> bool:
        """Test basic connectivity to Telegram API"""

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 · references/OPENCLAW_CONFIG.md (reported line 106)May include surrounding context.

md
class TelegramBotTester:
    def __init__(self, bot_token: str):
        self.bot_token = bot_token
        self.base_url = f"https://api.telegram.org/bot{bot_token}"
        
    def test_connectivity(self) -> bool:
        """Test basic connectivity to Telegram API"""

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 · references/OPENCLAW_CONFIG.md (reported line 245)May include surrounding context.

md
class TelegramBotTester:
    def __init__(self, bot_token: str):
        self.bot_token = bot_token
        self.base_url = f"https://api.telegram.org/bot{bot_token}"
        
    def test_connectivity(self) -> bool:
        """Test basic connectivity to Telegram API"""

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 · references/OPENCLAW_CONFIG.md (reported line 251)May include surrounding context.

md
class TelegramBotTester:
    def __init__(self, bot_token: str):
        self.bot_token = bot_token
        self.base_url = f"https://api.telegram.org/bot{bot_token}"
        
    def test_connectivity(self) -> bool:
        """Test basic connectivity to Telegram API"""

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 · references/WEBHOOK_SETUP.md (reported line 96)May include surrounding context.

md
class TelegramBotTester:
    def __init__(self, bot_token: str):
        self.bot_token = bot_token
        self.base_url = f"https://api.telegram.org/bot{bot_token}"
        
    def test_connectivity(self) -> bool:
        """Test basic connectivity to Telegram API"""

Static analysis

No suspicious patterns detected.