fix(core): restrict send_message_to_user to current session (security fix #7822)#7824
Merged
Soulter merged 3 commits intoAstrBotDevs:masterfrom Apr 28, 2026
Merged
Conversation
…ssion only Closes AstrBotDevs#7822 SECURITY: Remove the user-controlled 'session' parameter from the send_message_to_user tool. Previously, a regular user could ask the LLM to send messages to any arbitrary session (group chat) by providing a crafted session string, which is a high-risk vulnerability. Changes: - Remove 'session' parameter from tool schema (LLM can no longer propose it) - Always use context.context.event.unified_msg_origin as the target session - Update description to clearly state that messages can only be sent to the current user's session
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider adding a guard for
context.context.event.unified_msg_originbeingNoneor missing so the tool fails explicitly instead of passing an invalid session downstream in non-interactive contexts (e.g., cron-like triggers). - The description still suggests use in cron-job-like scenarios; if such jobs don’t naturally have a
unified_msg_origin, it may be worth clarifying how/if this tool can be used there now that the session is hardcoded to the triggering user.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding a guard for `context.context.event.unified_msg_origin` being `None` or missing so the tool fails explicitly instead of passing an invalid session downstream in non-interactive contexts (e.g., cron-like triggers).
- The description still suggests use in cron-job-like scenarios; if such jobs don’t naturally have a `unified_msg_origin`, it may be worth clarifying how/if this tool can be used there now that the session is hardcoded to the triggering user.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Code Review
This pull request addresses a security vulnerability in the SendMessageToUserTool by removing the optional session parameter, ensuring messages are only sent to the current user's session. The tool's description and logic were updated to enforce this restriction. Feedback suggests adding a validation check to handle cases where the session origin might be unavailable, providing a clearer error message.
- Re-add the parameter removed in the original PR - Non-admin users can only send to their own session (current_session) - Admin users can send to any session via the param - Uses from computer_tools.util (same pattern as fs.py) - Ref: AstrBotDevs#7822 Co-authored-by: Soulter <soulter@astrbot.app>
LIghtJUNction
pushed a commit
that referenced
this pull request
Apr 28, 2026
…ix #7822) (#7824) * fix(core): security fix - restrict send_message_to_user to current session only Closes #7822 SECURITY: Remove the user-controlled 'session' parameter from the send_message_to_user tool. Previously, a regular user could ask the LLM to send messages to any arbitrary session (group chat) by providing a crafted session string, which is a high-risk vulnerability. Changes: - Remove 'session' parameter from tool schema (LLM can no longer propose it) - Always use context.context.event.unified_msg_origin as the target session - Update description to clearly state that messages can only be sent to the current user's session * fix: restore session param but restrict to admin only - Re-add the parameter removed in the original PR - Non-admin users can only send to their own session (current_session) - Admin users can send to any session via the param - Uses from computer_tools.util (same pattern as fs.py) - Ref: #7822 Co-authored-by: Soulter <soulter@astrbot.app> * Update message_tools.py --------- Co-authored-by: AstrBot <bot@astrbot.app>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a high-security vulnerability (Issue #7822) in the
send_message_to_usertool.The Problem
The tool previously accepted a user-controlled
sessionparameter, allowing any regular user to ask the LLM to send arbitrary messages to any group chat by crafting a target session string (e.g.,KevinBot:GroupMessage:704943246). This is a severe security risk — attackers could send untrusted links/messages to any session.The Fix
sessionparameter from the tool's parameter schema — the LLM can no longer propose it.context.context.event.unified_msg_origin— always uses the current user's own session.Changes
astrbot/core/tools/message_tools.py: +9/-7 linesSecurity Audit
Also verified that no other built-in tools (e.g.,
cron_tools.py) have similar session injection vulnerabilities.Closes #7822
Summary by Sourcery
Restrict the send_message_to_user tool to only send messages to the current user session to address a security vulnerability.
Bug Fixes:
Documentation: