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.

fix(auth): close 3 gaps found in architecture review

cyh0717c83ec37b
diff --git a/modules/im/discord.py b/modules/im/discord.py
index edb3ea853..baa97e4a1 100644
--- a/modules/im/discord.py
+++ b/modules/im/discord.py
@@ -502,9 +502,12 @@ class DiscordBot(BaseIMClient):
if effective_require_mention and not is_dm:
if isinstance(channel, discord.Thread):
if self.settings_manager:
- if self.sessions and not self.sessions.is_thread_active(
- str(message.author.id), channel_id, str(channel.id)
- ):
+ thread_active = (
+ self.sessions.is_thread_active(str(message.author.id), channel_id, str(channel.id))
+ if self.sessions
+ else False
+ )
+ if not thread_active:
return
else:
return
@@ -1309,6 +1312,21 @@ class DiscordBot(BaseIMClient):
try:
await interaction.response.defer()
+ # Re-check auth before saving (defense-in-depth)
+ save_uid = str(interaction.user.id)
+ save_cid = channel_id or str(interaction.channel_id or "")
+ save_is_dm = interaction.guild is None
+ auth = self.outer.check_authorization(
+ user_id=save_uid,
+ channel_id=save_cid,
+ is_dm=save_is_dm,
+ action="cmd_routing",
+ settings_manager=self.outer.settings_manager,
+ )
+ if not auth.allowed:
+ await self.outer._send_auth_denial(save_cid, save_uid, auth, interaction=interaction)
+ return
+
if hasattr(self.outer, "_on_routing_update"):
await self.outer._on_routing_update(
str(interaction.user.id),
diff --git a/modules/im/feishu.py b/modules/im/feishu.py
index 64f460006..6c6ac4f28 100644
--- a/modules/im/feishu.py
+++ b/modules/im/feishu.py
@@ -1119,7 +1119,10 @@ class FeishuBot(BaseIMClient):
return
else:
if self.settings_manager:
- if self.sessions and not self.sessions.is_thread_active(user_id, chat_id, root_id):
+ thread_active = (
+ self.sessions.is_thread_active(user_id, chat_id, root_id) if self.sessions else False
+ )
+ if not thread_active:
logger.debug("Ignoring message in inactive thread %s", root_id)
return
else:
diff --git a/modules/im/slack.py b/modules/im/slack.py
index 4244eafdf..a8004aaf9 100644
--- a/modules/im/slack.py
+++ b/modules/im/slack.py
@@ -892,7 +892,10 @@ class SlackBot(BaseIMClient):
thread_ts = event.get("thread_ts")
# If we have settings_manager, check if thread is active
if self.settings_manager:
- if self.sessions and not self.sessions.is_thread_active(user_id, channel_id, thread_ts):
+ thread_active = (
+ self.sessions.is_thread_active(user_id, channel_id, thread_ts) if self.sessions else False
+ )
+ if not thread_active:
logger.debug(f"Ignoring message in inactive thread {thread_ts}: '{text}'")
return
else:
@@ -959,14 +962,24 @@ class SlackBot(BaseIMClient):
elif event_type == "app_mention":
# Handle @mentions
channel_id = event.get("channel")
+ user_id_mention = event.get("user")
+
+ # Remove the mention from the text first so we can parse commands for auth
+ text = event.get("text", "")
+ import re
+
+ text = re.sub(r"<@[\w]+>", "", text).strip()
+
+ # Parse command action for proper admin-protected auth check
+ parsed_command = self.parse_text_command(text)
+ auth_action = parsed_command[0] if parsed_command else ""
# Centralized auth gate (app_mention is always in a channel, not DM)
- user_id_mention = event.get("user")
auth = self.check_authorization(
user_id=user_id_mention or "",
channel_id=channel_id,
is_dm=False,
- action="",
+ action=auth_action,
settings_manager=self.settings_manager,
)
if not auth.allowed:
@@ -999,19 +1012,12 @@ class SlackBot(BaseIMClient):
self.sessions.mark_thread_active(event.get("user"), channel_id, thread_id)
logger.info(f"Marked thread {thread_id} as active due to @mention")
- # Remove the mention from the text
- text = event.get("text", "")
- import re
-
- text = re.sub(r"<@[\w]+>", "", text).strip()
-
# Extract shared/forwarded message content (defer appending until after command check)
shared_text = await self._extract_shared_message_content(event)
logger.info(f"App mention processed: original='{event.get('text')}', cleaned='{text}'")
- # Check if this is a command after mention (before appending shared content)
- parsed_command = self.parse_text_command(text)
+ # Check if this is a command after mention (command already parsed above for auth)
if parsed_command:
command, args = parsed_command
logger.info(f"Command detected: '{command}', available: {list(self.on_command_callbacks.keys())}")