You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Telegram early intake authorization built a SessionSource without preserving from_user.is_bot, then fell back to the human allowlist when the multiplex profile handler was a closure with no __self__. That meant bot-authored messages were rejected before the normal gateway bot policy could admit them, even when TELEGRAM_ALLOW_BOTS was mentions or all. This PR carries the Telegram sender's bot bit into the auth source and mirrors AuthzMixin's bot-policy branch at the early prefilter before applying the human allowlist.
Changes
plugins/platforms/telegram/adapter.py: propagates message.from_user.is_bot into _source_from_message_for_auth() and admits bot-authored messages early when scoped TELEGRAM_ALLOW_BOTS resolves to mentions or all.
tests/gateway/test_telegram_auth_check.py: extends the Telegram message fixture with is_bot, adds a multiplex-closure regression for allowed bot-authored messages, and adds a negative human-sender case proving bot policy does not bypass the human allowlist.
⚠️ Termux runner/environment failure: 3197 PermissionError/permission-denied patterns in the full-suite log
Notes
An open PR (#91483) also mentions TELEGRAM_ALLOW_BOTS, but it changes gateway/authz_mixin.py to add bot-loop protection for #91481. This PR is separate and scoped to Telegram adapter early-auth intake for #92840.
.env not used for non-credential settings (behavioral settings → config.yaml)
Risk & Impact
Low. The new bypass only applies when Telegram marks the sender as a bot and the existing bot policy explicitly allows bots; human senders still go through the existing allowlist path.
Type: Bug fix Closes: #92840
AI code review — automated review for reference, author can ignore or act on any point.
Correct fix with the right shape: I verified against gateway/authz_mixin.py:495-511 that the canonical bot-policy branch admits senders whenever {PLATFORM}_ALLOW_BOTS ∈ {mentions, all} without further conditions, so the adapter's early return faithfully mirrors the contract (including placement before the human allowlist), and it's needed because the multiplex closure handler genuinely can't reach the mixin via __self__. The negative-control test (bot policy must not admit humans) is exactly the right companion.
Two suggestions:
Policy logic is now duplicated across two modules — the env name, accepted value set, and ordering live in both gateway/authz_mixin.py:501-511 and this adapter (plugins/platforms/telegram/adapter.py:~1431-1437). Drift between them would make authorization depend on which handler shape received the message. Extracting a tiny shared helper (e.g. bot_policy_admits(env_var, is_bot) -> bool next to the gate helpers, used by both call sites) keeps one source of truth while preserving the closure workaround.
Missing negative case for the policy itself — tests cover bot+mentions → True and human+all → False, but not bot with TELEGRAM_ALLOW_BOTS=none/unset → False. That's the regression most likely to be introduced by a future refactor of the early-return block; one more test closes it.
Minor:
Confirm _scoped_gate_env resolves to the same value the mixin's _platform_gate_env would see on non-multiplex runs, so both entry paths can't disagree when a profile-scoped override exists.
Consider threading is_bot through _source_from_reaction_for_auth as well if bot reactions ever reach an auth gate.
#101250 won because it was built on the earlier #65589 fix and covers the same behavior across all affected call paths in one change. You're credited via Co-authored-by on the merge and in the PR body of #101250.
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
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
Telegram early intake authorization built a
SessionSourcewithout preservingfrom_user.is_bot, then fell back to the human allowlist when the multiplex profile handler was a closure with no__self__. That meant bot-authored messages were rejected before the normal gateway bot policy could admit them, even whenTELEGRAM_ALLOW_BOTSwasmentionsorall. This PR carries the Telegram sender's bot bit into the auth source and mirrorsAuthzMixin's bot-policy branch at the early prefilter before applying the human allowlist.Changes
plugins/platforms/telegram/adapter.py: propagates
message.from_user.is_botinto_source_from_message_for_auth()and admits bot-authored messages early when scopedTELEGRAM_ALLOW_BOTSresolves tomentionsorall.tests/gateway/test_telegram_auth_check.py: extends the Telegram message fixture with
is_bot, adds a multiplex-closure regression for allowed bot-authored messages, and adds a negative human-sender case proving bot policy does not bypass the human allowlist.How to Test
python -m pytest tests/gateway/test_telegram_auth_check.py tests/gateway/test_telegram_bot_auth_bypass.py -q
✅ 17/17 passed
ruff check plugins/platforms/telegram/adapter.py tests/gateway/test_telegram_auth_check.py tests/gateway/test_telegram_bot_auth_bypass.py
✅ passed
git diff --check
✅ passed
python scripts/check-windows-footguns.py --diff upstream/main
✅ passed
scripts/run_tests.sh
Notes
An open PR (#91483) also mentions
TELEGRAM_ALLOW_BOTS, but it changesgateway/authz_mixin.pyto add bot-loop protection for #91481. This PR is separate and scoped to Telegram adapter early-auth intake for #92840.Checklist
Risk & Impact
Low. The new bypass only applies when Telegram marks the sender as a bot and the existing bot policy explicitly allows bots; human senders still go through the existing allowlist path.
Type: Bug fix
Closes: #92840