Skip to content

fix: 修复 XSS 库中的原型污染漏洞 - #298

Merged
leizongmin merged 3 commits into
masterfrom
trae/solo-agent-e0R0oH
May 6, 2026
Merged

fix: 修复 XSS 库中的原型污染漏洞#298
leizongmin merged 3 commits into
masterfrom
trae/solo-agent-e0R0oH

Conversation

@leizongmin

Copy link
Copy Markdown
Owner

问题描述

该库存在多个原型污染漏洞,即使调用者不传任何配置选项(直接调用xss(html))也会受到影响。这些漏洞包括:

  1. shallowCopyObject 和 keysToLowerCase 两个工具函数在 for...in 循环中没有 hasOwnProperty 检查,导致会把污染过的原型属性复制为目标对象的自有属性。
  2. FilterXSS 构造函数对每个配置选项没有严格的 hasOwnProperty 检查,导致原型上的恶意属性会覆盖默认配置。
  3. 这些漏洞可能导致 RCE、XSS 跨站脚本、URL 绕过、白名单失效等严重安全问题,最高 CVSS 评分 9.6(Critical)。

修复方案

  1. 修复 shallowCopyObject 函数(lib/xss.js 第 55-63 行):添加 Object.prototype.hasOwnProperty.call(obj, i) 检查,确保只复制对象自身的可枚举属性。
  2. 修复 keysToLowerCase 函数(lib/xss.js 第 65-79 行):同样添加 hasOwnProperty 检查。
  3. 修复 FilterXSS 构造函数(lib/xss.js 第 90-124 行):每个配置项(stripIgnoreTag、whiteList/allowList、singleQuotedAttributeValue、onTag/onTagAttr 等)都增加 hasOwnProperty 检查,确保只使用用户显式传入的自有属性,不使用原型链上的属性。
  4. 修复 lib/index.js(第 27-38 行):在复制 DEFAULT 和 parser 的属性到 exports 时同样增加 hasOwnProperty 检查。
  5. 添加单元测试(test/test_xss.js):新增 prototype pollution protection 测试套件,验证修复后的代码能正确抵御原型污染攻击。

leizongmin and others added 3 commits May 5, 2026 02:44
Co-authored-by: traeagent <traeagent@users.noreply.github.com>
Co-authored-by: traeagent <traeagent@users.noreply.github.com>
Co-authored-by: traeagent <traeagent@users.noreply.github.com>
@leizongmin
leizongmin merged commit 49197ba into master May 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant