BashGuard class
Bash 命令沙箱守卫 — 轻量启发式逃逸检测。
bash 本质上是任意 shell 指令,无法跨平台做完美沙箱(macOS/Linux 的 sandbox-exec/bwrap 不在本实现范围内)。本守卫是防御性的启发式:
- 主保证是 BashTool 固定
workingDirectory为工作目录; - 本守卫拒绝明显的越界/危险操作,避免误伤常见命令;
- 最终兜底是
commandExec类别的权限确认(默认权限级别下需用户确认)。
判定规则(保守 deny-list):
- 危险根操作:
rm -rf /、sudo、mkfs、dd ... of=/dev/*等; - 绝对路径越界:
cd/rm/mv/cp/chmod/chown/ln/touch/mkdir及重定向>/>>指向工作目录之外的绝对路径。
Constructors
Properties
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