[Bug 报告 / 设计问题] glob/grep 工具完全绕过沙箱:path 无任何策略约束,可读取工作区外任意文件(含隐藏文件)并注入模型上下文
#951
truelove-dreamer
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
摘要
glob/grep两个搜索工具(dsh-tool-fs-search)通过ctx.subprocess.spawn直接运行 ripgrep,没有任何sandboxPolicy或路径约束(代码注释自称 "unconfined (a plainctx.subprocesscall)")。工具的path参数被原样拼进 rg argv,且 rg 以--no-ignore --hidden运行(刻意枚举隐藏文件)。因此:path: "C:\Users\<someone>\.ssh"、path: "$DSH_HOME"等任意路径,读取工作区之外的.env、密钥、其它用户文件的内容并注入模型上下文;FS_SANDBOX_DENIED机制完全不一致。证据(代码与行号)
dsh-tool-fs-search/lib/index.js:159-178(runRipgrep→ctx.subprocess.spawn({ argv: [rg, "--no-config", ...argv], cwd: workdir, ... }),全程无 sandboxPolicy);path原样进 argv:同文件:561(glob{ path: args.path })与:911(grep{ path: args.path });--no-ignore --hidden(见工具描述/实现,刻意如此);dsh-fs-sandbox/lib/index.js:157-170的checkedTarget→FS_SANDBOX_DENIED);bash/pwsh 有沙箱 + escalation(dsh-sandbox/dsh-pwsh-sandbox);dsh-fs-sandbox/lib/index.js:74-75:"Reads pass through untouched: every mode permits reading")——若读取开放是设计,则与"bash 的读也被沙箱约束"形成面差。复现步骤
在任意会话中调用 grep(普通工具调用,无需特殊权限):
.credentials.yaml、.env等文件内容)到模型上下文。同样,
glob传path: "C:\Users\..."可枚举任意目录下的文件名(含隐藏文件),作为后续读取的侦察手段。影响
建议修复(供讨论)
path施加与 fs 工具一致的策略根/工作区约束(越界报FS_SANDBOX_DENIED类错误),或将 rg 的 spawn 纳入与 bash 相同的沙箱执行路径;.env、.credentials*、.ssh等)或至少对工作区外读取追加审批;--hidden静默支持,改为显式 opt-in。附注
All reactions