## 漏洞概述 该提交修复了 OpenClaw 网关中设备会话管理的安全漏洞。当设备配对被移除或设备令牌被吊销时,系统未能及时断开相关的活跃客户端连接,可能导致已吊销权限的设备继续保持连接状态,造成未授权访问风险。 ## 影响范围 - **受影响组件**: OpenClaw Gateway 服务器 (`src/gateway/`) - **涉及功能**: - 设备配对移除 (`device.pair.remove`) - 设备令牌吊销 (`device.token.revoke`) - **风险场景**: 已吊销的设备/令牌仍能保持 WebSocket 连接,继续访问系统资源 ## 修复方案 ### 核心修复点 1. **设备配对移除后强制断连** (`devices.ts:176-179`) ```typescript queueMicrotask(() => { context.disconnectClientsForDevice?.([removed.deviceId]); }); ``` 2. **设备令牌吊销后强制断连** (`devices.ts:300-302`) ```typescript queueMicrotask(() => { context.disconnectClientsForDevice?.([normalizedDeviceId, { role: entry.role }]); }); ``` 3. **新增带角色过滤的断连方法** (`server.impl.ts:1199-1211`) ```typescript disconnectClientsForDevice: (deviceId: string, opts?: { role?: string }) => { for (const gatewayClient of clients) { if (gatewayClient.connect.device.id !== deviceId) { continue; } if (opts?.role && gatewayClient.connect.role !== opts.role) { continue; } try { gatewayClient.socket.close(4001, "device removed"); } catch { /* ignore */ } } } ``` 4. **类型定义更新** (`types.ts:60`) ```typescript disconnectClientsForDevice?: (deviceId: string, opts?: { role?: string }) => void; ``` ### 修复策略 - 使用 `queueMicrotask` 确保响应先返回给客户端,再异步执行断连操作 - 支持按设备ID和角色双重过滤,实现精确的会话管理 - 关闭连接时使用特定状态码 `4001` 标识"device removed"