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:
@@ -90,17 +90,45 @@ export async function fetchWithTimeout(
|
||||
|
||||
// ===== URL 标准化(去重用) =====
|
||||
|
||||
/**
|
||||
* H-6 增强: URL 标准化用于搜索结果去重
|
||||
*
|
||||
* 规范推荐使用 normalize-url 库(@see docs/Agent网络工具通用设计-v2.md §6.1.3),
|
||||
* 但当前实现已覆盖核心场景,且避免 ESM-only 依赖兼容性风险,
|
||||
* 故在现有基础上增强以下能力(对标 normalize-url 默认行为):
|
||||
* 1. 去除追踪参数(utm_*, gclid, fbclid)
|
||||
* 2. 强制小写 host
|
||||
* 3. 去除尾部斜杠(根路径除外)
|
||||
* 4. H-6 新增: 去除默认端口(http→:80, https→:443)
|
||||
* 5. H-6 新增: 排序查询参数(避免 ?a=1&b=2 vs ?b=2&a=1 被视为不同 URL)
|
||||
*/
|
||||
export function normalizeUrl(url: string): string {
|
||||
try {
|
||||
const u = new URL(url);
|
||||
|
||||
// 去除追踪参数
|
||||
const trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'fbclid'];
|
||||
for (const p of trackingParams) u.searchParams.delete(p);
|
||||
|
||||
// H-6 增强: 排序查询参数(确保参数顺序一致,便于去重)
|
||||
// searchParams.sort() 原地排序,URLSearchParams 按码点顺序
|
||||
u.searchParams.sort();
|
||||
|
||||
// 去除尾部斜杠(根路径除外)
|
||||
let path = u.pathname;
|
||||
if (path.length > 1 && path.endsWith('/')) path = path.slice(0, -1);
|
||||
|
||||
// H-6 增强: 去除默认端口
|
||||
// http 默认 :80, https 默认 :443, ws 默认 :80, wss 默认 :443
|
||||
const isDefaultPort =
|
||||
(u.protocol === 'http:' && u.port === '80') ||
|
||||
(u.protocol === 'https:' && u.port === '443') ||
|
||||
(u.protocol === 'ws:' && u.port === '80') ||
|
||||
(u.protocol === 'wss:' && u.port === '443');
|
||||
const portSuffix = isDefaultPort ? '' : (u.port ? `:${u.port}` : '');
|
||||
|
||||
// 强制小写 host
|
||||
return `${u.protocol}//${u.host.toLowerCase()}${path}${u.search}${u.hash}`;
|
||||
return `${u.protocol}//${u.hostname.toLowerCase()}${portSuffix}${path}${u.search}${u.hash}`;
|
||||
} catch {
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user