Skip to content

Telegram: Missing user-level access control — any user can trigger bot via @mention in any group #7651

@xandersbell

Description

@xandersbell

Problem

Hermes's Telegram integration has no user-level access control for group chats. Any Telegram user can add the bot to their own group and trigger it via @mention — without any authorization check.

Current Behavior

When a message passes through _should_process_message() (gateway/platforms/telegram.py), the only group access controls are:

  1. Is the chat in free_response_chats? → allow
  2. Is require_mention=false? → allow
  3. Is it a command? → allow
  4. Does it reply to the bot? → allow
  5. Does it @mention the bot? → allow
  6. Does it match mention_patterns? → allow

There is NO user ID check. Anyone can trigger the bot in any group.

TELEGRAM_ALLOWED_USERS is Ineffective

TELEGRAM_ALLOWED_USERS is mapped in the config but only used in one place — the approval button callback (telegram.py:1462). It does not gate message processing.

Compare with WeChat, which correctly implements this:

# gateway/config.py
weixin_allowed_users = os.getenv("WEIXIN_ALLOWED_USERS", "").strip()
if weixin_allowed_users:
    extra["allow_from"] = weixin_allowed_users

weixin_group_allowed_users = os.getenv("WEIXIN_GROUP_ALLOWED_USERS", "").strip()
if weixin_group_allowed_users:
    extra["group_allow_from"] = weixin_group_allowed_users

Telegram has no equivalent.

Security Impact

Any Telegram user can:

  1. Add the bot to any group they control
  2. @mention the bot to trigger responses
  3. Invoke any tool the bot has access to (file operations, code execution, etc.)

This is a significant security gap for production deployments.

Expected Behavior

Add TELEGRAM_ALLOWED_USERS and TELEGRAM_GROUP_ALLOWED_USERS support for Telegram, mirroring the WeChat implementation:

  • TELEGRAM_ALLOWED_USERS — whitelist of user IDs who can interact with the bot
  • TELEGRAM_GROUP_ALLOWED_USERS — whitelist of user IDs who can trigger the bot in groups (beyond existing mention/pattern controls)

Suggested Fix

In gateway/config.py, add Telegram's user/group allowlist mapping alongside the existing WeChat implementation, then check allow_from in _should_process_message() before allowing group message processing.

References

  • WeChat implementation: gateway/config.py:1012-1017, gateway/platforms/weixin.py
  • Telegram group trigger logic: gateway/platforms/telegram.py:_should_process_message()

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundcomp/gatewayGateway runner, session dispatch, deliveryplatform/telegramTelegram bot adaptertype/securitySecurity vulnerability or hardening

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions