GHSA-55q2-fjhq-7xh7: DOMPurify Cross-Site Scripting Vulnerability
MODERATEGHSA-55q2-fjhq-7xh7 is a MODERATE cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting DOMPurify libraries in the npm ecosystem. The issue involves in_place hook removal leaves a detached subtree executable, causing xss. Remediation is available by upgrading affected packages to version 3.4.13.
GHSA-55q2-fjhq-7xh7 at a Glance
How to Fix GHSA-55q2-fjhq-7xh7
To remediate this vulnerability, upgrade all affected DOMPurify dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install dompurify@3.4.13
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls dompurify
How to Check if You Are Affected
To determine whether your Node.js application is affected by GHSA-55q2-fjhq-7xh7, inspect your project dependencies using npm:
npm ls dompurify
Analyze the terminal output to locate any version of DOMPurify in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.4.13), your application is affected.
Note: The npm ls dompurify command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In DOMPurify, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
GHSA-55q2-fjhq-7xh7 Affected DOMPurify Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
dompurify
|
npm |
< 3.4.13
|
3.4.13
|
References
Frequently Asked Questions
What is GHSA-55q2-fjhq-7xh7?
Which DOMPurify versions are affected?
What version fixes GHSA-55q2-fjhq-7xh7?
Is dompurify affected?
What CWE is associated with GHSA-55q2-fjhq-7xh7?
How can I check npm dependencies for GHSA-55q2-fjhq-7xh7?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-55q2-fjhq-7xh7",
"modified" : "2026-08-07T15:30:47Z",
"published" : "2026-08-07T15:30:47Z",
"aliases" : [ ],
"summary" : "DOMPurify: IN_PLACE hook removal leaves a detached subtree executable, causing XSS",
"details" : "### Summary\n\nDuring `IN_PLACE` sanitization, a hook that removes an element can leave that element's detached descendants executable. A descendant image can retain its attacker-provided `onload` handler and fire after `sanitize()` returns, even though the returned root is clean and the image remains disconnected from the document.\n\n### Details\n\nIn DOMPurify 3.4.12, `_sanitizeElements()` in `src/purify.ts:1862-1904` runs the `beforeSanitizeElements` or `uponSanitizeElement` hook and returns immediately when the hook detached the current node. The return does not call `_neutralizeSubtree(currentNode)`.\n\nThe detached subtree is not added to `DOMPurify.removed`, so the post-walk `IN_PLACE` neutralization cannot reach it. If the browser queued a resource event while the application constructed the detached dirty root, a descendant can therefore retain its handler and execute after sanitization.\n\nThe hook only rejects the containing element and does not add or approve the event handler. DOMPurify's ordinary removal path de-arms the same queued event; only the hook-detachment early return skips the existing subtree neutralization.\n\n### PoC\n\nLoad the published `dompurify@3.4.12` `dist/purify.js` before this script in Chromium:\n\n```html\n<div id=\"result\">not fired</div>\n<script>\nconst root = document.createElement('div');\nroot.innerHTML = `\n <footer>\n <img src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\"\n onload=\"result.textContent = 'XSS after sanitize'\">\n </footer>\n <div>safe</div>`;\n\nDOMPurify.setConfig({\n ALLOWED_TAGS: ['div', '#text', 'footer'],\n IN_PLACE: true\n});\nDOMPurify.addHook('uponSanitizeElement', node => {\n if (node.tagName === 'FOOTER') node.remove();\n});\n\nDOMPurify.sanitize(root);\ndocument.body.append(root);\n</script>\n```\n\n`sanitize()` returns with no handler execution and the returned root contains only the safe `div`. After the event loop advances, the original image remains disconnected but its retained `onload` changes the page to `XSS after sanitize`.\n\nAs the claim-matched control, use the same detached input with `ALLOWED_TAGS: ['div', '#text']` and no hook. DOMPurify's ordinary removal path removes the original image's handler, the returned root is still `<div>safe</div>`, and the marker does not fire.\n\n### Impact\n\nIn an application that uses `IN_PLACE` with the documented element-removal hook pattern, an attacker who can supply HTML can execute JavaScript in the integrating application's origin after the application sanitizes and renders that content.\n\nThe required non-default configuration is `IN_PLACE` plus a hook that removes a containing element. The hook does not add or approve the event handler, and the dirty root never needs to be connected before sanitization.\n\n### Suggested fix\n\nReuse the existing `_neutralizeSubtree(currentNode)` helper before returning from both hook-detachment branches in `_sanitizeElements()`. Add regressions for `beforeSanitizeElements` and `uponSanitizeElement` that retain a reference to a descendant resource element and verify that its event handler is removed after the hook detaches its ancestor.",
"severity" : [ {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "dompurify"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "3.4.13"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 3.4.12"
}
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/cure53/DOMPurify/security/advisories/GHSA-55q2-fjhq-7xh7"
}, {
"type" : "WEB",
"url" : "https://github.com/cure53/DOMPurify/pull/1557"
}, {
"type" : "WEB",
"url" : "https://github.com/cure53/DOMPurify/commit/3067f7746769"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/cure53/DOMPurify"
}, {
"type" : "WEB",
"url" : "https://github.com/cure53/DOMPurify/releases/tag/3.4.13"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-79" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2026-08-07T15:30:47Z",
"nvd_published_at" : null
}
}