fix(telegram): add user-level access control for groups and DMs#7659
Closed
xandersbell wants to merge 0 commit into
Closed
fix(telegram): add user-level access control for groups and DMs#7659xandersbell wants to merge 0 commit into
xandersbell wants to merge 0 commit into
Conversation
Contributor
|
Why was this PR closed? |
Contributor
Author
acctually, I forgot, maybe my AI agent closed it by some reasons that I dont know ^_^ |
Contributor
Author
|
seems synced then lost the codes in the main branch, I see |
Contributor
Author
|
Follow-up: I reopened this fix as a fresh PR here: Root cause for this old PR showing The new PR uses a dedicated branch ( |
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.
Summary
Add
TELEGRAM_ALLOWED_USERSandTELEGRAM_GROUP_ALLOWED_USERSsupport to the Telegram adapter, mirroring the existing WeChat implementation (fixes #7651).Problem
Hermes's Telegram integration has no user-level access control. Any Telegram user can add the bot to their own group and trigger it via @mention — there is no way to restrict access to specific users.
Solution
Read
TELEGRAM_ALLOWED_USERSandTELEGRAM_GROUP_ALLOWED_USERSenvironment variables (or config.yamlallow_from/group_allow_fromfields) and check sender user ID before processing any message:TELEGRAM_ALLOWED_USERS: whitelist of Telegram user IDs who can DM the botTELEGRAM_GROUP_ALLOWED_USERS: whitelist of Telegram user IDs who can @mention the bot in groups"*"wildcard disables the check (backwards-compatible default)Changes
gateway/platforms/telegram.py__init__: add_allow_from,_group_allow_from; add_coerce_liststatic method;_should_process_message: add user allowlist checks before existing trigger logictests/gateway/test_telegram_group_gating.pyUsage
Or in
config.yaml:Testing
All 11 tests pass (including 5 new ones):
Refs