fix(gateway): enforce auth check in busy-session path to prevent unauthorized injection (#17775)
The busy-session handler (_handle_active_session_busy_message) bypassed the authorization gate that the cold path enforces via _is_user_authorized(). In shared-thread contexts (Slack threads, Telegram forum topics, Discord threads) where thread_sessions_per_user=False (the default), all participants share one session_key. An unauthorized user posting in the same thread as an authorized user would hit the active-session branch, skip the auth check, and have their text merged into _pending_messages or injected via agent.interrupt(). This commit adds the same _is_user_authorized() check at the top of the busy handler, before any message queuing, steering, or interrupt logic. Unauthorized messages are silently dropped (return True) with a warning log — matching the cold-path behavior. Affected platforms: Slack, Telegram, Discord, any adapter with shared-session thread contexts. Closes #17775
This commit is contained in:
@@ -1874,6 +1874,22 @@ class GatewayRunner:
|
||||
merge_pending_message_event(adapter._pending_messages, session_key, event)
|
||||
|
||||
async def _handle_active_session_busy_message(self, event: MessageEvent, session_key: str) -> bool:
|
||||
# --- Authorization gate (#17775) ---
|
||||
# The cold path (_handle_message) checks _is_user_authorized before
|
||||
# creating a session. The busy path must enforce the same check;
|
||||
# otherwise unauthorized users in shared threads (Slack/Telegram/Discord)
|
||||
# can inject messages into an active session they don't own.
|
||||
if not self._is_user_authorized(event.source):
|
||||
logger.warning(
|
||||
"Dropping message from unauthorized user in active session: "
|
||||
"user=%s (%s), platform=%s, session=%s",
|
||||
event.source.user_id,
|
||||
event.source.user_name,
|
||||
event.source.platform.value if event.source.platform else "unknown",
|
||||
session_key,
|
||||
)
|
||||
return True # handled (silently dropped); do not fall through
|
||||
|
||||
# --- Draining case (gateway restarting/stopping) ---
|
||||
if self._draining:
|
||||
adapter = self.adapters.get(event.source.platform)
|
||||
|
||||
Reference in New Issue
Block a user