feat(telegram): deny-by-default sender allowlist + command menu (16.33, 16.34)

Allowlist (16.33). telegram.New was called with a nil allowlist and
isChatAllowed returned true whenever the list was empty, so any Telegram
user who found the bot could talk to it; AllowedChatIDs was not plumbed
into config, so there was no way to close it. Chat tools run with the
daemon's own authority, so this had to be fixed before wiring any real
tools to the chat agent.

Now chat.telegram.allowed_user_ids configures it and an empty list denies
everyone: a bot handle is public, so failing open is not a safe default.
The check matches the sender (from.id) rather than the chat, so adding
the bot to a group cannot be used to inherit access. Rejections log the
sender id and answer once, so a legitimate user missing from the list can
tell the bot is misconfigured rather than dead. Startup warns when the
gateway is enabled with an empty list.

The previous TestIsChatAllowed asserted 'empty allowlist allows all' --
it encoded the vulnerability -- and is replaced by fail-closed tests.

Command menu (16.34). SetMyCommands was never called, so Telegram showed
no menu and the commands Router implements were undiscoverable; asked
about /commands the LLM confidently answered it had none. The published
list mirrors what Router actually handles. Failure is logged, not fatal:
it costs discoverability, not function.
This commit is contained in:
sam committed 2026-07-27 05:14:34 +10:00
1 parent 285c618f74
commit cb147b7a37
6 files changed
+114 -35

No files matched your search

+8 -1
View File
@@ -268,7 +268,14 @@ func run() int {
log.Error("chat.telegram configured but token env var is empty", "env", cfg.Chat.Telegram.TokenEnv)
return 1
}
tg := telegram.New(tgToken, "", "", nil, log)
// Deny-by-default: an empty allowlist blocks everyone. A bot handle
// is public, so failing open would expose the chat agent's tools,
// which run with this daemon's authority, to any stranger.
if len(cfg.Chat.Telegram.AllowedUserIDs) == 0 {
log.Warn("chat.telegram has no allowed_user_ids: every sender will be rejected. " +
"Add your Telegram user id to chat.telegram.allowed_user_ids to enable the bot.")
}
tg := telegram.New(tgToken, "", "", cfg.Chat.Telegram.AllowedUserIDs, log)
// Session store backed by the same NellDB log as task state.
// Sessions and messages survive daemon restarts.