Skip to content

Commit 6df54bb

Browse files
committed
fix: enforce admin guard for sandbox file transfer tools
1 parent 80fd511 commit 6df54bb

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • astrbot/core/computer/tools

astrbot/core/computer/tools/fs.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212

1313
from ..computer_client import get_booter
1414

15+
16+
def _check_admin_permission(context: ContextWrapper[AstrAgentContext]) -> str | None:
17+
cfg = context.context.context.get_config(
18+
umo=context.context.event.unified_msg_origin
19+
)
20+
provider_settings = cfg.get("provider_settings", {})
21+
require_admin = provider_settings.get("computer_use_require_admin", True)
22+
if require_admin and context.context.event.role != "admin":
23+
return (
24+
"error: Permission denied. File upload/download is only allowed for admin users. "
25+
"Tell user to set admins in `AstrBot WebUI -> Config -> General Config` by adding their user ID to the admins list if they need this feature."
26+
f"User's ID is: {context.context.event.get_sender_id()}. User's ID can be found by using /sid command."
27+
)
28+
return None
29+
30+
1531
# @dataclass
1632
# class CreateFileTool(FunctionTool):
1733
# name: str = "astrbot_create_file"
@@ -102,6 +118,8 @@ async def call(
102118
context: ContextWrapper[AstrAgentContext],
103119
local_path: str,
104120
) -> str | None:
121+
if permission_error := _check_admin_permission(context):
122+
return permission_error
105123
sb = await get_booter(
106124
context.context.context,
107125
context.context.event.unified_msg_origin,
@@ -161,6 +179,8 @@ async def call(
161179
remote_path: str,
162180
also_send_to_user: bool = True,
163181
) -> ToolExecResult:
182+
if permission_error := _check_admin_permission(context):
183+
return permission_error
164184
sb = await get_booter(
165185
context.context.context,
166186
context.context.event.unified_msg_origin,

0 commit comments

Comments
 (0)