fix(telegram): honor DM env allowlist when yaml allow_from is set - #55529
Open
xiawiie wants to merge 3 commits into
Open
fix(telegram): honor DM env allowlist when yaml allow_from is set#55529xiawiie wants to merge 3 commits into
xiawiie wants to merge 3 commits into
Conversation
Follow-up to NousResearch#55496. The original PR removed the adapter-level allow_from short-circuit for group/forum senders but kept it for DMs, so a user listed in TELEGRAM_ALLOWED_USERS is still rejected when DMing the bot whenever yaml allow_from is set to a different user — the second half of the scenario in issue NousResearch#55462. Drop the DM short-circuit so the existing _telegram_sender_auth_env_configured fallback applies symmetrically: yaml allow_from wins when it matches; otherwise sender-scoped env vars get a chance. When neither matches and no sender env is configured, DMs still deny. Refs NousResearch#55462.
tonydwb
reviewed
Jun 30, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment — Complex auth logic with many code paths
This PR adds Telegram DM env allowlist support when yaml allow_from is set, plus allowed_users/group_allowed_users aliases. The auth logic now has multiple overlapping code paths for DM vs group vs forum authorization.
Observations
- The core fix is correct: when
allow_fromis set in yaml, group senders should still be checkable against group-specific allowlists _coerce_telegram_allowlistproperly handles string, list, tuple, and set inputs_telegram_sender_auth_env_configuredcorrectly distinguishes chat-level vs sender-level env config- Tests cover the key scenarios: group env allowlist not masked by DM allow_from, group_allowed_users alias, allowed_users alias
Concern
- The auth flow now has 4+ branches with overlapping conditions. Consider adding a comment or diagram showing the authorization decision tree for future maintainers.
Reviewed by Hermes Agent
xiawiie
force-pushed
the
fix/telegram-dm-allowlist-55462
branch
from
June 30, 2026 10:20
7f0b634 to
6fc5388
Compare
This was referenced Jun 30, 2026
Contributor
|
Thanks for the focused Telegram authorization fix. Current main still has the reported intake-gate ordering problem: Problems
Suggested changes
This is an automated hermes-sweeper review. |
This was referenced Aug 3, 2026
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
Follow-up to #55496. The original PR fixed the same-shape bug for group/forum senders but kept the early
return Falsefor DMs, so a user listed only inTELEGRAM_ALLOWED_USERSis still blocked when DMing the bot whenever yamlallow_fromis set to a different user — which is the second half of the scenario reporter described in #55462:This change removes the DM short-circuit so the existing
_telegram_sender_auth_env_configured()fallback handles DMs the same way it already handles groups: yamlallow_fromwins when it matches; otherwise sender-scoped env vars (TELEGRAM_ALLOWED_USERS,TELEGRAM_ALLOW_ALL_USERS,GATEWAY_ALLOWED_USERS,GATEWAY_ALLOW_ALL_USERS) get a chance. When no env sender allowlist is configured, DMs still deny — same as before.Behavior change to note
The symmetry with the existing group path means that if a user has yaml
allow_from=[A]and onlyTELEGRAM_GROUP_ALLOWED_USERS=Bset (no DM-scoped env allowlist, noTELEGRAM_ALLOWED_USERS), a DM from any user not matchingallow_fromnow falls through to the runner / final env fallback instead of being denied at the adapter. This matches how group messages are already handled in that exact config — it isn't a new code path, just the same fallback applied symmetrically. The "no env at all" case is unchanged (still denies, covered bytest_config_allow_from_still_blocks_dm_sender_without_env).Test plan
pytest tests/gateway/test_telegram_auth_check.py tests/gateway/test_telegram_group_gating.py→ 73 passedtest_config_allow_from_still_blocks_group_sender_without_group_allowlistDepends on #55496. Refs #55462.