fix: make goosed mcp paths container safe

This commit is contained in:
john
2026-06-27 21:31:02 +08:00
parent def9b0b5eb
commit fc5b50c936
7 changed files with 157 additions and 30 deletions
+28
View File
@@ -8,6 +8,7 @@ import {
clampUserCapabilities,
DEFAULT_USER_CAPABILITIES,
normalizeCapabilityPatch,
resolveSandboxMcpNodeExecPath,
resolveSandboxMcpServerPath,
sandboxDeveloperTools,
sandboxMcpTools,
@@ -20,6 +21,18 @@ test('resolveSandboxMcpServerPath resolves to an existing MCP entry file', () =>
assert.ok(fs.existsSync(serverPath));
});
test('resolveSandboxMcpServerPath honors container-path override without host fs checks', () => {
assert.equal(
resolveSandboxMcpServerPath('/opt/portal/mindspace-sandbox-mcp.mjs'),
'/opt/portal/mindspace-sandbox-mcp.mjs',
);
});
test('resolveSandboxMcpNodeExecPath honors container-path override without host fs checks', () => {
assert.equal(resolveSandboxMcpNodeExecPath('/usr/local/bin/node'), '/usr/local/bin/node');
assert.equal(resolveSandboxMcpNodeExecPath(''), process.execPath);
});
test('default user policy blocks dangerous capabilities', () => {
assert.equal(DEFAULT_USER_CAPABILITIES.shell, false);
assert.equal(DEFAULT_USER_CAPABILITIES.filesystem, false);
@@ -222,6 +235,7 @@ test('static_publish with sandboxMcp uses stdio sandbox-fs extension instead of
const sandboxExt = policy.extensionOverrides.find((ext) => ext.name === 'sandbox-fs');
assert.ok(sandboxExt, 'sandbox-fs extension should be present');
assert.equal(sandboxExt.type, 'stdio');
assert.equal(sandboxExt.cmd, process.execPath);
assert.equal(sandboxExt.envs.SANDBOX_ROOT, '/opt/h5/MindSpace/abc123');
assert.equal(sandboxExt.args[1], '/opt/h5/MindSpace/abc123'); // also passed as argv[2]
assert.ok(sandboxExt.available_tools.includes('write_file'));
@@ -237,3 +251,17 @@ test('static_publish with sandboxMcp uses stdio sandbox-fs extension instead of
assert.ok(!allTools.includes('write'), 'built-in write should not be exposed');
assert.ok(!allTools.includes('shell'), 'shell should not be exposed');
});
test('sandboxMcp honors container node executable override', () => {
const caps = { ...DEFAULT_USER_CAPABILITIES, static_publish: true };
const policy = buildAgentExtensionPolicy(caps, {
sandboxMcp: {
serverPath: '/opt/h5/mindspace-sandbox-mcp.mjs',
sandboxRoot: '/opt/h5/MindSpace/abc123',
nodeExecPath: '/usr/local/bin/node',
},
});
const sandboxExt = policy.extensionOverrides.find((ext) => ext.name === 'sandbox-fs');
assert.equal(sandboxExt?.cmd, '/usr/local/bin/node');
});