fix(telegram): apply bot auth policy to Telegram sources#33830
Open
sweetcornna wants to merge 1 commit into
Open
fix(telegram): apply bot auth policy to Telegram sources#33830sweetcornna wants to merge 1 commit into
sweetcornna wants to merge 1 commit into
Conversation
70fe8a6 to
6316ce7
Compare
6316ce7 to
02c5628
Compare
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.
Problem
When two Hermes profiles use separate Telegram bot tokens while polling the same account, one profile's outbound bot message can be delivered to the other gateway. Telegram messages did not carry the sender's bot-origin flag into
SessionSource, so those bot messages were evaluated as ordinary human messages and could trigger echo replies.Closes #32188.
Root Cause
Two Telegram-specific pieces were missing from the existing bot-auth path:
gateway/platforms/telegram.pydid not pass python-telegram-bot'suser.is_botthroughbuild_source(...).gateway/authz_mixin.pyhad allow-bots env mappings for Discord and Feishu, but not Telegram.gateway/config.pydid not bridgetelegram.allow_botsfromconfig.yamlintoTELEGRAM_ALLOW_BOTS.Fix
Platform.TELEGRAM: "TELEGRAM_ALLOW_BOTS"to the gateway bot-policy map.is_botintoSessionSourceduring message event construction.telegram.allow_botsfrom config YAML intoTELEGRAM_ALLOW_BOTSwhile preserving env-var precedence.TELEGRAM_ALLOW_BOTS, since Telegram now has its own bot policy.Review State
upstream/mainat9c051f57c3b1e9962feef958710ee58fa8ca2444.02c5628e407e81200f8de2f9a6c37ce978f4e12b.Verification
RED on current main before the fix:
.venv\Scripts\python.exe -m pytest tests\gateway\test_telegram_bot_auth_bypass.py tests\gateway\test_config.py::TestLoadGatewayConfig::test_bridges_telegram_allow_bots_from_config_yaml_to_env tests\gateway\test_config.py::TestLoadGatewayConfig::test_telegram_allow_bots_env_takes_precedence_over_config_yaml -q --timeout-method=thread-> 5 failed, 4 passed.GREEN after the fix:
.venv\Scripts\python.exe -m pytest tests\gateway\test_telegram_bot_auth_bypass.py tests\gateway\test_config.py tests\gateway\test_discord_bot_auth_bypass.py tests\gateway\test_feishu_bot_auth_bypass.py tests\gateway\test_telegram_format.py tests\gateway\test_telegram_mention_boundaries.py tests\gateway\test_telegram_reply_mode.py tests\gateway\test_telegram_reply_quote.py -q --timeout-method=thread-> 250 passed..venv\Scripts\ruff.exe check gateway\authz_mixin.py gateway\config.py gateway\platforms\telegram.py tests\gateway\test_config.py tests\gateway\test_telegram_bot_auth_bypass.py tests\gateway\test_discord_bot_auth_bypass.py tests\gateway\test_feishu_bot_auth_bypass.py-> passed..venv\Scripts\python.exe -m py_compile gateway\authz_mixin.py gateway\config.py gateway\platforms\telegram.py tests\gateway\test_config.py tests\gateway\test_telegram_bot_auth_bypass.py tests\gateway\test_discord_bot_auth_bypass.py tests\gateway\test_feishu_bot_auth_bypass.py-> passed.git diff --check-> passed.git merge-tree --write-tree upstream/main HEAD->5c5333999cc2745a92e86c433b9133d89e1ba581.Risk
Low. Existing non-bot Telegram sender behavior is unchanged. Bot-origin Telegram messages now follow the same explicit
none/mentions/allpolicy shape as Discord and Feishu; the default remains deny unless configured otherwise.