feat: v0.7.0 四阶段全量迭代 — 修复面收口 · 安全纵深 · 架构还债 · 能力演进
P1 修复面收口: v0.6.3 截断自愈推全量(Anthropic/Ollama/非流式/引擎兜底); SSE 上游错误帧检测进重试通道; clearMessages 摘要游标根治; truncateResult 内联图片白名单统一; 前端四 bug(确认弹窗锁死/MemoryViewer/ Virtuoso Footer/abort 尾部过滤) + reasoning 缓冲跨迭代污染; 托盘通知过滤与新建会话死链接线 P2 安全纵深: MCP 审批闭环(ConfirmationHook×PolicyEngine 联动+重名拒注册); SSRF 收敛 ssrf-guard 共享模块 (web_fetch 双通道校验+重定向终态复检); Electron 加固(preload CJS 化→sandbox:true/CSP/权限白名单/will-navigate); run_command cmd.exe 白名单通道元字符守门; diff_viewer 10MB 预检; Anthropic thinking 预算下限; Agnes 思考显式关闭 P3 架构还债: OpenAICompatibleAdapter 中间基类收敛四家样板; 错误分类单轨化(删 mapError/getFetchSignal, 超时显式 ETIMEDOUT); PRAGMA user_version 迁移版本化; 死代码清理专项(cn.ts/SHORTCUTS/ContextMenu 分支/ getWindowState/modifiedArgs/sandbox 空壳); i18next 引入; a11y 第一轮; SearXNG 页批量草稿模型统一 P4 能力演进: Ollama pull 可取消/capabilities 探测/num_ctx 实测缓存; UpdateService feed 比对式自动更新 (app:updateCheck IPC + StatusBar 入口); MiMo providerOptions(web_search 服务端工具/strict JSON); web_fetch extract_mode=markdown(turndown); network.proxyUrl 全局代理(Chromium sessions+undici dispatcher) 测试: 264 → 507 用例(Electron ABI 全绿零跳过), 覆盖引擎压缩管线/重试竞速/MEMORY.md 闸门/file_editor 五操作/ filesystem 七工具实体夹具/git 真实仓库/SSE 错误帧/全线截断自愈/Provider 请求形态矩阵/SSRF 表测/钩子分级矩阵/ OutputValidator 全量/SLO 指标/MCP 安全纯函数/task_manager 链路/渲染层纯域/i18n 桥契约
This commit is contained in:
@@ -199,6 +199,40 @@ export class PolicyEngine {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* v0.6.4: 解析工具对应的策略(精确名 → 通配符前缀 → 无)
|
||||
* 供 checkAuthorization 与 requiresConfirmation 共用匹配逻辑,消除双份漂移。
|
||||
*/
|
||||
private resolvePolicy(toolName: string): PermissionPolicy | undefined {
|
||||
const exact = this.policies.get(toolName);
|
||||
if (exact) return exact;
|
||||
// C-7 修复: 支持通配符策略匹配(如 mcp_* 匹配所有 MCP 工具)
|
||||
// MCP 工具名称动态生成(mcp_{serverName}_{toolName}),无法预先配置精确策略
|
||||
for (const [pattern, p] of this.policies) {
|
||||
if (pattern.endsWith('*') && toolName.startsWith(pattern.slice(0, -1))) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* v0.6.4 P2-1: 查询某工具按策略引擎的配置是否需要用户确认。
|
||||
*
|
||||
* 背景(跨层防线不一致):ConfirmationHook 原先只读工具定义的
|
||||
* `requiresPermission || riskLevel∈{high,critical}` —— 而 MCPToolAdapter 把
|
||||
* 全部 MCP 工具标为 requiresPermission:false + MEDIUM,导致 PolicyEngine 为
|
||||
* `mcp_*` 配置的 requireConfirmation 形同虚设:外部 MCP server 的任意工具
|
||||
* 都被免确认执行。此方法让 ConfirmationHook 能消费策略层的声明。
|
||||
*
|
||||
* @param toolName 工具名
|
||||
* @returns true 表示有策略且其 requireConfirmation=true;无策略时返回 false
|
||||
* (未知工具由 PermissionCheckHook 的 fail-closed 负责拒绝)
|
||||
*/
|
||||
requiresConfirmation(toolName: string): boolean {
|
||||
return this.resolvePolicy(toolName)?.requireConfirmation ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限校验
|
||||
*
|
||||
@@ -218,18 +252,8 @@ export class PolicyEngine {
|
||||
level: PermissionLevel;
|
||||
requiresConfirmation: boolean;
|
||||
} {
|
||||
let policy = this.policies.get(toolName);
|
||||
|
||||
// C-7 修复: 支持通配符策略匹配(如 mcp_* 匹配所有 MCP 工具)
|
||||
// MCP 工具名称动态生成(mcp_{serverName}_{toolName}),无法预先配置精确策略
|
||||
if (!policy) {
|
||||
for (const [pattern, p] of this.policies) {
|
||||
if (pattern.endsWith('*') && toolName.startsWith(pattern.slice(0, -1))) {
|
||||
policy = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// v0.6.4: 复用统一的策略解析(精确 → 通配符 → 无)
|
||||
const policy = this.resolvePolicy(toolName);
|
||||
|
||||
if (!policy) {
|
||||
return {
|
||||
|
||||
@@ -9,17 +9,12 @@
|
||||
import { resolve, sep } from 'path';
|
||||
import { existsSync, realpathSync } from 'fs';
|
||||
|
||||
// v0.6.4 死代码清理:networkPolicy / resourceLimits 配置壳已删除。
|
||||
// 原字段被赋值后无任何方法消费(SandboxManager 没有进程沙箱执行器),
|
||||
// 属于"纸面防御层多于实作层",给读者虚假安全感。当前真实防线为:
|
||||
// 路径白名单(validatePath) + 危险模式静态扫描(scanCode) —— 与文档口径一致。
|
||||
export interface SandboxConfig {
|
||||
allowedPaths?: string[];
|
||||
networkPolicy?: 'allowall' | 'deny-all' | 'allowlist';
|
||||
resourceLimits?: Partial<ResourceLimits>;
|
||||
}
|
||||
|
||||
export interface ResourceLimits {
|
||||
maxMemoryMB: number;
|
||||
maxCpuSeconds: number;
|
||||
maxExecutionMs: number;
|
||||
maxOutputSizeKB: number;
|
||||
}
|
||||
|
||||
export interface SandboxExecutionResult {
|
||||
@@ -33,17 +28,9 @@ export interface SandboxExecutionResult {
|
||||
|
||||
export class SandboxManager {
|
||||
private allowedPaths: Set<string> = new Set();
|
||||
private networkPolicy: 'allowall' | 'deny-all' | 'allowlist' = 'deny-all';
|
||||
private resourceLimits: ResourceLimits = {
|
||||
maxMemoryMB: 512,
|
||||
maxCpuSeconds: 30,
|
||||
maxExecutionMs: 60_000,
|
||||
maxOutputSizeKB: 1024,
|
||||
};
|
||||
|
||||
constructor(private config: SandboxConfig) {
|
||||
this.allowedPaths = new Set(config.allowedPaths ?? []);
|
||||
this.networkPolicy = config.networkPolicy ?? 'allowlist';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user