fix(slack): reject unauthorized users before event construction

Add early auth check in _handle_slack_message() that runs BEFORE any
API calls (thread context fetch, user name resolution, file downloads)
or file processing. Unauthorized users could previously trigger Slack
API calls and file downloads before the runner's _is_user_authorized
gate rejected them.

Same pattern as Telegram fix #54164: build a SessionSource and check
the runner's _is_user_authorized at the adapter level before event
construction consumes resources.

Fixes the gap where Slack has no adapter-level auth gate while Discord
and Telegram have adapter-level allowlists.
This commit is contained in:
dsad 2026-06-30 02:34:46 +03:00 committed by Teknium
parent f54e8706f7
commit 5bb933eedf

View file

@ -4370,6 +4370,25 @@ class SlackAdapter(BasePlatformAdapter):
# both as DM-style persistent conversations.
is_one_to_one_dm = channel_type == "im"
# Early auth check: reject unauthorized users before any API calls
# (thread context fetch, user name resolution, file downloads).
# Pattern matches Telegram fix #54164 — gate at the adapter level
# BEFORE event construction consumes resources.
if user_id:
_source = self.build_source(
chat_id=channel_id, chat_name="",
chat_type="dm" if is_dm else "group",
user_id=user_id, user_name="",
)
_runner = getattr(getattr(self, "_message_handler", None), "__self__", None)
_auth_fn = getattr(_runner, "_is_user_authorized", None)
if callable(_auth_fn) and not _auth_fn(_source):
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
# new thread/session (the bot always replies in a thread).