BashGuard class

Bash 命令沙箱守卫 — 轻量启发式逃逸检测。

bash 本质上是任意 shell 指令,无法跨平台做完美沙箱(macOS/Linux 的 sandbox-exec/bwrap 不在本实现范围内)。本守卫是防御性的启发式

  • 主保证是 BashTool 固定 workingDirectory 为工作目录;
  • 本守卫拒绝明显的越界/危险操作,避免误伤常见命令;
  • 最终兜底是 commandExec 类别的权限确认(默认权限级别下需用户确认)。

判定规则(保守 deny-list):

  1. 危险根操作:rm -rf /sudomkfsdd ... of=/dev/* 等;
  2. 绝对路径越界:cd/rm/mv/cp/chmod/chown/ln/touch/mkdir 及重定向 >/>> 指向工作目录之外的绝对路径。

Constructors

BashGuard(String sandboxPath, {bool enabled = true})
enabled 为 false 时不限制;sandboxPath 为空时仍拒绝危险根操作 (rm -rf /sudo 等),但不做路径越界检查。

Properties

enabled bool
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validateCommand(String command) String?
校验命令是否安全。返回 null 表示允许,否则为错误信息。

Operators

operator ==(Object other) bool
The equality operator.
inherited