Skip to content

fix(allowlist): check contact_id/group_id chats and hide unallowed chats in listings - #323

Merged
chigwell merged 2 commits into
chigwell:mainfrom
axisrow:upstream/allowlist-contact-group-params
Oct 17, 2026
Merged

chigwell merged 2 commits into
chigwell:mainfrom
axisrow:upstream/allowlist-contact-group-params

Conversation

@axisrow

@axisrow axisrow commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

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, while get_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=…) and demote_admin(group_id=…) changed groups outside the allowlist.
  • get_common_chats, get_contact_chats (common chats), get_direct_chat_by_contact and get_folder returned 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_NAMES now includes contact_id (the private chat with that contact) and group_id (the administered group), so all five tools are checked through their existing @validate_id decorators. user_id stays out on purpose: it names a member acted on inside an already-checked chat.
  • get_common_chats, get_contact_chats, get_direct_chat_by_contact and get_folder drop chats outside the allowlist. Under an allowlist, get_folder also drops peers it cannot resolve, because they cannot be checked.
  • create_folder checks 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.
  • The README allowlist section lists the newly covered tools.

Tests

  • 12 new test cases in tests/test_chat_allowlist.py, one per bypass plus positive pins: every bypass fails on main and passes with this change; an allowlisted group_id still reaches invite_to_group, and create_folder(chat_ids=["me"]) keeps working with and without an allowlist.
  • Full suite: 1247 passed.
  • black --check and flake8 --select=E9,F63,F7,F82 are clean on the changed files.

Not changed

set_contact_alias and resolve_username can still return the profile name or ID of a target outside the allowlist, and get_contact_ids still 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

…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
chigwell merged commit 9a54bf8 into chigwell:main Oct 17, 2026
4 checks passed
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.

TELEGRAM_ALLOWED_CHAT_IDS is bypassed via contact_id/group_id tool parameters, and listing tools reveal unallowed chats

3 participants