The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): Discord's config allow_from also governs guild channels
calvinnwq9c1a75e56f59
diff --git a/gateway/authz_mixin.py b/gateway/authz_mixin.pyindex d54e5202d88..5dea0e6401f 100644--- a/gateway/authz_mixin.py+++ b/gateway/authz_mixin.py@@ -498,7 +498,11 @@ class GatewayAuthorizationMixin:if adapter is None:return Falseextra = _adapter_config_extra(adapter)- adapter_allow = extra.get("group_allow_from" if is_group else "allow_from")+ # ``group_allow_from`` is a separate group list (Telegram); an adapter with a single user+ # allowlist (Discord) declares ``allow_from_covers_groups`` so its groups read ``allow_from``.+ groups_use_allow_from = getattr(adapter, "allow_from_covers_groups", False) is True+ group_key = "allow_from" if groups_use_allow_from else "group_allow_from"+ adapter_allow = extra.get(group_key if is_group else "allow_from")if not adapter_allow:# Plugin platforms (Buzz, DingTalk) spell their env allowlist as ``extra.allowed_users``;# under multiplex only the default profile's list reaches the env (first-writer-winsdiff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.pyindex a31f99c97d3..f903ead4a5a 100644--- a/plugins/platforms/discord/adapter.py+++ b/plugins/platforms/discord/adapter.py@@ -1225,6 +1225,7 @@ class DiscordAdapter(DiscordAuthorizationMixin, DiscordMediaMixin, DiscordThreadMAX_MESSAGE_LENGTH = 2000_SPLIT_THRESHOLD = 1900 # near the 2000-char split pointsupports_code_blocks = True # Discord markdown renders fenced code blocks natively+ allow_from_covers_groups = True # no group_allow_from: allow_from is the one user allowlistsplits_long_messages = True # send() chunks via truncate_message(MAX_MESSAGE_LENGTH)# Safety ceiling on split deliveries: chunks beyond the cap become a notice (degenerate turns).# Safety ceiling on split deliveries (#86581): a degenerate turn can produce tens of thousands ofdiff --git a/tests/gateway/test_discord_config_allowlist_multiplex.py b/tests/gateway/test_discord_config_allowlist_multiplex.pyindex 930c7eb319a..e96bbe47d8b 100644--- a/tests/gateway/test_discord_config_allowlist_multiplex.py+++ b/tests/gateway/test_discord_config_allowlist_multiplex.py@@ -88,6 +88,51 @@ def test_button_click_in_a_thread_follows_the_thread_message_verdict(config_onlyassert _component_check_auth(stranger, snapshot, set(), live_auth=adapter._component_live_auth) is False[email protected]("user_id,expected", [(USER, True), (STRANGER, False)])+def test_guild_channel_message_and_button_honor_config_allow_from(config_only_discord, user_id, expected):+ """Regression: ``allow_from`` is Discord's only user allowlist, so it governs guild channels+ too. The gateway's fallback read ``group_allow_from`` (Telegram's group-only key) for ``group``+ sources and silently dropped the allowlisted user's channel messages and button clicks."""+ from plugins.platforms.discord.adapter_component_auth import _component_check_auth++ runner, adapter = _wire(config_only_discord)+ source = adapter.build_source(+ chat_id=CHANNEL, chat_type="group", user_id=user_id, user_name="u", guild_id="1")+ runner._canonicalize(source, primary_home=config_only_discord)+ assert runner._is_user_authorized_for_source(source) is expected++ click = _click(user_id, SimpleNamespace(id=int(CHANNEL)))+ snapshot = adapter._get_allowed_users()+ assert _component_check_auth(click, snapshot, set(), live_auth=adapter._component_live_auth) is expected+++def test_telegram_group_still_requires_group_allow_from(monkeypatch):+ """Guard: Telegram's ``allow_from`` is DM-only and must not admit the user in a group."""+ from gateway.config import GatewayConfig, PlatformConfig+ from gateway.pairing import PairingStore+ from gateway.run import GatewayRunner+ from gateway.session import SessionSource+ from plugins.platforms.telegram.adapter import TelegramAdapter++ for key in ("TELEGRAM_ALLOWED_USERS", "TELEGRAM_GROUP_ALLOWED_USERS", "GATEWAY_ALLOWED_USERS",+ "GATEWAY_ALLOW_ALL_USERS", "TELEGRAM_ALLOW_ALL_USERS"):+ monkeypatch.delenv(key, raising=False)+ runner = object.__new__(GatewayRunner)+ runner.config = GatewayConfig()+ adapter = object.__new__(TelegramAdapter)+ adapter.config = PlatformConfig(enabled=True, extra={"allow_from": "777"})+ runner.config.platforms = {Platform.TELEGRAM: adapter.config}+ runner.adapters = {Platform.TELEGRAM: adapter}+ runner.pairing_store = PairingStore(profile="default")++ def source(chat_type):+ return SessionSource(platform=Platform.TELEGRAM, chat_id="-100555", chat_type=chat_type,+ user_id="777")++ assert runner._is_user_authorized(source("dm")) is True+ assert runner._is_user_authorized(source("group")) is False++def test_button_click_in_a_thread_resolves_a_thread_scoped_route(monkeypatch):"""A click carries the thread id, so a ``thread_id`` profile route matches it the same way itmatches the thread's messages: a user paired only in the routed profile can answer the card."""