安全漏洞 / 高 / 工具系统
electron/harness/tools/built-in/file-editor.ts
FileEditorTool 支持基于正则的查找替换:
const regex = new RegExp(input.pattern, input.flags); const newContent = content.replace(regex, input.replacement);
用户提供的 pattern 未做 ReDoS 防护:
(a+)+
import { setTimeout } from 'timers/promises'; async function safeRegexReplace(content: string, pattern: RegExp, replacement: string): Promise<string> { try { return await Promise.race([ Promise.resolve(content.replace(pattern, replacement)), setTimeout(1000).then(() => { throw new Error('Regex timeout'); }), ]); } catch (err) { throw new Error(`Regex execution failed: ${err.message}`); } }
import safeRegex from 'safe-regex'; if (!safeRegex(pattern)) { throw new Error('Potentially catastrophic regex'); }
文件: electron/harness/tools/built-in/file-editor.ts
修复: 新增 isPotentiallyCatastrophicRegex 函数检测嵌套量词 (a+)+、重叠量词 a+a+、交替分支加量词 (a|a)*。regex case 中调用该函数拒绝危险模式;multiline 模式添加 100KB 内容长度限制。
isPotentiallyCatastrophicRegex
a+a+
(a|a)*
验证: tsc --noEmit 类型检查通过。
tsc --noEmit
No dependencies set.
The note is not visible to the blocked user.
问题类型
安全漏洞 / 高 / 工具系统
文件位置
electron/harness/tools/built-in/file-editor.ts问题描述
FileEditorTool 支持基于正则的查找替换:
用户提供的 pattern 未做 ReDoS 防护:
(a+)+等灾难性回溯模式影响
建议修复
修复说明
文件:
electron/harness/tools/built-in/file-editor.ts修复: 新增
isPotentiallyCatastrophicRegex函数检测嵌套量词(a+)+、重叠量词a+a+、交替分支加量词(a|a)*。regex case 中调用该函数拒绝危险模式;multiline 模式添加 100KB 内容长度限制。验证:
tsc --noEmit类型检查通过。