@sleep2agi/commhub-server 0.9.0-preview.264 → 0.9.0-preview.265

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/build-info.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": 1,
3
- "commit": "1e0b230ff60161367d1b779df5bcdca4163a4ec4",
3
+ "commit": "67b398a34011ddc3b7eb8beb0299b790e54fe618",
4
4
  "dirty": false,
5
- "built_at": "2026-11-01T08:16:32.456Z",
5
+ "built_at": "2026-11-01T11:04:39.383Z",
6
6
  "source": "git"
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sleep2agi/commhub-server",
3
- "version": "0.9.0-preview.264",
3
+ "version": "0.9.0-preview.265",
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",
@@ -0,0 +1,132 @@
1
+ // #3148 —— 保险库的值要能**流向**真正要用的那个进程,但任何人仍然**读不出来**。
2
+ //
3
+ // admin 2026-11-01 在客户端里撞到的死结:
4
+ // 密钥已经在保险库里了,可没有任何路径把它送到目标节点;
5
+ // 于是人只能把明文再复制一遍,或者写进工作区文件 —— 两条都比保险库更差。
6
+ //
7
+ // 本文件的判据分两半,缺一半就只是「加了个功能」:
8
+ // ① 流向成立:owner/admin 只给键名,节点真的收到值(用节点侧 pull 来验,不靠内部字段)
9
+ // ② 读权不成立:任何读接口都不回值(getScopedSecrets / ack 回来的 snapshot / 响应体本身)
10
+ import './require-explicit-test-db';
11
+ import { afterAll, beforeEach, describe, expect, test } from 'bun:test';
12
+ import { db } from './db';
13
+ import { getScopedSecrets, pullNodeSecrets, ackNodeSecrets, requestNodeSecrets } from './scoped-secrets';
14
+ import { vaultUpsert, vaultListKeys, vaultDelete } from './vault';
15
+
16
+ const net = 'net_vaultinject';
17
+ const baseNode = 'n_vaultinject';
18
+ let node = baseNode;
19
+ const owner = 'u_vaultinject_owner';
20
+ const member = 'u_vaultinject_member';
21
+ const KEY = 'TMPAT';
22
+ const VALUE = 'pat-value-that-must-never-be-readable-0123456789';
23
+
24
+ function cleanup() {
25
+ db.run('DELETE FROM nodes WHERE network_id=?1', [net]);
26
+ db.run('DELETE FROM network_members WHERE network_id=?1', [net]);
27
+ db.run('DELETE FROM networks WHERE network_id=?1', [net]);
28
+ db.run('DELETE FROM users WHERE user_id IN (?1, ?2)', [owner, member]);
29
+ for (const k of vaultListKeys(net)) vaultDelete(net, k);
30
+ }
31
+
32
+ function makeNode(name: string) {
33
+ node = name;
34
+ db.run('INSERT INTO nodes(node_id,node_name,alias,network_id,config_snapshot) VALUES(?1,?1,?1,?2,?3)',
35
+ [node, net, JSON.stringify({ node_secrets_capable: true })]);
36
+ return node;
37
+ }
38
+
39
+ beforeEach(() => {
40
+ cleanup();
41
+ node = baseNode;
42
+ process.env.ANET_HUB_SECRET_VAULT_KEY = '43'.repeat(32);
43
+ db.run("INSERT INTO users(user_id,username,password_hash,role) VALUES(?1,?1,'x','user')", [owner]);
44
+ db.run("INSERT INTO users(user_id,username,password_hash,role) VALUES(?1,?1,'x','user')", [member]);
45
+ db.run('INSERT INTO networks(network_id,network_name,owner_id) VALUES(?1,?1,?2)', [net, owner]);
46
+ db.run("INSERT INTO network_members(user_id,network_id,role) VALUES(?1,?2,'owner')", [owner, net]);
47
+ db.run("INSERT INTO network_members(user_id,network_id,role) VALUES(?1,?2,'member')", [member, net]);
48
+ vaultUpsert(net, KEY, VALUE);
49
+ });
50
+ afterAll(cleanup);
51
+
52
+ const human = (userId: string) => ({ userId, isNode: false, networkId: net });
53
+ // 必须是函数:node 每个用例都不同,写成常量会把第一个用例的节点名焊死。
54
+ const asDaemon = () => ({ ok: true as const, networkId: net, daemonNodeId: node, daemonAlias: node });
55
+
56
+ /** 节点侧真正会收到的那个请求(不是内部字段:走 pullNodeSecrets 这条公开路径)。 */
57
+ function pulledFor(requestId: string) {
58
+ const pulled = pullNodeSecrets(asDaemon()) as any;
59
+ expect(pulled.ok).toBe(true);
60
+ return (pulled.requests as any[]).find((r) => r.request_id === requestId);
61
+ }
62
+
63
+ describe("#3148 保险库 → 节点:值能流过去,但读不回来", () => {
64
+ test("① 流向:owner 只给键名(from_vault),节点 pull 到的那条请求里带着保险库的值", () => {
65
+ makeNode("n_vi_flow");
66
+ const created = requestNodeSecrets(human(owner), node, 'put', KEY, undefined, 0, true) as any;
67
+ expect(created.ok).toBe(true);
68
+ const pulled = pulledFor(created.request_id);
69
+ expect(pulled).toBeDefined();
70
+ expect(pulled.action).toBe('put');
71
+ expect(pulled.key).toBe(KEY);
72
+ // 这一条是「值真的到了目标进程手上」——流向成立。
73
+ expect(pulled.value).toBe(VALUE);
74
+ });
75
+
76
+ test("② 读权:ack 回来的回执里只有键名与来源,没有任何值", () => {
77
+ makeNode("n_vi_ack");
78
+ const created = requestNodeSecrets(human(owner), node, 'put', KEY, undefined, 0, true) as any;
79
+ pulledFor(created.request_id);
80
+ const ack = ackNodeSecrets(asDaemon(), created.request_id, {
81
+ network_id: net, daemon_node_id: null, node_id: node, revision: 1, activation: 'next_start',
82
+ keys: [{ key: KEY, source: 'node' }],
83
+ }) as any;
84
+ expect(ack.ok).toBe(true);
85
+ expect(JSON.stringify(ack)).not.toContain(VALUE);
86
+ });
87
+
88
+ test("② 镜像否定:getScopedSecrets 的回执里没有值,也没有请求体里的明文", () => {
89
+ makeNode("n_vi_noread");
90
+ const created = requestNodeSecrets(human(owner), node, 'put', KEY, undefined, 0, true) as any;
91
+ const got = getScopedSecrets(human(owner), created.request_id) as any;
92
+ expect(got.ok).toBe(true);
93
+ expect(JSON.stringify(got)).not.toContain(VALUE);
94
+ expect(JSON.stringify(got)).not.toContain('"value"');
95
+ });
96
+
97
+ test("保险库里没有这个键 ⇒ vault_key_missing(不许回一个看起来成功的请求)", () => {
98
+ makeNode("n_vi_missing");
99
+ expect(requestNodeSecrets(human(owner), node, 'put', 'NOT_THERE', undefined, 0, true)).toEqual({
100
+ ok: false, error: 'vault_key_missing',
101
+ });
102
+ });
103
+
104
+ test("from_vault 只对 put 有意义:list / delete 用它是无效输入", () => {
105
+ makeNode("n_vi_list");
106
+ expect((requestNodeSecrets(human(owner), node, 'list', KEY, undefined, 0, true) as any).error).toBe('invalid_secret_input');
107
+ expect((requestNodeSecrets(human(owner), node, 'delete', KEY, undefined, 0, true) as any).error).toBe('invalid_secret_input');
108
+ });
109
+
110
+ test("同时给 value 与 from_vault ⇒ 无效输入(两种来源不许混用,否则说不清写进去的是哪一个)", () => {
111
+ makeNode("n_vi_mix");
112
+ expect((requestNodeSecrets(human(owner), node, 'put', KEY, 'another-value', 0, true) as any).error).toBe('invalid_secret_input');
113
+ });
114
+
115
+ test("普通成员用 from_vault ⇒ secret_admin_required(这是权限边界,不是能力边界)", () => {
116
+ makeNode("n_vi_member");
117
+ expect((requestNodeSecrets(human(member), node, 'put', KEY, undefined, 0, true) as any).error).toBe('secret_admin_required');
118
+ });
119
+
120
+ test("节点令牌(isNode)自己调 ⇒ user_token_required(机器不能给自己发密钥)", () => {
121
+ makeNode("n_vi_nodetoken");
122
+ expect((requestNodeSecrets({ userId: null, isNode: true, networkId: net }, node, 'put', KEY, undefined, 0, true) as any)
123
+ .error).toBe('user_token_required');
124
+ });
125
+
126
+ test("不支持的节点 ⇒ node_secrets_upgrade_required(先升级,不是先提权)", () => {
127
+ makeNode("n_vi_oldnode");
128
+ db.run('UPDATE nodes SET config_snapshot=?1 WHERE node_id=?2', [JSON.stringify({}), node]);
129
+ expect((requestNodeSecrets(human(owner), node, 'put', KEY, undefined, 0, true) as any).error)
130
+ .toBe('node_secrets_upgrade_required');
131
+ });
132
+ });
@@ -6,6 +6,7 @@ import { providerScanTargets } from './daemon-provider-snapshots';
6
6
  import { validScopedSecretKey } from './shared/scoped-secret-contract';
7
7
  import { observeSecretWrite, transportOf } from './env-transport-gate.js';
8
8
  import { secretTransportVerdict } from './env-transport-policy.js';
9
+ import { vaultGet } from './vault';
9
10
  type Human = { userId?: string | null; isNode: boolean; networkId: string | null };
10
11
  type Daemon = { ok: false; error: string } | { ok: true; networkId: string; daemonNodeId: string; daemonAlias: string };
11
12
  type Request = { request_id: string; network_id: string; daemon_node_id: string | null; node_id: string | null;
@@ -33,9 +34,33 @@ function nodeSupported(network: string, node: string) {
33
34
  try { return JSON.parse(row?.config_snapshot ?? '{}').node_secrets_capable === true; } catch { return false; }
34
35
  }
35
36
  // Independent node lane: no supervisor lookup, binding, or Daemon credential.
36
- export function requestNodeSecrets(h: Human, node: string, action: Request['action'], key?: string, value?: string, revision?: number) {
37
+ //
38
+ // `fromVault`(2026-11-01,#3148)—— **把保险库里的值直接推给这个节点**,调用方不必再持有明文。
39
+ //
40
+ // 背景:RFC-028 的保险库是「只进不出」——`list_network_secrets` 只回键名,没有任何取值接口。
41
+ // 这是对的:给 agent 一个读口,等于把整个网络的密钥变成任何一次 prompt 注入都能 dump 的东西。
42
+ // 但它带来一个真实的死结(admin 2026-11-01 在客户端里撞到):
43
+ //
44
+ // 密钥已经在保险库里了,可**没有任何路径**把它送到真正要用的那个进程;
45
+ // 于是人只能把明文再复制一遍,或者干脆写进工作区文件 —— 两条都比保险库更差。
46
+ //
47
+ // 所以这里补的是**流向**而不是**读权**:值从保险库直接写进目标节点的那次请求,
48
+ // 调用方(必须是 owner/admin)只提供键名。读侧仍然拿不到任何明文:
49
+ // · getScopedSecrets 只回 status/snapshot/error
50
+ // · 节点 ack 回来的 snapshot 里只有 {key, source},没有值
51
+ export function requestNodeSecrets(h: Human, node: string, action: Request['action'], key?: string, value?: string, revision?: number, fromVault?: boolean) {
37
52
  const refusal = authorize(h); if (refusal) return refusal;
38
53
  if (!nodeSupported(h.networkId!, node)) return denied('node_secrets_upgrade_required');
54
+ // from_vault 只在 put 上有意义:list/delete 没有值可推。
55
+ if (fromVault && action !== 'put') return denied('invalid_secret_input');
56
+ if (fromVault && value !== undefined) return denied('invalid_secret_input');
57
+ if (fromVault) {
58
+ if (!validScopedSecretKey(key)) return denied('invalid_secret_input');
59
+ // 保险库里没有这个名字 ⇒ 明确说「没有」,不要回一个看起来成功的请求。
60
+ const fromVaultValue = vaultGet(h.networkId!, key!);
61
+ if (typeof fromVaultValue !== 'string' || !fromVaultValue) return denied('vault_key_missing');
62
+ value = fromVaultValue;
63
+ }
39
64
  if (action !== 'list' && (!validScopedSecretKey(key) || !Number.isSafeInteger(revision) || revision! < 0
40
65
  || (action === 'put' && (typeof value !== 'string' || !value || Buffer.byteLength(value) > 8192 || value.includes('\0'))))) return denied('invalid_secret_input');
41
66
  expire();
@@ -45,7 +70,8 @@ export function requestNodeSecrets(h: Human, node: string, action: Request['acti
45
70
  const transport = transportOf(h.networkId!, node);
46
71
  const verdict = secretTransportVerdict(transport);
47
72
  if (verdict) return denied(verdict);
48
- observeSecretWrite(h.networkId!, node, `node_secret_${action}`);
73
+ // 记录的是**来源**,不是值:from_vault 的注入要能从审计里区分出来。
74
+ observeSecretWrite(h.networkId!, node, `node_secret_${action}${fromVault ? '_from_vault' : ''}`);
49
75
  }
50
76
  if ([...requests.values()].some(r => r.network_id === h.networkId && r.daemon_node_id === null && r.node_id === node && r.status === 'pending')) return denied('secret_store_busy');
51
77
  if (requests.size >= 1000) return denied('secret_queue_busy');
package/src/tools.ts CHANGED
@@ -4607,8 +4607,8 @@ export function registerTools(server: McpServer, clientIP?: string, enforceNetwo
4607
4607
  // No additional tools in model context; ordinary Provider actions unchanged.
4608
4608
  if (action === 'secret_read') return providerReply(getScopedSecrets(human, id));
4609
4609
  if (action === 'node_secret_list' || action === 'node_secret_put' || action === 'node_secret_delete') {
4610
- const input = provider as { key?: string; value?: string } | undefined;
4611
- const result = requestNodeSecrets(human, id, action === 'node_secret_list' ? 'list' : action === 'node_secret_put' ? 'put' : 'delete', input?.key, input?.value, revision);
4610
+ const input = provider as { key?: string; value?: string; from_vault?: boolean } | undefined;
4611
+ const result = requestNodeSecrets(human, id, action === 'node_secret_list' ? 'list' : action === 'node_secret_put' ? 'put' : 'delete', input?.key, input?.value, revision, input?.from_vault === true);
4612
4612
  if (result.ok) {
4613
4613
  const target = db.get<{ alias: string }>('SELECT alias FROM nodes WHERE node_id=?1 AND network_id=?2', id, human.networkId!);
4614
4614
  if (target) pushEvent(target.alias, { type: 'node_secrets', request_id: result.request_id }, human.networkId!);