AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug] shell blocklist rejects rm -rf under /tmp because it is a raw substring match

Open Rebines opened this issue 3 weeks ago • 2 comments

Summary

astrbot_execute_shell rejects any command containing rm -rf, even when the only target is a temporary directory under /tmp. The current check is a raw substring match, so a benign cleanup command is treated the same as rm -rf /.

Environment

  • AstrBot 4.29.4 (also present on current master)
  • Debian 12 / aarch64 (Raspberry Pi)
  • provider_settings.computer_use_runtime = local
  • astrbot_execute_shell works for ordinary commands; only this pattern is blocked

Reproduction

Call the local shell tool with a command that only deletes a temp directory:

rm -rf /tmp/my_build && mkdir -p /tmp/my_build && cp -r ./src /tmp/my_build/ && cd /tmp/my_build && make

Actual result:

Error executing command: Blocked unsafe shell command.

Expected: the command should be allowed because every rm target is a literal path under /tmp.

Source

  • astrbot/core/computer/booters/local.py, _BLOCKED_COMMAND_PATTERNS includes " rm -rf ", " rm -fr ", and " rm -r ".
  • _is_safe_command() only does pat in command; it never parses rm targets.
  • Master: https://github.com/AstrBotDevs/AstrBot/blob/master/astrbot/core/computer/booters/local.py#L47-L61 and #L83-L85

Impact

Legitimate temp-directory cleanup is blocked. Agents commonly react by reporting that their tools are incomplete or by refusing to continue, instead of using a workaround.

Suggested fix

Allow rm -rf / rm -fr / rm -r only when every target is a literal path under /tmp/ and contains no ..; keep blocking non-/tmp targets, variables, command substitution, and all other patterns (sudo, mkfs, dd, shutdown, killall, etc.). Alternatively, make the blocklist configurable instead of hardcoded.

Related

  • #8552 reports the same class of problem (closed without a code fix).
  • #8627 is the security context; this request does not ask to weaken non-/tmp protections.

Would a PR scoped to /tmp be acceptable?

Rebines avatar Nov 07 '26 17:11 Rebines

我接手这条。当前 astrbot/core/computer/booters/local.py:48 的拦截表里有 " rm -rf " 这类原始子串项,所以 rm -rf /tmp/my_build ... 会被当成 rm -rf / 一样拒绝。

计划:把「绝对危险目标」和「普通路径」分开判断——只有目标包含根目录、家目录、系统目录或未限定的通配符时才拒绝;/tmp 等工作目录下的临时目录允许,其它路径保持原有拦截。单元测试覆盖:rm -rf /tmp/x 通过、rm -rf / 与 rm -rf ~ 仍拒绝、带 && 的复合命令按每个 rm 判断;不执行真实删除,只测判定函数。

Ethereal49 avatar Nov 08 '26 01:11 Ethereal49

/dev/fd/11

Ethereal49 avatar Nov 09 '26 09:11 Ethereal49