@sleep2agi/commhub-server 0.9.0-preview.203 → 0.9.0-preview.205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/node-permissions-http.test.ts +49 -0
- package/src/server.ts +25 -0
- package/src/tools.ts +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/commhub-server",
|
|
3
|
-
"version": "0.9.0-preview.
|
|
3
|
+
"version": "0.9.0-preview.205",
|
|
4
4
|
"description": "CommHub Server — AI Agent communication hub with MCP protocol, multi-network isolation, user auth, and MCP tools (17 collaboration-core + node/provider ops tools; authoritative list: docs-site/docs/api/mcp-tools.md).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -292,6 +292,23 @@ describe("#2823 调用面计数(node_tool_calls)", () => {
|
|
|
292
292
|
expect(denyRows(node.nN.id)).toBe(before.denials);
|
|
293
293
|
});
|
|
294
294
|
|
|
295
|
+
// #2971 —— 读类 / 需求类 / 排程类原来根本不到闸里,账本因此完全看不到它们。
|
|
296
|
+
// 而敏感读恰恰在这一类里(list_network_secrets / list_providers / tail_node_logs)。
|
|
297
|
+
// 修法只有一个方向:**记账,但不判定** —— 拦截语义必须零变化。
|
|
298
|
+
test("#2971 读类工具会被计数,且行为不变(不被拦、不进拒绝日志)", async () => {
|
|
299
|
+
const before = { calls: callHits(node.nN.id, "mcp:list_providers"), denials: denyRows(node.nN.id) };
|
|
300
|
+
const r = await mcp(node.nN.token, "list_providers", { network_id: net });
|
|
301
|
+
expect(r.error).not.toBe("node_permission_denied");
|
|
302
|
+
expect(callHits(node.nN.id, "mcp:list_providers")).toBe(before.calls + 1);
|
|
303
|
+
expect(denyRows(node.nN.id)).toBe(before.denials);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("#2971 always 类不进账本(心跳会把账本淹掉)", async () => {
|
|
307
|
+
const before = toolCallTotal(node.nN.id);
|
|
308
|
+
await mcp(node.nN.token, "get_inbox", { alias: node.nN.alias });
|
|
309
|
+
expect(toolCallTotal(node.nN.id)).toBe(before);
|
|
310
|
+
});
|
|
311
|
+
|
|
295
312
|
test("本来会被拒的调用两个表都记(分子与分母同源)", async () => {
|
|
296
313
|
const beforeCalls = callHits(node.nN.id, "mcp:projects_create");
|
|
297
314
|
const beforeDeny = hitsOf(node.nN.id, "mcp:projects_create", "human_only");
|
|
@@ -415,3 +432,35 @@ describe("GET /api/nodes 读回白名单与 transport", () => {
|
|
|
415
432
|
expect((await rowOf(shadowId)).env_transport).toBe("https");
|
|
416
433
|
});
|
|
417
434
|
});
|
|
435
|
+
|
|
436
|
+
// #2969 —— 空数组是歧义的,Hub 直接拒,不猜。
|
|
437
|
+
//
|
|
438
|
+
// 客户端(PR #1165)把「[] = 不允许任何」做进了界面,而 Hub 的 `length ? … : null`
|
|
439
|
+
// 会把 [] 规范化成 null = 不限制。两边语义相反:用户以为收紧了,系统其实放开了。
|
|
440
|
+
// 三种做法里选了最不含糊的一种 —— 拒收,让调用方当场看到 400 和「清空请传 null」。
|
|
441
|
+
describe("空数组不猜:拒收,清空请传 null", () => {
|
|
442
|
+
test("PUT tool-allowlist [] → 400 empty_allowlist_ambiguous,且没改动库里已有值", async () => {
|
|
443
|
+
expect((await call(user.boss.token, "PUT", `/api/nodes/${node.other.id}/tool-allowlist`, { tools: ["send_task"] })).status).toBe(200);
|
|
444
|
+
const r = await call(user.boss.token, "PUT", `/api/nodes/${node.other.id}/tool-allowlist`, { tools: [] });
|
|
445
|
+
expect(r.status).toBe(400);
|
|
446
|
+
expect(r.body.error).toBe("empty_allowlist_ambiguous");
|
|
447
|
+
// 关键:拒收不能顺手把它清掉 —— 那等于「报错了,但行为已经变了」。
|
|
448
|
+
const row = await call(user.boss.token, "GET", `/api/nodes?network_id=${net}&node_id=${node.other.id}`);
|
|
449
|
+
expect(row.body.nodes[0].tool_allowlist).toEqual(["send_task"]);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
test("PUT peer-allowlist [] → 400,库里也没变", async () => {
|
|
453
|
+
expect((await call(user.boss.token, "PUT", `/api/nodes/${node.other.id}/peer-allowlist`, { peers: ["boss"] })).status).toBe(200);
|
|
454
|
+
const r = await call(user.boss.token, "PUT", `/api/nodes/${node.other.id}/peer-allowlist`, { peers: [] });
|
|
455
|
+
expect(r.status).toBe(400);
|
|
456
|
+
expect(r.body.error).toBe("empty_allowlist_ambiguous");
|
|
457
|
+
const row = await call(user.boss.token, "GET", `/api/nodes?network_id=${net}&node_id=${node.other.id}`);
|
|
458
|
+
expect(row.body.nodes[0].peer_allowlist).toEqual(["boss"]);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
test("清空走 null:200,读回来是 null(不是 [])", async () => {
|
|
462
|
+
expect((await call(user.boss.token, "PUT", `/api/nodes/${node.other.id}/tool-allowlist`, { tools: null })).status).toBe(200);
|
|
463
|
+
const row = await call(user.boss.token, "GET", `/api/nodes?network_id=${net}&node_id=${node.other.id}`);
|
|
464
|
+
expect(row.body.nodes[0].tool_allowlist).toBeNull();
|
|
465
|
+
});
|
|
466
|
+
});
|
package/src/server.ts
CHANGED
|
@@ -2953,6 +2953,23 @@ return Bun.serve({
|
|
|
2953
2953
|
const tools = Array.isArray(rawTools)
|
|
2954
2954
|
? rawTools.filter((x: unknown): x is string => typeof x === "string" && x.trim().length > 0).map((x: string) => x.trim())
|
|
2955
2955
|
: [];
|
|
2956
|
+
// #2969 —— 空数组是**歧义的**,直接拒,不猜。
|
|
2957
|
+
//
|
|
2958
|
+
// 发生过的事:客户端把「[] = 不允许任何工具」做进了界面(PR #1165),
|
|
2959
|
+
// 而 Hub 这边 `tools.length ? ... : null` 会把 [] 规范化成 null = **不限制**。
|
|
2960
|
+
// 两边语义相反,结果是「用户以为收紧了,系统其实放开了」——比没有这个选项更糟。
|
|
2961
|
+
//
|
|
2962
|
+
// 三种做法里选了最不含糊的一种:
|
|
2963
|
+
// · 把 [] 当「禁止一切」 → 老客户端「清空」按钮会变成把节点封死,回归风险太大
|
|
2964
|
+
// · 把 [] 当 null(现状) → 界面可以无声地说「全部禁止」而实际全放开,安全洞
|
|
2965
|
+
// · 拒收 [](本实现) → 调用方当场看到 400 和一句「清空请传 null」,没有静默行为
|
|
2966
|
+
if (Array.isArray(rawTools) && tools.length === 0) {
|
|
2967
|
+
return withCors(req, Response.json({
|
|
2968
|
+
ok: false,
|
|
2969
|
+
error: "empty_allowlist_ambiguous",
|
|
2970
|
+
message: "send null to clear the allowlist (no restriction); an empty array is ambiguous and is rejected",
|
|
2971
|
+
}, { status: 400 }));
|
|
2972
|
+
}
|
|
2956
2973
|
if (tools.length > 500) {
|
|
2957
2974
|
return withCors(req, Response.json({ ok: false, error: "too_many_tools", message: "at most 500 entries" }, { status: 400 }));
|
|
2958
2975
|
}
|
|
@@ -2985,6 +3002,14 @@ return Bun.serve({
|
|
|
2985
3002
|
const peers = Array.isArray(rawPeers)
|
|
2986
3003
|
? rawPeers.filter((x: unknown): x is string => typeof x === "string" && x.trim().length > 0).map((x: string) => x.trim())
|
|
2987
3004
|
: [];
|
|
3005
|
+
// 同 tool-allowlist:空数组歧义,拒收;清空请传 null。
|
|
3006
|
+
if (Array.isArray(rawPeers) && peers.length === 0) {
|
|
3007
|
+
return withCors(req, Response.json({
|
|
3008
|
+
ok: false,
|
|
3009
|
+
error: "empty_allowlist_ambiguous",
|
|
3010
|
+
message: "send null to clear the allowlist (no restriction); an empty array is ambiguous and is rejected",
|
|
3011
|
+
}, { status: 400 }));
|
|
3012
|
+
}
|
|
2988
3013
|
if (peers.length > 200) {
|
|
2989
3014
|
return withCors(req, Response.json({ ok: false, error: "too_many_peers", message: "at most 200 entries" }, { status: 400 }));
|
|
2990
3015
|
}
|
package/src/tools.ts
CHANGED
|
@@ -35,7 +35,7 @@ import { addAgentNetworkScope, addAgentTimelineScope, addNetworkScope, canRestWr
|
|
|
35
35
|
import { canMessageAgent, restrictedNetworkIds, RESTRICTED_MEMBER_TOOLS, type AgentRef } from "./agent-access.js";
|
|
36
36
|
import { listedToolFilter, scopeToolsList, type ToolCaller } from "./tool-audience.js";
|
|
37
37
|
import { agentBatchScheduleInterval, agentCancelSchedule, agentCreateSchedule, agentGetSchedule, agentListSchedules, agentRunScheduleNow, agentScheduleRuns, agentUpdateSchedule } from "./schedule-agent.js";
|
|
38
|
-
import { broadcastVerdict, dispatchVerdict, humanOnlyVerdict, NODE_TOOL_CLASS, nodeDecide, nodeIdentity, nodePermissionDeniedBody, writeVerdict, type NodeIdentity, type Verdict, toolAllowlistVerdict } from "./node-permissions.js";
|
|
38
|
+
import { broadcastVerdict, dispatchVerdict, humanOnlyVerdict, NODE_TOOL_CLASS, nodeDecide, nodeIdentity, nodePermissionDeniedBody, recordNodeToolCall, writeVerdict, type NodeIdentity, type Verdict, toolAllowlistVerdict } from "./node-permissions.js";
|
|
39
39
|
import { countInFlightTasks } from "./node-in-flight-tasks.js";
|
|
40
40
|
import { restrictedMemberAttachmentsDenied } from "./restricted-files.js";
|
|
41
41
|
import { errorBody } from "./requirements-errors.js";
|
|
@@ -296,8 +296,15 @@ function guardNodePermissionTools(server: McpServer, tokenId: string, networkId:
|
|
|
296
296
|
if (allowVerdict && nodeDecide(id, `mcp:${name}`, allowVerdict)) {
|
|
297
297
|
return denied(allowVerdict.reason, `mcp:${name}`);
|
|
298
298
|
}
|
|
299
|
+
// #2971 —— 账本要覆盖「到达工具的每一次调用」,不只是会被拦的那几类。
|
|
300
|
+
// 读类 / 需求类 / 排程类原来根本不到这里 ⇒ node_tool_calls 漏掉它们,
|
|
301
|
+
// 而 read 类里就有 list_network_secrets / list_providers / tail_node_logs 这些敏感读。
|
|
302
|
+
// 🔴 只计数、不判定:拦截语义零变化(这几类本来也不在这个闸里判)。
|
|
303
|
+
// always 类仍然不记:那是心跳(get_inbox / report_status),记进来只会把账本淹掉。
|
|
299
304
|
const gated = cls !== "always" && cls !== "read" && cls !== "requirements" && cls !== "schedule";
|
|
300
|
-
if (gated) {
|
|
305
|
+
if (!gated) {
|
|
306
|
+
if (cls !== "always") recordNodeToolCall(id, `mcp:${name}`);
|
|
307
|
+
} else {
|
|
301
308
|
const args = callArgs[0] && typeof callArgs[0] === "object" ? callArgs[0] as Record<string, unknown> : {};
|
|
302
309
|
const verdict = verdictFor(id, name, args);
|
|
303
310
|
if (nodeDecide(id, `mcp:${name}`, verdict)) return denied(verdict!.reason, `mcp:${name}`);
|