安全漏洞 / 高 / Agent 引擎
electron/harness/security/prompt-injection-defense.ts
攻击者可使用 Unicode 同形字符(homoglyph)绕过关键词检测:
іgnore
іgnorе
ignore\u200bprevious
ignore\u00adprevious
这些字符在视觉上与原文无异,但正则匹配会失败。
const normalized = input.normalize('NFKC'); // 移除零宽字符 const cleaned = normalized.replace(/[\u200b\u200c\u200d\u00ad\ufeff]/g, ''); // 然后检测
文件: electron/harness/security/prompt-injection-defense.ts
修复: 新增 normalizeForDetection 方法(NFKC 归一化 + 移除零宽字符 U+200B/C/D/U+00AD/U+FEFF),detect/detectSemantic 均使用归一化文本检测。新增 hasMixedScripts 检测拉丁/西里尔/希腊混用,命中时 riskScore +3。
normalizeForDetection
detect
detectSemantic
hasMixedScripts
验证: tsc --noEmit 类型检查通过。
tsc --noEmit
No dependencies set.
The note is not visible to the blocked user.
问题类型
安全漏洞 / 高 / Agent 引擎
文件位置
electron/harness/security/prompt-injection-defense.ts问题描述
攻击者可使用 Unicode 同形字符(homoglyph)绕过关键词检测:
іgnore(使用西里尔字母 і 替换 i)іgnorе(混用拉丁、西里尔、希腊字母)ignore\u200bprevious(零宽空格分隔)ignore\u00adprevious(软连字符)这些字符在视觉上与原文无异,但正则匹配会失败。
影响
建议修复
修复说明
文件:
electron/harness/security/prompt-injection-defense.ts修复: 新增
normalizeForDetection方法(NFKC 归一化 + 移除零宽字符 U+200B/C/D/U+00AD/U+FEFF),detect/detectSemantic均使用归一化文本检测。新增hasMixedScripts检测拉丁/西里尔/希腊混用,命中时 riskScore +3。验证:
tsc --noEmit类型检查通过。