feat: 升级至 v0.3.1 — 全量代码审计修复 + 安全增强
本次升级基于完整代码审查,修复 Critical/High/Medium/Low 四级共 96 项问题, 并通过返工审计修复 10 项遗留问题,tsc 双端类型检查零错误。 Critical (10/10 完成): - C-4: command.ts 接入 shell-quote 进行 token-level 注入检测,替代原有正则匹配 可防御 r"m" -rf /、$'rm'、$(echo rm) 等字符串拼接绕过 High (11/11 完成): - 竞态保护、Promise.allSettled、AbortController 资源泄漏、IPC 参数校验等 Medium (55/55 完成): - 事务保护、敏感数据脱敏、枚举校验、MUI v9 Stack prop 迁移、 React 组件 cancelled 标志、类型收窄等 Low (20/20 完成): - 辅助方法提取(flushToolCallBuffer/scoreAndPushMemory/tryAddColumn 等) - nanoid 统一替代 Date.now()+Math.random() - confirm() 替换为 MUI Dialog、useMemo 缓存、魔法数字命名化等 返工审计修复 (10/10 完成): - L-11: LogsSettings 残留的原生 confirm()/alert() 全部替换为 MUI Dialog/Alert - M-53: MemoryViewer handleSearch 独立 ref,修复 searching 状态卡死 - M-42: 脱敏短值(length <= 4)泄露修复 - M-47: tasks:update 补全 title/description 类型校验 - L-9: ollama.adapter 非流式路径 nanoid 统一 - M-45: audit:query limit 策略与 memory:listAll 一致化 - SettingsModal handleConfirmRemove 补全 try/catch + loadServers cleanup - L-15: CommandPalette useMemo 补全 sessions 响应式依赖 - useAgentStream 事件类型补全 seq/timestamp 字段 新增依赖: shell-quote + @types/shell-quote 版本号: 0.3.0 -> 0.3.1
This commit is contained in:
+52
-7
@@ -222,7 +222,9 @@ async function initialize(): Promise<void> {
|
||||
];
|
||||
|
||||
// ===== Agent Loop =====
|
||||
// TODO: Re-read agent config on each runStream call or when config changes
|
||||
// Agent 配置初始化:仅此处一次性读取,配置变更时由 handlers.ts 的 config:set
|
||||
// 监听器调用 agentLoop.updateConfig() 和 orchestrator.updateDefaultConfig() 即时生效。
|
||||
// @see electron/ipc/handlers.ts — 'config:set' handler
|
||||
const ollamaNumCtx = configService.get<number>('ollama.numCtx');
|
||||
const agentMaxIter = configService.get<number>('agent.maxIterations');
|
||||
const agentTimeout = configService.get<number>('agent.totalTimeoutMs');
|
||||
@@ -375,7 +377,7 @@ async function initialize(): Promise<void> {
|
||||
contextBuilder, agentLoop, toolRegistry, auditService,
|
||||
sessionRecorder, memoryManager, mcpManager, reloadAdapter,
|
||||
promptDefender, outputValidator,
|
||||
confirmationHook, memoryConsolidator,
|
||||
confirmationHook, memoryConsolidator, orchestrator,
|
||||
);
|
||||
|
||||
// TODO: Initialize UpdateService for auto-update functionality
|
||||
@@ -395,16 +397,46 @@ async function initialize(): Promise<void> {
|
||||
}
|
||||
});
|
||||
|
||||
app.on('before-quit', async () => {
|
||||
// M-13 修复: before-quit 回调改为同步 + event.preventDefault() 确保异步清理完成
|
||||
// 之前 async 回调 Electron 不会 await,导致 MCP shutdown 未完成时应用已退出
|
||||
app.on('before-quit', (event) => {
|
||||
// 标记为正在退出,允许窗口关闭(两处 isQuitting 统一设置)
|
||||
(global as Record<string, unknown>).isQuitting = true;
|
||||
TrayManager.markQuitting();
|
||||
windowManager?.unregisterGlobalShortcuts();
|
||||
trayManager?.destroy();
|
||||
windowManager?.closeAll();
|
||||
try { await mcpManager.shutdown(); } catch (err) { log.error('[Shutdown] MCP shutdown failed:', err); }
|
||||
cleanupBrowser();
|
||||
if (databaseService) { databaseService.close(); databaseService = null; }
|
||||
|
||||
// 防止重复触发(macOS before-quit 可能触发多次)
|
||||
if ((global as Record<string, unknown>).shutdownInProgress === true) {
|
||||
return;
|
||||
}
|
||||
(global as Record<string, unknown>).shutdownInProgress = true;
|
||||
|
||||
event.preventDefault();
|
||||
// 内部异步清理,加 5 秒超时保护防止卡死
|
||||
const shutdownTimeout = setTimeout(() => {
|
||||
log.warn('[Shutdown] Timeout reached, forcing exit');
|
||||
if (databaseService) { databaseService.close(); databaseService = null; }
|
||||
app.exit(0);
|
||||
}, 5_000);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await mcpManager.shutdown();
|
||||
} catch (err) {
|
||||
log.error('[Shutdown] MCP shutdown failed:', err);
|
||||
}
|
||||
cleanupBrowser();
|
||||
if (databaseService) { databaseService.close(); databaseService = null; }
|
||||
clearTimeout(shutdownTimeout);
|
||||
app.exit(0);
|
||||
})().catch((err) => {
|
||||
log.error('[Shutdown] Async cleanup failed:', err);
|
||||
clearTimeout(shutdownTimeout);
|
||||
if (databaseService) { try { databaseService.close(); } catch { /* ignore */ } databaseService = null; }
|
||||
app.exit(1);
|
||||
});
|
||||
});
|
||||
|
||||
// ===== 应用日志级别配置 =====
|
||||
@@ -430,5 +462,18 @@ async function initialize(): Promise<void> {
|
||||
app.whenReady().then(initialize);
|
||||
|
||||
app.on('web-contents-created', (_, contents) => {
|
||||
contents.setWindowOpenHandler(({ url }) => { shell.openExternal(url); return { action: 'deny' }; });
|
||||
// C-8 修复: 全局 web-contents 监听器也校验 URL 协议
|
||||
contents.setWindowOpenHandler(({ url }) => {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
|
||||
shell.openExternal(url);
|
||||
} else {
|
||||
log.warn(`[Main] Blocked window.open with unsafe protocol: ${parsed.protocol}`);
|
||||
}
|
||||
} catch {
|
||||
log.warn(`[Main] Blocked window.open with invalid URL: ${url.slice(0, 100)}`);
|
||||
}
|
||||
return { action: 'deny' };
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user