Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(remote-agent): 没映射上的沙箱禁止 glob 一律保留,不再依赖绝对路径判断

fmfsaisaia863da6099d7
diff --git a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts b/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts
index f117c19e49..524f9df3ef 100644
--- a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts
+++ b/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts
@@ -195,8 +195,10 @@ function mapSandboxDirs(record: JsonRecord, workspace: ExecutorWorkspace): JsonR
/**
* 一条文件权限:虚拟工作区内的路径换成本机路径。Agent 主机自己的路径(如它的 Codex 记忆目录)在本机
- * 没有对应位置,读写授权直接丢掉,只收不放;禁止条目在本机也是合法绝对路径时原样保留,不删本机
- * 有意义的禁止规则。相对 glob 与特殊路径(`:tmpdir`、项目根等)由本机 exec-server 按映射后的目录解释。
+ * 没有对应位置,读写授权直接丢掉,只收不放。禁止规则不因转换失效:路径条目在本机也是合法绝对路径时
+ * 原样保留(不合法的会让本机 exec-server 拒绝整个请求);没映射上的禁止 glob 一律原样保留——相对的由本机
+ * 按工作目录解释,Agent 主机的绝对路径在本机匹配不到东西,无需判断它是不是绝对路径。特殊路径(`:tmpdir`、
+ * 项目根等)由本机 exec-server 按映射后的目录解释。
*/
function mapSandboxEntry(entry: unknown, workspace: ExecutorWorkspace): unknown[] {
const record = asJsonRecord(entry);
@@ -209,11 +211,11 @@ function mapSandboxEntry(entry: unknown, workspace: ExecutorWorkspace): unknown[
const agentPath = agentPathFromUri(target.path);
return deny && agentPath !== null && isLocalAbsolutePath(agentPath) ? [entry] : [];
}
- // 绝对 glob 只认盘符、`/` 开头与 UNC(`\\server`);单个 `\` 开头是 POSIX 的转义(`\*.pem`),按相对 glob 保留。
- if (target.type === 'glob_pattern' && typeof target.pattern === 'string' && /^(?:[A-Za-z]:|\/|\\\\)/.test(target.pattern)) {
+ if (target.type === 'glob_pattern' && typeof target.pattern === 'string') {
const local = workspace.localGlobFromAgent(target.pattern);
if (local !== null) return [{ ...record, path: { ...target, pattern: local } }];
- return deny && isLocalAbsolutePath(target.pattern) ? [entry] : [];
+ // 读写 glob 只有明确是绝对路径(盘符加分隔符、`/` 开头、`\\server`)才是 Agent 主机的路径,丢掉;判断不准只会少放。
+ return deny || !/^(?:[A-Za-z]:[\\/]|\/|\\\\)/.test(target.pattern) ? [entry] : [];
}
return [entry];
}
diff --git a/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts b/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts
index 7475508a23..b05f71aa66 100644
--- a/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts
+++ b/apps/desktop/src/main/remote-agent/executor/__tests__/virtualWorkspace.test.ts
@@ -424,6 +424,7 @@ describe('virtual workspace', () => {
{ path: { type: 'path', path: 'file:///C:/Agent/secrets' }, access: 'deny' },
// Windows 网络路径:POSIX 本机的 exec-server 不认带主机名的 file URI,留下会让每条命令都被拒。
{ path: { type: 'path', path: 'file://server/share/secret' }, access: 'deny' },
+ // 没映射上的禁止 glob 原样保留:在本机匹配不到东西,也不会让请求被拒。
{ path: { type: 'glob_pattern', pattern: '\\\\server\\share\\**' }, access: 'deny' },
] } },
cwd: 'file:///C:/Agent/mirror/workspace',
@@ -441,6 +442,7 @@ describe('virtual workspace', () => {
{ path: { type: 'path', path: local(path.join(project, '.git')) }, access: 'read' },
{ path: { type: 'glob_pattern', pattern: project + '/**/*.env' }, access: 'deny' },
{ path: { type: 'glob_pattern', pattern: '**/*.pem' }, access: 'deny' },
+ { path: { type: 'glob_pattern', pattern: '\\\\server\\share\\**' }, access: 'deny' },
] } },
cwd: local(project),
policyContext: { cwd: local(project), workspaceRoots: [local(project)] },
@@ -481,8 +483,13 @@ describe('virtual workspace', () => {
{ path: { type: 'path', path: 'file:///home/agent/workspace' }, access: 'write' },
{ path: { type: 'path', path: 'file:///home/agent/.codex/memories' }, access: 'write' },
{ path: { type: 'path', path: 'file:///home/agent/.ssh' }, access: 'deny' },
- // 以转义开头的相对 glob(名字就叫 `*.pem` 的文件),不是以反斜杠开头的绝对路径。
+ // 相对 glob 不能被误认成绝对路径丢掉:以转义开头(名字就叫 `*.pem` 的文件)、文件名里带冒号。
{ path: { type: 'glob_pattern', pattern: '\\*.pem' }, access: 'deny' },
+ { path: { type: 'glob_pattern', pattern: 'a:*.pem' }, access: 'deny' },
+ { path: { type: 'glob_pattern', pattern: 'a:*.cache' }, access: 'write' },
+ // Agent 主机自己的绝对路径:写入授权丢掉,禁止规则保留。
+ { path: { type: 'glob_pattern', pattern: '/home/agent/.codex/**' }, access: 'write' },
+ { path: { type: 'glob_pattern', pattern: '/home/agent/.aws/**' }, access: 'deny' },
] } },
cwd: 'file:///home/agent/workspace',
};
@@ -492,6 +499,9 @@ describe('virtual workspace', () => {
// 任务电脑是 Windows 时 POSIX 路径不是本机路径,禁止条目也无从对应。
...(process.platform === 'win32' ? [] : [{ path: { type: 'path', path: 'file:///home/agent/.ssh' }, access: 'deny' }]),
{ path: { type: 'glob_pattern', pattern: '\\*.pem' }, access: 'deny' },
+ { path: { type: 'glob_pattern', pattern: 'a:*.pem' }, access: 'deny' },
+ { path: { type: 'glob_pattern', pattern: 'a:*.cache' }, access: 'write' },
+ { path: { type: 'glob_pattern', pattern: '/home/agent/.aws/**' }, access: 'deny' },
]);
expect(params.sandbox.cwd).toBe(pathToFileURL(project).href);
// 没有虚拟工作区(旧版对端)时沙箱原样转发,与之前一致。
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 4d74d6ceee..8a4504ac7e 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -1055,9 +1055,10 @@ handler 无 sender 依赖;不加入共享任务访客白名单,不进入自
升级 Codex 后核对 exec-server 新增的方法,只读的要显式归类,否则会被当成写入拒掉(#5764)。
非完全访问档下 `process/start` 与 `fs/*` 带 `sandbox`(固定版本 `codex-rs/file-system/src/lib.rs` 的
`WireFileSystemSandboxContext`),其中目录与权限条目都是 B 上看到的 file URI,中继换成 A 的路径:虚拟工作区内的
- 映射为本机路径;不在其中的是 B 自己的目录(如它的 Codex 记忆目录),读写授权丢弃,禁止条目在 A 上也是合法
- 绝对路径时原样保留,只收不放;网络与 Windows 沙箱档位不动。原样转发时两端系统不同会被 A 的 exec-server
- 拒绝(`invalid sandbox permission path URI`)。
+ 映射为本机路径(绝对 glob 里本机目录名按字面转义);不在其中的是 B 自己的目录(如它的 Codex 记忆目录),读写
+ 授权丢弃,只收不放;禁止规则不因转换失效:路径条目在 A 上也是合法绝对路径时原样保留,没映射上的禁止 glob
+ 一律原样保留;网络与 Windows 沙箱档位不动。原样转发时两端系统不同会被 A 的 exec-server 拒绝
+ (`invalid sandbox permission path URI`)。
- **影子目录与配置同步**:`open` 载荷除项目说明文件(含 `.claude/CLAUDE.md`、`.claude/rules`、
`.codex/skills`)外还带 `ancestorFiles`(项目上级目录里的
`CLAUDE.md` / `CLAUDE.local.md` / `AGENTS.md` / `AGENTS.override.md`,按层级 `up`,最多 24 级)与