Repository navigation
fix(allowlist): check contact_id/group_id chats and hide unallowed chats in listings - #323
Merged
chigwell merged 2 commits intoOct 17, 2026
Conversation
…ats in listings TELEGRAM_ALLOWED_CHAT_IDS was only enforced for parameters named chat_id, from_chat_id, to_chat_id and channel. Tools whose chat parameter had another name bypassed it: get_last_interaction(contact_id) read the last messages of any private chat, and invite_to_group/promote_admin/demote_admin(group_id) changed groups outside the allowlist. Listing tools also revealed the titles and IDs of unallowed chats: get_common_chats, get_contact_chats (common chats), get_direct_chat_by_contact and get_folder. create_folder accepted unallowed chat_ids. - contact_id and group_id are now checked like chat_id by @validate_id - the listing tools drop chats outside the allowlist (get_folder also drops peers it cannot resolve, since those cannot be checked) - create_folder refuses an unallowed chat after resolving it - README lists the newly covered tools Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018Xun6C4mXUAKbVSmiEEh79
…llowed path Review feedback. utils.get_peer_id() raises ValueError for InputPeerSelf, so create_folder with 'me' in chat_ids started failing under an allowlist check that does not apply to the account's own chat. Skip the check for InputPeerSelf. Add positive tests: an allowlisted group_id still reaches invite_to_group, and Saved Messages is accepted with and without an allowlist. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018Xun6C4mXUAKbVSmiEEh79
chigwell
approved these changes
Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #322
Before
With
TELEGRAM_ALLOWED_CHAT_IDS=101:get_last_interaction(contact_id=202)returned the last messages of user 202's private chat, whileget_messages(chat_id=202)was refused — the same chat was readable through a differently named parameter.invite_to_group(group_id=…),promote_admin(group_id=…)anddemote_admin(group_id=…)changed groups outside the allowlist.get_common_chats,get_contact_chats(common chats),get_direct_chat_by_contactandget_folderreturned the titles and IDs of unallowed chats.create_folder(chat_ids=[202, …])added an unallowed chat to a newly created folder.The README promises that with an allowlist "all other conversations remain completely invisible to the agent".
After
CHAT_PARAM_NAMESnow includescontact_id(the private chat with that contact) andgroup_id(the administered group), so all five tools are checked through their existing@validate_iddecorators.user_idstays out on purpose: it names a member acted on inside an already-checked chat.get_common_chats,get_contact_chats,get_direct_chat_by_contactandget_folderdrop chats outside the allowlist. Under an allowlist,get_folderalso drops peers it cannot resolve, because they cannot be checked.create_folderchecks each resolved chat and refuses an unallowed one, keeping its plain-string error contract.InputPeerSelf("me"/ Saved Messages) short-circuits the check: the account's own chat has no peer id to check and is always allowed.Tests
tests/test_chat_allowlist.py, one per bypass plus positive pins: every bypass fails onmainand passes with this change; an allowlistedgroup_idstill reachesinvite_to_group, andcreate_folder(chat_ids=["me"])keeps working with and without an allowlist.black --checkandflake8 --select=E9,F63,F7,F82are clean on the changed files.Not changed
set_contact_aliasandresolve_usernamecan still return the profile name or ID of a target outside the allowlist, andget_contact_idsstill returns the full contact ID list. They read no messages and change no chat, so they are left for a separate decision.🤖 Generated with Claude Code