mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-26 17:38:36 +00:00
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:
parent
0d6717e5aa
commit
856b604b4a
1 changed files with 19 additions and 0 deletions
|
|
@ -3942,6 +3942,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).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue