Skip to content

fix: resolve relative file paths within a local workspace root for the SendMessageToUserTool#7668

Merged
Soulter merged 5 commits intoAstrBotDevs:masterfrom
Blueteemo:fix/issue-7632-relative-path-workspace
Apr 19, 2026
Merged

fix: resolve relative file paths within a local workspace root for the SendMessageToUserTool#7668
Soulter merged 5 commits intoAstrBotDevs:masterfrom
Blueteemo:fix/issue-7632-relative-path-workspace

Conversation

@Blueteemo
Copy link
Copy Markdown
Contributor

@Blueteemo Blueteemo commented Apr 19, 2026

问题描述

send_message_to_user 发送文件时,传入相对路径(如 filename.md)会先尝试绝对路径失败,再试绝对路径才成功,浪费 token。

修复方案

_resolve_path_from_sandbox 方法中,当 path 是相对路径时,先尝试解析到 workspace 目录下检查文件是否存在。同时添加了 path 安全检查,防止 .. 等路径遍历问题。

Related Issue

Fixes #7632

Summary by Sourcery

Bug Fixes:

  • Ensure non-absolute paths in send_message_to_user are resolved relative to the active workspace when possible instead of relying solely on the raw filesystem path.

@auto-assign auto-assign bot requested review from Fridemn and LIghtJUNction April 19, 2026 04:38
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 19, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider normalizing path (e.g., via Path(path).resolve() or similar) before checking isabs and composing with workspace_root to avoid subtle issues with .. segments or mixed separators.
  • If workspace_root(unified_msg_origin) can fail or return an invalid path, it might be worth adding a guard or error handling to avoid raising when doing ws_path / path.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider normalizing `path` (e.g., via `Path(path).resolve()` or similar) before checking `isabs` and composing with `workspace_root` to avoid subtle issues with `..` segments or mixed separators.
- If `workspace_root(unified_msg_origin)` can fail or return an invalid path, it might be worth adding a guard or error handling to avoid raising when doing `ws_path / path`.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces logic to resolve relative file paths within a workspace root for the SendMessageToUserTool. A security concern was identified regarding potential path traversal attacks; the current implementation does not prevent access to files outside the workspace if the input path contains parent directory references. It is recommended to resolve the path and verify its location relative to the workspace root.

Comment thread astrbot/core/tools/message_tools.py Outdated
@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Apr 19, 2026
@Soulter
Copy link
Copy Markdown
Member

Soulter commented Apr 19, 2026

@gemini-code-assist /gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces logic to resolve relative file paths within a user's workspace root. A security vulnerability was identified where malicious relative paths could bypass workspace boundaries and access the host's filesystem via path traversal. The feedback suggests strictly resolving relative paths within the workspace and using file-specific checks to prevent unauthorized access.

Comment thread astrbot/core/tools/message_tools.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Soulter Soulter changed the title fix: send_message_to_user 相对路径解析到 workspace fix: resolve relative file paths within a workspace root for the SendMessageToUserTool Apr 19, 2026
@Soulter Soulter changed the title fix: resolve relative file paths within a workspace root for the SendMessageToUserTool fix: resolve relative file paths within a local workspace root for the SendMessageToUserTool Apr 19, 2026
@Soulter Soulter merged commit b40bcbb into AstrBotDevs:master Apr 19, 2026
21 checks passed
@Blueteemo Blueteemo deleted the fix/issue-7632-relative-path-workspace branch April 19, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]send_message_to_user对文件相对路径的支持

2 participants