Skip to content

Add --allowed-bot-ids option to whitelist bots - #892

Open
yagop wants to merge 1 commit into
tdlib:masterfrom
yagop:allowed-bot-ids
Open

Add --allowed-bot-ids option to whitelist bots#892
yagop wants to merge 1 commit into
tdlib:masterfrom
yagop:allowed-bot-ids

Conversation

@yagop

@yagop yagop commented Aug 25, 2026

Copy link
Copy Markdown

Adds an optional --allowed-bot-ids command-line option that takes a comma-separated list of bot user identifiers permitted to use the server.

When the option is set, a request whose bot user id is not in the list is rejected with 401 Unauthorized: bot is not allowed to use the server in ClientManager::send, before any Client is created — so unknown bots can't consume server resources (memory, TDLib instances, database entries). When the option is omitted the behavior is unchanged: all bots are allowed.

This complements the existing --filter option: --filter partitions bots across server instances by bot_user_id % modulo, whereas --allowed-bot-ids restricts the server to an explicit allowlist, which is useful for single-tenant or private deployments.

Changes

  • ClientParameters: add allowed_bot_user_ids_ (empty means all bots allowed).
  • telegram-bot-api.cpp: parse and validate the --allowed-bot-ids option.
  • ClientManager::send: reject bot ids outside the allowlist with 401.

When specified, requests for bot user identifiers outside the
comma-separated list are rejected with 401 before a client is created,
so unknown bots can't consume server resources. By default all bots
are allowed.
@levlam

levlam commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

The server must be either available only from a private network or to be available through a TLS termination proxy. In the first case it makes no sense to restrict allowed bots. In the second case the restriction is better to be done on the proxy side. The option filter exists only as a sanity check to discard misrouted requests.

@yagop

yagop commented Aug 25, 2026

Copy link
Copy Markdown
Author

I'm running my telegram-bot-api in a public exposed Fly.io instance.

Fly.io handles the TLS certificates (we can't do any kind of authorization). Many other cloud providers may handle the certificates too. Thus the need of --allowed-bot-ids.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants