fix: constrain custom workspace paths#9136
Conversation
There was a problem hiding this comment.
Code Review
This pull request restricts custom workspace paths to stay within a subdirectory of the AstrBot workspaces root, rejecting absolute paths that point outside of it. The tests have been updated to reflect this security constraint. The reviewer suggests simplifying the path resolution logic in workspace_path_to_root by leveraging pathlib.Path's behavior where the / operator automatically ignores the left-hand side if the right-hand side is absolute, which removes the need for the ternary operator.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| resolved = ( | ||
| candidate.resolve(strict=False) | ||
| if candidate.is_absolute() | ||
| else (workspaces_root / candidate).resolve(strict=False) | ||
| ) |
There was a problem hiding this comment.
The ternary operator checking candidate.is_absolute() is redundant. In Python's pathlib, the / operator automatically ignores the left-hand side (workspaces_root) if the right-hand side (candidate) is an absolute path. Simplifying this to a single expression makes the code cleaner and more idiomatic.
resolved = (workspaces_root / candidate).resolve(strict=False)
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
astrbot-docs | fef3fb4 | Commit Preview URL Branch Preview URL |
Jul 04 2026, 09:09 AM |
|
this is by design. Users can select custom paths in chatui project to attach project sessions workspace. |
Motivation
customworkspace paths could be absolute and point outside AstrBot's workspaces, allowing chat-scoped users to expand non-admin file-tool allowlists.Description
workspace_path_to_root()inastrbot/core/workspace.pyto always resolve the candidate path (absolute or relative) and then require the resolved path to be a subdirectory of the AstrBot workspaces root.tests/unit/test_chatui_project_service.pyto accept absolute paths that are workspace subdirectories and to reject absolute paths that resolve outside the workspaces root.Testing
uv run --no-sync ruff format .which completed successfully.uv run --no-sync ruff check .which completed successfully.uv run --no-sync pytest tests/unit/test_chatui_project_service.pybut test execution was blocked by a missing test dependency (pytest_asyncio) and an external PyPI fetch/connectivity failure, so full pytest validation could not be completed.Codex Task
Summary by Sourcery
Constrain custom ChatUI workspaces so that both relative and absolute paths must resolve within the AstrBot workspaces root.
Bug Fixes:
Enhancements:
Tests: