fix(gateway): honor group_allow_from for Telegram group/forum chats - #57189
fix(gateway): honor group_allow_from for Telegram group/forum chats#57189busminer wants to merge 1 commit into
Conversation
_is_user_authorized_from_message short-circuited on adapter-level allow_from for every chat type, so a DM-only allow_from silently gated group/forum chats too — group_allow_from was never consulted at this intake gate, even though it's a documented config key and the downstream gateway/authz_mixin.py runner-level check does union it correctly for the fallback path. Practical effect: an operator who set allow_from (DM restriction) plus group_allow_from: ['*'] (open groups) got only the DM restriction — real group senders were silently dropped before mention-detection ever ran, no error, no log visible to the sender. Fix: union group_allow_from into the allowed set for group/forum chat_type when it's configured, while keeping the existing allow_from-gates-everywhere behavior when group_allow_from is unset (matches existing test expectations / backward compat).
Competing with #55496 (diff-verified canonical, allow_from-before-group-allowlist ordering rewrite) for the same Telegram group-allowlist intake gap. Also related: #55624 (messy variant already deduped into #55496) and #55529 (DM-half). This PR unions |
|
Closing in favor of #55496 — thanks @alt-glitch for the pointer, and I independently checked: #55496 (and its follow-up #55529 for the DM-side symmetry) is genuinely more complete than this PR. It handles the same intake-gate ordering bug, plus the Should have searched existing PRs/issues before opening this one per CONTRIBUTING.md — apologies for the duplicate noise. Root-caused and reproduced the bug independently on a live deployment before finding #55496, for what it's worth, so at least the report itself is corroborating evidence that #55462 is real and worth prioritizing. 🤖 Addressed by Claude Code |
What
_is_user_authorized_from_messageinplugins/platforms/telegram/adapter.pyshort-circuited on adapter-levelallow_fromfor every chat type.group_allow_fromwas never consulted at this intake gate, even though it's a documented config key.Why
Practical effect discovered on a live deployment: an operator set
allow_from(DM restricted to themselves) plusgroup_allow_from: ['*'](groups open to everyone). Real group senders were silently dropped before mention-detection ever ran — no error, no log visible to the sender, just silence. Confirmed via a two-day-old CIS Telegram group where community members got zero replies while the operator's own DM continued working normally.The downstream
gateway/authz_mixin.pyrunner-level fallback check does uniongroup_allow_fromcorrectly — but it's unreachable once the adapter-level gate above it returns early.Fix
Union
group_allow_frominto the allowed set forgroup/forumchat_typewhen it's configured, while preserving the existingallow_from-gates-everywhere behavior whengroup_allow_fromis unset (this matches existing test expectations for backward compatibility — some deployments rely on a singleallow_fromrestricting groups too).How to test
All 80 tests pass locally (fresh venv, no other changes).
Platforms tested
Windows 10, Python 3.11, live Telegram gateway (not just unit tests) — the union behavior was verified end-to-end against a real group with a real non-operator sender getting through post-fix, and blocked pre-fix.