Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

🔒 (slack.py, telegram.py): implement unauthorized access handling

cyhhaofc10d399aca4
diff --git a/modules/im/slack.py b/modules/im/slack.py
index eb9f13428..b6675688c 100644
--- a/modules/im/slack.py
+++ b/modules/im/slack.py
@@ -238,12 +238,11 @@ class SlackBot(BaseIMClient):
channel_id = event.get("channel")
- # Check if target_channel is configured and message is not in that channel
- if self.config.target_channel and channel_id != self.config.target_channel:
- # Check if this is a DM (starts with 'D')
- if not channel_id.startswith('D'):
- logger.info(f"Ignoring message from non-target channel: {channel_id}")
- return
+ # Check if channel is authorized based on whitelist configuration
+ if not await self._is_authorized_channel(channel_id):
+ logger.info(f"Unauthorized message from channel: {channel_id}")
+ await self._send_unauthorized_message(channel_id)
+ return
# Check if this message contains a bot mention
# If it does, skip processing as it will be handled by app_mention event
@@ -255,7 +254,8 @@ class SlackBot(BaseIMClient):
# Check if channel is authorized based on whitelist
if not await self._is_authorized_channel(channel_id):
- logger.info(f"Ignoring message from unauthorized channel: {channel_id}")
+ logger.info(f"Unauthorized message from channel: {channel_id}")
+ await self._send_unauthorized_message(channel_id)
return
# Check if we require mention in channels (not DMs)
@@ -296,7 +296,8 @@ class SlackBot(BaseIMClient):
# Check if channel is authorized based on whitelist
if not await self._is_authorized_channel(channel_id):
- logger.info(f"Ignoring mention from unauthorized channel: {channel_id}")
+ logger.info(f"Unauthorized mention from channel: {channel_id}")
+ await self._send_unauthorized_message(channel_id)
return
context = MessageContext(
@@ -345,7 +346,7 @@ class SlackBot(BaseIMClient):
# Check if channel is authorized based on whitelist
if not await self._is_authorized_channel(channel_id):
- logger.info(f"Ignoring slash command from unauthorized channel: {channel_id}")
+ logger.info(f"Unauthorized slash command from channel: {channel_id}")
# Send a response to user about unauthorized channel
response_url = payload.get("response_url")
if response_url:
@@ -410,6 +411,14 @@ class SlackBot(BaseIMClient):
# Handle button clicks
user = payload.get("user", {})
actions = payload.get("actions", [])
+ channel_id = payload.get("channel", {}).get("id")
+
+ # Check if channel is authorized for interactive components
+ if not await self._is_authorized_channel(channel_id):
+ logger.info(f"Unauthorized interactive action from channel: {channel_id}")
+ # For interactive components, we can't easily send a message back
+ # The user will just see the button doesn't respond
+ return
for action in actions:
if action.get("type") == "button":
@@ -419,7 +428,7 @@ class SlackBot(BaseIMClient):
# Create a context for the callback
context = MessageContext(
user_id=user.get("id"),
- channel_id=payload.get("channel", {}).get("id"),
+ channel_id=channel_id,
message_id=payload.get("message", {}).get("ts"),
platform_specific={
"trigger_id": payload.get("trigger_id"),
@@ -732,4 +741,15 @@ class SlackBot(BaseIMClient):
# Should not reach here, but handle gracefully
logger.warning(f"Unexpected target_channel type: {type(target_channel)}")
- return True
\ No newline at end of file
+ return True
+
+ async def _send_unauthorized_message(self, channel_id: str):
+ """Send unauthorized access message to channel"""
+ try:
+ self._ensure_clients()
+ await self.web_client.chat_postMessage(
+ channel=channel_id,
+ text="❌ This channel is not authorized to use bot commands."
+ )
+ except Exception as e:
+ logger.error(f"Failed to send unauthorized message to {channel_id}: {e}")
\ No newline at end of file
diff --git a/modules/im/telegram.py b/modules/im/telegram.py
index 08fb30dde..d4b1daa74 100644
--- a/modules/im/telegram.py
+++ b/modules/im/telegram.py
@@ -27,7 +27,8 @@ class TelegramBot(BaseIMClient):
# Check if message is authorized based on whitelist
if not self._is_authorized_chat(chat_id, chat_type):
- # Silently ignore unauthorized messages
+ logger.info(f"Unauthorized message from chat: {chat_id}")
+ await self._send_unauthorized_message(chat_id)
return
# Create MessageContext
@@ -54,6 +55,15 @@ class TelegramBot(BaseIMClient):
async def handle_telegram_callback(self, update: Update, tg_context: ContextTypes.DEFAULT_TYPE):
"""Handle callback queries from inline keyboards"""
query = update.callback_query
+ chat_id = query.message.chat_id
+ chat_type = query.message.chat.type
+
+ # Check if callback is authorized based on whitelist
+ if not self._is_authorized_chat(chat_id, chat_type):
+ logger.info(f"Unauthorized callback from chat: {chat_id}")
+ # For callback queries, we can answer with an alert
+ await query.answer("❌ This chat is not authorized to use bot commands.", show_alert=True)
+ return
# Store the query for later use in answer_callback
self._callback_queries[query.id] = query
@@ -61,7 +71,7 @@ class TelegramBot(BaseIMClient):
# Create MessageContext
context = MessageContext(
user_id=str(query.from_user.id),
- channel_id=str(query.message.chat_id),
+ channel_id=str(chat_id),
message_id=str(query.message.message_id),
platform_specific={'query': query, 'update': update, 'tg_context': tg_context, 'callback_id': query.id}
)
@@ -79,7 +89,8 @@ class TelegramBot(BaseIMClient):
# Check if command is authorized based on whitelist
if not self._is_authorized_chat(chat_id, chat_type):
- # Silently ignore unauthorized commands
+ logger.info(f"Unauthorized command from chat: {chat_id}")
+ await self._send_unauthorized_message(chat_id)
return
# Extract args
@@ -435,4 +446,15 @@ class TelegramBot(BaseIMClient):
# Should not reach here, but handle gracefully
logger.warning(f"Unexpected target_chat_id type: {type(target_chat_id)}")
- return True
\ No newline at end of file
+ return True
+
+ async def _send_unauthorized_message(self, chat_id: int):
+ """Send unauthorized access message to chat"""
+ try:
+ bot = self.application.bot
+ await bot.send_message(
+ chat_id=chat_id,
+ text="❌ This chat is not authorized to use bot commands."
+ )
+ except Exception as e:
+ logger.error(f"Failed to send unauthorized message to {chat_id}: {e}")
\ No newline at end of file