安全漏洞 / 高 / 工具系统
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'); }
No dependencies set.
The note is not visible to the blocked user.
问题类型
安全漏洞 / 高 / 工具系统
文件位置
electron/harness/tools/built-in/file-editor.ts问题描述
FileEditorTool 支持基于正则的查找替换:
用户提供的 pattern 未做 ReDoS 防护:
(a+)+等灾难性回溯模式影响
建议修复