DOMPurify: IN_PLACE hook removal leaves a detached subtree executable, causing XSS
DOMPurify versions prior to 3.4.13 contain a vulnerability in the IN_PLACE sanitization mode where a hook that removes an element can leave detached descendant elements executable. This allows an attacker who can supply HTML to execute JavaScript via retained event handlers on detached subtrees after sanitization completes. The issue arises because the sanitization process skips neutralizing the subtree of a detached node when a hook removes it, leaving event handlers intact on disconnected elements.
AI Analysis
Technical Summary
In DOMPurify 3.4.12, during IN_PLACE sanitization, the _sanitizeElements() function runs hooks such as uponSanitizeElement and returns immediately if the hook detaches the current node. However, it does not call _neutralizeSubtree() on the detached node, leaving any descendant elements with attacker-controlled event handlers executable after sanitize() returns. This detached subtree is not tracked for neutralization, so queued resource events like onload on images can fire, resulting in cross-site scripting (XSS) despite the returned sanitized root being clean and disconnected from the document. The vulnerability requires the non-default IN_PLACE configuration combined with a hook that removes a containing element, but does not add or approve event handlers. A proof-of-concept demonstrates that an image's onload handler fires after sanitization, modifying page content. The suggested fix is to call _neutralizeSubtree() on detached nodes before returning from hook-detachment branches in _sanitizeElements().
Potential Impact
An attacker able to supply HTML to an application using DOMPurify with IN_PLACE mode and an element-removal hook can execute arbitrary JavaScript in the application's origin after sanitization. This results in a cross-site scripting (XSS) vulnerability despite the sanitized output appearing clean. The vulnerability affects only the non-default IN_PLACE configuration combined with hooks that remove elements. There are no known exploits in the wild. The impact is moderate due to the specific configuration required and the need for attacker-controlled HTML input.
Mitigation Recommendations
A patch is available in DOMPurify version 3.4.13 that fixes this issue by ensuring the detached subtree is neutralized before returning from hook-detachment branches. Users should upgrade to version 3.4.13 or later. If upgrading is not immediately possible, avoid using the IN_PLACE configuration with hooks that remove elements until patched. The vendor advisory confirms a fix is available.
DOMPurify: IN_PLACE hook removal leaves a detached subtree executable, causing XSS
Description
DOMPurify versions prior to 3.4.13 contain a vulnerability in the IN_PLACE sanitization mode where a hook that removes an element can leave detached descendant elements executable. This allows an attacker who can supply HTML to execute JavaScript via retained event handlers on detached subtrees after sanitization completes. The issue arises because the sanitization process skips neutralizing the subtree of a detached node when a hook removes it, leaving event handlers intact on disconnected elements.
CVSS v4.0
Affected software
Run on your own infrastructure? Check whether these packages are installed with threat-finder — our free open-source scanner.
Weaknesses
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
In DOMPurify 3.4.12, during IN_PLACE sanitization, the _sanitizeElements() function runs hooks such as uponSanitizeElement and returns immediately if the hook detaches the current node. However, it does not call _neutralizeSubtree() on the detached node, leaving any descendant elements with attacker-controlled event handlers executable after sanitize() returns. This detached subtree is not tracked for neutralization, so queued resource events like onload on images can fire, resulting in cross-site scripting (XSS) despite the returned sanitized root being clean and disconnected from the document. The vulnerability requires the non-default IN_PLACE configuration combined with a hook that removes a containing element, but does not add or approve event handlers. A proof-of-concept demonstrates that an image's onload handler fires after sanitization, modifying page content. The suggested fix is to call _neutralizeSubtree() on detached nodes before returning from hook-detachment branches in _sanitizeElements().
Potential Impact
An attacker able to supply HTML to an application using DOMPurify with IN_PLACE mode and an element-removal hook can execute arbitrary JavaScript in the application's origin after sanitization. This results in a cross-site scripting (XSS) vulnerability despite the sanitized output appearing clean. The vulnerability affects only the non-default IN_PLACE configuration combined with hooks that remove elements. There are no known exploits in the wild. The impact is moderate due to the specific configuration required and the need for attacker-controlled HTML input.
Mitigation Recommendations
A patch is available in DOMPurify version 3.4.13 that fixes this issue by ensuring the detached subtree is neutralized before returning from hook-detachment branches. Users should upgrade to version 3.4.13 or later. If upgrading is not immediately possible, avoid using the IN_PLACE configuration with hooks that remove elements until patched. The vendor advisory confirms a fix is available.
Technical Details
- Gcve Source
- db.gcve.eu
- Osv Id
- GHSA-55q2-fjhq-7xh7
- Osv Schema Version
- 1.4.0
- Aliases
- []
- Ecosystems
- ["npm"]
- Database Specific Severity
- MODERATE
- Cvss Version
- 4.0
Threat ID: 6a774343bf8831d539b47b7c
Added to database: 08/08/2026, 14:54:59 UTC
Last enriched: 08/08/2026, 15:44:13 UTC
Last updated: 08/08/2026, 16:02:47 UTC
Views: 5
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.