The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(slack): interactive-caller and pre-fetch auth prefer the injected profile check; gate reads never fall through to os.environ
Teknium11f932c93554
diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.pyindex cef1f9be757..b4cd21c143f 100644--- a/plugins/platforms/slack/adapter.py+++ b/plugins/platforms/slack/adapter.py@@ -6353,9 +6353,19 @@ class SlackAdapter(BasePlatformAdapter):# or file downloads. The final gateway runner auth check happens# after MessageEvent construction, so adapter-side media fetches need# the same auth chain up front.+ # Prefer the injected profile-bound check (survives the multiplex+ # closure handler, which has no ``__self__``); fall back to runner+ # introspection for adapters wired without one.+ _early_decision = (+ self._is_sender_authorized(+ user_id, "dm" if is_dm else "group", channel_id+ )+ if user_id and getattr(self, "_authorization_check", None) is not None+ else None+ )_runner = getattr(getattr(self, "_message_handler", None), "__self__", None)_auth_fn = getattr(_runner, "_is_user_authorized", None)- if user_id and callable(_auth_fn):+ if _early_decision is None and user_id and callable(_auth_fn):_source = self.build_source(chat_id=channel_id,chat_name="",@@ -6363,13 +6373,14 @@ class SlackAdapter(BasePlatformAdapter):user_id=user_id,user_name="",)- if not _auth_fn(_source):- logger.warning(- "[Slack] Early reject of unauthorized user %s in channel %s",- user_id,- channel_id,- )- return+ _early_decision = bool(_auth_fn(_source))+ if _early_decision is False:+ logger.warning(+ "[Slack] Early reject of unauthorized user %s in channel %s",+ user_id,+ channel_id,+ )+ return# Build thread_ts for session keying.# In channels: fall back to ts so each top-level @mention starts a@@ -7490,6 +7501,23 @@ class SlackAdapter(BasePlatformAdapter):if not normalized_user_id:return False+ chat_type = "dm" if str(channel_id or "").startswith("D") else "group"++ # Preferred path: the auth callback GatewayRunner injects at connect+ # time (``set_authorization_check``) runs the full, profile-bound+ # ``_is_user_authorized`` chain. Unlike the ``__self__`` introspection+ # below it also resolves on a multiplexed adapter, whose message+ # handler is a profile closure with no ``__self__`` (#72657, same+ # class as Telegram's #86296).+ # ``getattr``: adapters built via ``object.__new__`` never ran+ # ``BasePlatformAdapter.__init__``.+ if getattr(self, "_authorization_check", None) is not None:+ injected = self._is_sender_authorized(+ normalized_user_id, chat_type, str(channel_id or "")+ )+ if injected is not None:+ return injected+runner = getattr(getattr(self, "_message_handler", None), "__self__", None)auth_fn = getattr(runner, "_is_user_authorized", None)if callable(auth_fn):@@ -7499,7 +7527,7 @@ class SlackAdapter(BasePlatformAdapter):source = SessionSource(platform=Platform.SLACK,chat_id=str(channel_id or normalized_user_id),- chat_type="dm" if str(channel_id or "").startswith("D") else "group",+ chat_type=chat_type,user_id=normalized_user_id,user_name=str(user_name).strip() if user_name else None,scope_id=str(team_id) if team_id else None,@@ -7512,20 +7540,14 @@ class SlackAdapter(BasePlatformAdapter):exc_info=True,)- if os.getenv("SLACK_ALLOW_ALL_USERS", "").lower() in {"true", "1", "yes"}:- return True-- def _env(name: str) -> str:- # Multiplex: profile .env is in secret_scope, not process environ.- try:- from agent.secret_scope import get_secret+ # Env-only fallback (no injected check, no bound runner). Gate reads go+ # through the shared per-profile accessor: under multiplex a scoped+ # miss returns "" instead of falling through to ``os.environ``, which+ # holds the DEFAULT profile's allow-all flag / allowlist.+ from gateway.authz_mixin import _platform_gate_env as _env- val = get_secret(name)- if val is not None and str(val).strip():- return str(val).strip()- except Exception:- pass- return (os.getenv(name) or "").strip()+ if _env("SLACK_ALLOW_ALL_USERS").lower() in {"true", "1", "yes"}:+ return Trueallowed_ids = set()platform_allowlist = _env("SLACK_ALLOWED_USERS")@@ -7538,8 +7560,6 @@ class SlackAdapter(BasePlatformAdapter):if allowed_ids:return "*" in allowed_ids or normalized_user_id in allowed_ids- if _env("SLACK_ALLOW_ALL_USERS").lower() in {"true", "1", "yes"}:- return Truereturn _env("GATEWAY_ALLOW_ALL_USERS").lower() in {"true", "1", "yes"}async def _handle_slash_confirm_action(self, ack, body, action) -> None:diff --git a/tests/gateway/test_multiplex_interactive_auth.py b/tests/gateway/test_multiplex_interactive_auth.pyindex 26a03b59558..5ed97aa17c8 100644--- a/tests/gateway/test_multiplex_interactive_auth.py+++ b/tests/gateway/test_multiplex_interactive_auth.py@@ -110,6 +110,39 @@ def test_bot_sender_reaches_allow_bots_policy_through_callback(mux_home):assert tg._is_user_authorized_from_message(msg(4343, False)) is False+def test_slack_interactive_auth_prefers_wired_profile_check(mux_home, monkeypatch):+ """#72657: a multiplexed Slack adapter's button gate resolves through the+ wired ``_make_adapter_auth_check`` for its own profile; the DEFAULT+ profile's process-env allow-all never leaks in — not through the+ injected path, and not through the env-only fallback either."""+ from gateway.run import _profile_runtime_scope+ from plugins.platforms.slack.adapter import SlackAdapter++ runner = _runner(mux_home)+ runner.adapters = {}+ sec_home = mux_home / "profiles" / "secondary"+ (sec_home / ".env").write_text("SLACK_ALLOWED_USERS=U_SEC\n")+ monkeypatch.setenv("SLACK_ALLOW_ALL_USERS", "true")++ def slack(with_check):+ sl = object.__new__(SlackAdapter)+ sl.config = PlatformConfig(enabled=True, extra={})+ sl._authorization_check = None+ sl._message_handler = runner._make_profile_message_handler("secondary")+ if with_check:+ runner._profile_adapters = {"secondary": {Platform.SLACK: sl}}+ sl.set_authorization_check(+ runner._make_adapter_auth_check(Platform.SLACK, profile_name="secondary")+ )+ return sl++ with _profile_runtime_scope(sec_home):+ wired = slack(True)+ assert wired._is_interactive_user_authorized("U_SEC", channel_id="C1") is True+ assert wired._is_interactive_user_authorized("U_X", channel_id="C1") is False+ assert slack(False)._is_interactive_user_authorized("U_X", channel_id="C1") is False++def test_authorization_adapter_ignores_per_turn_active_profile(mux_home):"""#87240 egress half: inside a secondary profile's runtime scope thedefault bot must not be handed to that profile (fail-closed None); the